2013-03-07 5 views
15

मैं Google MarkerClusterer का उपयोग कर रहा हूं। जब भी नक्शा ज़ूम स्तर 15 से ऊपर जाता है तो मैं सभी मार्करों को अस्वीकार करना चाहता हूं।Google मार्करक्लस्टर: एक निश्चित ज़ूम स्तर के नीचे गिरावट मार्कर?

कॉन्फ़िगरेशन विकल्पों में maxZoom सेटिंग है, लेकिन documentation does not make it clear what it is supposed to do है।

मैं इसे स्थापित करने के रूप में इस की कोशिश की है, लेकिन नक्शे संकुल बनी हुई है जो कुछ भी ज़ूम स्तर मैं करने के लिए नक्शे सेट:

new_mc = new MarkerClusterer(map, newco_markers, { 
     maxZoom: 9 
    }); 

मैं कुछ गलत कर रहा हूँ, मैं गलत समझा है क्या विकल्प करने के लिए माना जाता है, या यह ठीक करने का कोई और तरीका है?

उत्तर

12

this example पर अधिकतम ज़ूम स्तर सेट करना, ज़ूम स्तर 8 और उसके बाद के सभी मार्करों को अस्वीकार करता है।

पुन: पेश करने के लिए:

  1. सेट मैक्स ज़ूम स्तर 7 क्लिक ताज़ा नक्शा करने के लिए
  2. परिवर्तन ज़ूम स्तर को 0 पर (दूर का बाहर)
  3. ज़ूम पर क्लिक करें "+" स्लाइडर 8 बार।

MarkerClustererPlus के लिए प्रलेखन एक छोटे से स्पष्ट है:

Maxzoom | संख्या | अधिकतम ज़ूम स्तर पर क्लस्टरिंग सक्षम या शून्य है यदि सभी ज़ूम स्तरों पर क्लस्टरिंग सक्षम होना है। डिफॉल्ट मान शून्य है।

कोड स्निपेट:

var styles = [ 
 
    [{ 
 
    url: 'https://googlemaps.github.io/js-marker-clusterer/images/people35.png', 
 
    height: 35, 
 
    width: 35, 
 
    anchor: [16, 0], 
 
    textColor: '#ff00ff', 
 
    textSize: 10 
 
    }, { 
 
    url: 'https://googlemaps.github.io/js-marker-clusterer/images/people45.png', 
 
    height: 45, 
 
    width: 45, 
 
    anchor: [24, 0], 
 
    textColor: '#ff0000', 
 
    textSize: 11 
 
    }, { 
 
    url: 'https://googlemaps.github.io/js-marker-clusterer/images/people55.png', 
 
    height: 55, 
 
    width: 55, 
 
    anchor: [32, 0], 
 
    textColor: '#ffffff', 
 
    textSize: 12 
 
    }], 
 
    [{ 
 
    url: 'https://googlemaps.github.io/js-marker-clusterer/images/conv30.png', 
 
    height: 27, 
 
    width: 30, 
 
    anchor: [3, 0], 
 
    textColor: '#ff00ff', 
 
    textSize: 10 
 
    }, { 
 
    url: 'https://googlemaps.github.io/js-marker-clusterer/images/conv40.png', 
 
    height: 36, 
 
    width: 40, 
 
    anchor: [6, 0], 
 
    textColor: '#ff0000', 
 
    textSize: 11 
 
    }, { 
 
    url: 'https://googlemaps.github.io/js-marker-clusterer/images/conv50.png', 
 
    width: 50, 
 
    height: 45, 
 
    anchor: [8, 0], 
 
    textSize: 12 
 
    }], 
 
    [{ 
 
    url: 'https://googlemaps.github.io/js-marker-clusterer/images/heart30.png', 
 
    height: 26, 
 
    width: 30, 
 
    anchor: [4, 0], 
 
    textColor: '#ff00ff', 
 
    textSize: 10 
 
    }, { 
 
    url: 'https://googlemaps.github.io/js-marker-clusterer/images/heart40.png', 
 
    height: 35, 
 
    width: 40, 
 
    anchor: [8, 0], 
 
    textColor: '#ff0000', 
 
    textSize: 11 
 
    }, { 
 
    url: 'https://googlemaps.github.io/js-marker-clusterer/images/heart50.png', 
 
    width: 50, 
 
    height: 44, 
 
    anchor: [12, 0], 
 
    textSize: 12 
 
    }], 
 
    [{ 
 
    url: 'https://googlemaps.github.io/js-marker-clusterer/images/pin.png', 
 
    height: 48, 
 
    width: 30, 
 
    anchor: [-18, 0], 
 
    textColor: '#ffffff', 
 
    textSize: 10, 
 
    iconAnchor: [15, 48] 
 
    }] 
 
]; 
 

 
var markerClusterer = null; 
 
