Currently trying to integrate the Overlapping Marker Spiderfier add-on into a Google Map setup. I am passing the location data to a Jade Template from MongoDB.
Before utilising the add-on, I used a for loop to create markers from an array of co-cordinates. These were displayed as expected.
However, when I integrated the Spiderfier code, the markers are no longer added to the map. The map is still displayed, but the JavaScript console is returning a Uncaught Reference Error - OverlappingMarkerSpiderfier is not defined
message. Does this mean the call to the add-on is incorrect? I am fully ready to accept that I have missed something obvious but have so far tried the following to no avail:
Here is the code concerning the Google Map:
script(src="http://maps.googleapis.com/maps/api/js?key=AIzaSyASXfB-y1pwF_S-qToDhYL7doiHrUFOx0Q&sensor=false")
script(src"http://jawj.github.io/OverlappingMarkerSpiderfier/bin/oms.min.js")
script.
var locationArray = [];
each tweetlocations, i in locationlist
script.
var latitude = "#{tweetlocations.latitude}";
var longitude = "#{tweetlocations.longitude}";
var markerlocation = new google.maps.LatLng(latitude,longitude);
locationArray.push(markerlocation);
script.
function initialize()
{
var mapProp = {
center:markerlocation,
zoom:1,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
var iw = new google.maps.InfoWindow();
var oms = new OverlappingMarkerSpiderfier(map,{markersWontMove: true, markersWontHide: true});
var usualColor = 'eebb22';
var spiderfiedColor = 'ffee22';
var iconWithColor = function(color) {
return 'http://chart.googleapis.com/chart?chst=d_map_xpin_letter&chld=pin|+|' + color + '|000000|ffff00';
}
var shadow = new google.maps.MarkerImage('https://www.google.com/intl/en_ALL/mapfiles/shadow50.png',
new google.maps.Size(37, 34),
new google.maps.Point(0, 0),
new google.maps.Point(10, 34)
);
oms.addListener('click', function(marker, event) {
iw.open(map, marker);
});
oms.addListener('spiderfy', function(markers) {
for(var i = 0; i < markers.length; i ++) {
markers[i].setIcon(iconWithColor(spiderfiedColor));
markers[i].setShadow(null);
}
iw.close();
});
oms.addListener('unspiderfy', function(markers) {
for(var i = 0; i < markers.length; i ++) {
markers[i].setIcon(iconWithColor(usualColor));
markers[i].setShadow(shadow);
}
});
var bounds = new google.maps.LatLngBounds();
var coord;
for (coord in locationArray) {
bounds.extend(coord);
var marker = new google.maps.Marker({
position: locationArray[coord],
map: map,
icon: iconWithColor(usualColor),
shadow: shadow
});
oms.addMarker(marker);
}
}
google.maps.event.addDomListener(window, 'load', initialize);
Looks like you made a small typo inside the second script() function, missing the =
sign between src and url. Consequently the external Spiderfier script wasn't getting loaded, which explains OverlappingMarkerSpiderfier is not defined
.
So change
script(src"http://jawj.github.io/OverlappingMarkerSpiderfier/bin/oms.min.js")
so it includes a =
script(src="http://jawj.github.io/OverlappingMarkerSpiderfier/bin/oms.min.js")