Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps Spiderfy open by default

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 accomplished this?

https://github.com/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.net/vFAy6/5/

like image 793
user3032973 Avatar asked Jan 08 '14 15:01

user3032973


1 Answers

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);

like image 65
Shevy Avatar answered Oct 11 '22 23:10

Shevy