admin管理员组

文章数量:1313177

Looking to utlize the spiderfy which George MacKerron has developed. However I have one other requirement which is to load the map with all markers "spiderd" out by default. I can mimic this by using javascript to click on the markers, but there has to be another way by using the spiderfy code. Has anyone acplished this?

var map = new google.maps.Map(document.getElementById("map-canvas"), options);
var iw = new google.maps.InfoWindow();
var oms = new OverlappingMarkerSpiderfier(map, {keepSpiderfied: true});

/

Looking to utlize the spiderfy which George MacKerron has developed. However I have one other requirement which is to load the map with all markers "spiderd" out by default. I can mimic this by using javascript to click on the markers, but there has to be another way by using the spiderfy code. Has anyone acplished this?

https://github./jawj/OverlappingMarkerSpiderfier#overlapping-marker-spiderfier-for-google-maps-api-v3

var map = new google.maps.Map(document.getElementById("map-canvas"), options);
var iw = new google.maps.InfoWindow();
var oms = new OverlappingMarkerSpiderfier(map, {keepSpiderfied: true});

http://jsfiddle/vFAy6/5/

Share Improve this question edited Jan 8, 2014 at 16:56 user3032973 asked Jan 8, 2014 at 15:27 user3032973user3032973 4152 gold badges10 silver badges26 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

I came up with a solution that worked for me. After I've added all markers, I set a timeout to call a functiont to open each cluster and in the OMS js.

  1. keepSpiderfied keeps all spideried markers open. It wasn't working for me so I altered the OMS js. If it works for you, you don't need to change this.

Find this:

(!e||!this.keepSpiderfied)&&this.unspiderfy();

Replace with this:

(!e||!this.keepSpiderfied);
  1. function to call to open each cluster group:

    function openAllClusters() {
        var markers = oms.markersNearAnyOtherMarker();
    
        $.each(markers, function (i, marker) {
            google.maps.event.trigger(markers[i], 'click');
        });
    }
    
  2. I set a timeout after I added my last marker (because it didn't work just calling the function immediately after):

    setTimeout(openAllClusters, 2000);

From the documentation:

keepSpiderfied (default: false)

By default, the OverlappingMarkerSpiderfier works like Google Earth, in that when you click > a spiderfied marker, the markers unspiderfy before any other action takes place.

Since this can make it tricky for the user to work through a set of markers one by one, you > can override this behaviour by setting the keepSpiderfied option to true.

According to the developer of this google map extension this will not work.

https://github./jawj/OverlappingMarkerSpiderfier/issues/2

本文标签: javascriptGoogle Maps Spiderfy open by defaultStack Overflow