Overlapping Marker Spiderfier Marker Icon When There are Multiple Markers at Same Location

后端 未结 3 1609
春和景丽
春和景丽 2021-02-08 22:58

Google Maps doesn\'t provide a way to break apart multiple markers that are at the same location. This can occur with a people or businesses at a multiple residency location suc

3条回答
  •  無奈伤痛
    2021-02-08 23:42

    Here's how I got it to work. Where map is a Gmap instance and oms is an Overlapping Marker Spiderfier instance. We're also using Marker Clusterer on the initial zoom which buys us a break.

    map.addListener('zoom_changed', function() {        
    
        map.addListenerOnce('idle', function() {
    
            // change spiderable markers to plus sign markers
            // we are lucky here in that initial map is completely clustered
            // for there is no init listener in oms :(
            // so we swap on the first zoom/idle
            // and subsequently any other zoom/idle
    
            var spidered = oms.markersNearAnyOtherMarker();
    
            for (var i = 0; i < spidered.length; i ++) {
    
                // this was set when we created the markers
                url = spidered[i].icon.url;
    
                // code to manipulate your spidered icon url
            };
    
        });
    
    });
    
    
    oms.addListener('unspiderfy', function(markers) {
    
        var spidered = markers;
    
        for (var i = 0; i < spidered.length; i ++) {
    
            url = spidered[i].icon.url;
    
            // change it back
        };
    });
    
    
    oms.addListener('click', function(marker) {
    
      // put the clicked-on marker on top
      // when oms un-spiders
    
      marker.zIndex=999;
    
      // set infowindow, panning etc.
    
    });
    

提交回复
热议问题