var map = null; 
 
var imageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&' + 
 
    'chco=FFFFFF,008CFF,000000&ext=.png'; 
 

 
function refreshMap() { 
 
    if (markerClusterer) { 
 
    markerClusterer.clearMarkers(); 
 
    } 
 

 
    var markers = []; 
 

 
    var markerImage = new google.maps.MarkerImage(imageUrl, 
 
    new google.maps.Size(24, 32)); 
 

 
    for (var i = 0; i < 1000; ++i) { 
 
    var latLng = new google.maps.LatLng(data.photos[i].latitude, 
 
     data.photos[i].longitude) 
 
    var marker = new google.maps.Marker({ 
 
     position: latLng, 
 
     draggable: true, 
 
     icon: markerImage 
 
    }); 
 
    markers.push(marker); 
 
    } 
 

 
    var zoom = parseInt(document.getElementById('zoom').value, 10); 
 
    var size = parseInt(document.getElementById('size').value, 10); 
 
    var style = parseInt(document.getElementById('style').value, 10); 
 
    zoom = zoom === -1 ? null : zoom; 
 
    size = size === -1 ? null : size; 
 
    style = style === -1 ? null : style; 
 

 
    markerClusterer = new MarkerClusterer(map, markers, { 
 
    maxZoom: zoom, 
 
    gridSize: size, 
 
    styles: styles[style], 
 
    imagePath: 'https://googlemaps.github.io/js-marker-clusterer/images/m' 
 
    }); 
 
} 
 

 
function initialize() { 
 
    map = new google.maps.Map(document.getElementById('map'), { 
 
    zoom: 2, 
 
    center: new google.maps.LatLng(39.91, 116.38), 
 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
 
    }); 
 

 
    var refresh = document.getElementById('refresh'); 
 
    google.maps.event.addDomListener(refresh, 'click', refreshMap); 
 

 
    var clear = document.getElementById('clear'); 
 
    google.maps.event.addDomListener(clear, 'click', clearClusters); 
 

 
    refreshMap(); 
 
} 
 

 
function clearClusters(e) { 
 
    e.preventDefault(); 
 
    e.stopPropagation(); 
 
    markerClusterer.clearMarkers(); 
 
} 
 

 
google.maps.event.addDomListener(window, 'load', initialize);
body { 
 
    margin: 0; 
 
    padding: 10px 20px 20px; 
 
    font-family: Arial; 
 
    font-size: 16px; 
 
} 
 
#map-container { 
 
    padding: 6px; 
 
    border-width: 1px; 
 
    border-style: solid; 
 
    border-color: #ccC#ccC#999 #ccc; 
 
    -webkit-box-shadow: rgba(64, 64, 64, 0.5) 0 2px 5px; 
 
    -moz-box-shadow: rgba(64, 64, 64, 0.5) 0 2px 5px; 
 
    box-shadow: rgba(64, 64, 64, 0.1) 0 2px 5px; 
 
    width: 800px; 
 
} 
 
#map { 
 
    width: 800px; 
 
    height: 400px; 
 
} 
 
#actions { 
 
    list-style: none; 
 
    padding: 0; 
 
} 
 
#inline-actions { 
 
    padding-top: 10px; 
 
} 
 
.item { 
 
    margin-left: 20px; 
 
}
<script src="https://maps.googleapis.com/maps/api/js"></script> 
 
<script src="https://googlemaps.github.io/js-marker-clusterer/examples/data.json"></script> 
 
<script src="https://googlemaps.github.io/js-marker-clusterer/src/markerclusterer.js"></script> 
 
<h3>An example of MarkerClusterer v3</h3> 
 
