jawj / OverlappingMarkerSpiderfier

Deals with overlapping markers in Google Maps JS API v3, Google Earth-style
http://blog.mackerron.com
836 stars 238 forks source link

Map won't center correctly when using spiderfier #150

Closed resqonline closed 6 years ago

resqonline commented 6 years ago

I am having trouble with the spiderfier - as soon as I activate it, the map won't center and fit to the bounds, instead it just shows somewhere around the equator (the blackened part is where my json file does an overlay)

screenshot 2018-05-22 10 10 05

I am not getting any errors in the console, though. As soon as I deactivate the spiderfying, the whole map shows up correctly. But I need a solution to show overlapping markers (sometimes there are five or more in the same spot). I am using Advanced Custom Fields plugin in WordPress to manage the markers with the Google Maps field and included the Spiderfier function like this:

    // Spiderfier
    var oms = new OverlappingMarkerSpiderfier(map, { markersWontMove: true, markersWontHide: true, keepSpiderfied: true, legWeight: 2, circleFootSeparation: 50});

    function omsMarkers( markers ) {
      for ( var i = 0; i < markers.length; i++ ) {
        oms.addMarker( markers[i] );
      }
    }

    omsMarkers(markers);

You can take a look at the whole skript here: https://github.com/resqonline/code-snippets/blob/master/google-maps.js

jawj commented 6 years ago

Looking at the whole script, the markers variable appears to be set to []? Do you need to use $markers instead (and is this an array of Google Maps Marker objects, as it will need to be)?

resqonline commented 6 years ago

yes it is an array of marker objects

resqonline commented 6 years ago

@jawj just noticed that the error only occurs on start page with the map, it seems on sub-pages (taxonomies and such) everything is fine. I am using the same template tag on all pages including start page, so I am not sure, why it throws an error on the front page but not on other pages.

resqonline commented 6 years ago

@jawj finally found the issue! it seems it mattered, how and when the individual functions were called... good heavens, this is why I don't like JS 😄