Google Maps API v3 - Different markers/labels on different zoom levels

前端 未结 2 1608
情话喂你
情话喂你 2021-02-14 17:01

I was wondering if it is possible that Google has a feature to view different markers on different zoom levels.

For example, on zoom level 1, I want one marker over Chin

相关标签:
2条回答
  • 2021-02-14 17:25

    The real reason why my program was failing was because of the Marker Manager, which doesn't work with my Markers with Labels.

    There was actually a much simpler approach, however, to fulfill my needs.

    function initialize() {
            map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    
            getMarkers();
            google.maps.event.addListener(map,'zoom_changed',function () {
                 if (map.getZoom() >= 3) showMarkers();
                 if (map.getZoom() <= 2) eraseMarkers();
    
                });
    
        }
    
        function eraseMarkers() {
            for (i = 0; i < locations.length; i++) { 
                marker[i].setVisible(false);
            }
    
          }
    
        function showMarkers() {
            for (i = 0; i < locations.length; i++) { 
                marker[i].setVisible(true);
            }
    
          }
    
        function getMarkers() {
            for (i = 0; i < locations.length; i++) { 
                marker[i] = new MarkerWithLabel({
                  position: new google.maps.LatLng(locations[i][1], locations[i][2]),
                  draggable: false,
                  map: map,
                  labelContent: locations[i][3],
                  labelAnchor: new google.maps.Point(30, 0),
                  labelClass: "labels", // the CSS class for the label
                  labelStyle: {opacity: 0.75}
                });
    
    
                }
            eraseMarkers();
          }
    
    0 讨论(0)
  • 2021-02-14 17:28

    Looks like thing you are trying to make is called Marker Clustering.

    Here you are lots of official google exmamples https://developers.google.com/maps/articles/toomanymarkers written on native javascript

    http://gmap3.net/examples/clustering.html - using jQuery library.

    I hope this will help you.

    0 讨论(0)
提交回复
热议问题