<div id="map-container"> 
 
    <div id="map"></div> 
 
</div> 
 
<div id="inline-actions"> 
 
    <span>Max zoom level: 
 
     <select id="zoom"> 
 
      <option value="-1">Default</option> 
 
      <option value="7">7</option> 
 
      <option value="8">8</option> 
 
      <option value="9">9</option> 
 
      <option value="10">10</option> 
 
      <option value="11">11</option> 
 
      <option value="12">12</option> 
 
      <option value="13">13</option> 
 
      <option value="14">14</option> 
 
     </select> 
 

 
     </span> 
 
    <span class="item">Cluster size: 
 
     <select id="size"> 
 
      <option value="-1">Default</option> 
 
      <option value="40">40</option> 
 
      <option value="50">50</option> 
 
      <option value="70">70</option> 
 
      <option value="80">80</option> 
 
     </select> 
 
     </span> 
 
    <span class="item">Cluster style: 
 
     <select id="style"> 
 
      <option value="-1">Default</option> 
 
      <option value="0">People</option> 
 
      <option value="1">Conversation</option> 
 
      <option value="2">Heart</option> 
 
      <option value="3">Pin</option> 
 
     </select> 
 
     <input id="refresh" type="button" value="Refresh Map" class="item"/> 
 
     <a href="#" id="clear">Clear</a> 
 
    </div>

+0

मेरे मामले में यह केवल कन्स्ट्रक्टर में सेट करते समय काम कर रहा था। अगर मैं इसे बाद में सेट करता हूं तो अधिकतम ज़ूम काम नहीं करेगा। – mandarin

+0

बिल्कुल वही जो मैं खोज रहा था। बहुत बहुत धन्यवाद। – rahul

5
var markerClusterer = new MarkerClusterer(map, myMarkers, { 
    maxZoom: 15, 
    zoomOnClick: false 
    }); 
//zoom 0 corresponds to a map of the Earth fully zoomed out, 20 is closeup 
//markerCluster goes away after zoom 
//turn off zoom on click or spiderfy won't work 
0

तुम हमेशा अलग कोड wrire कर सकते हैं, उदाहरण के लिए गठबंधन

  • map.getZoom(),
  • मार्कर [i] .setVisible (सही) (या गलत) और
  • google.maps.event.addListener (नक्शा, 'zoom_changed', ...

कुछ इस तरह:

function show_hide_markers(zoom) { 
    var markerVisible; 
    for (var i = 0; i < markers.length; i++) { 
     if (zoom <= zoomRanges[i][1] && zoom >= zoomRanges[i][0]) { 
      markerVisible = true 
     } else markerVisible = false; 

     if (markers[i].getVisible() != markersVisible) { 
     markers[i].setVisible(markersVisible);} 
    } 
} 

// ... 

google.maps.event.addListener(map, 'zoom_changed', function() { 
    show_hide_markers(map.getZoom()); 
}); 

पहले मार्कर सरणी बनाएं। ज़ूम स्तर श्रेणियों को मार्कर सरणी (यहां ज़ूमरेंज) में इंडेक्स के किसी भी तरह से संबंधित एक अलग सरणी में रखा जा सकता है। ज़ूम स्तर को मार्कर सरणी बनाने के लिए उपयोग की जाने वाली मूल सरणी (सूची) से भी लिया जा सकता है।

इस उदाहरण में ज़ूम रेंज प्रत्येक मार्कर को व्यक्तिगत रूप से असाइन की जाती है, लेकिन दो आयामी सरणी का उपयोग किया जा सकता है और मार्कर पूरे क्लस्टर के लिए प्राप्त किया जा सकता है।

यदि मार्कर संख्या बहुत अधिक नहीं है तो यह पर्याप्त होना चाहिए।संभावित रूप से दृश्यता स्थापित करने के बजाय अपराधी को जोड़ना/निकालना लागू किया जाना चाहिए।

मार्कर प्रबंधक (कम से कम हाल ही में कुछ मामलों में) के विपरीत यह एपीआई 3 + एपीआई कुंजी के तहत भी काम करता है। मुझे कल/आज ऐसा करने के लिए मजबूर होना पड़ा।

संबंधित मुद्दे