目前正在尝试将重叠标记Spiderfier插件集成到Google Map设置中。我将位置数据传递给MongoDB的Jade模板。
在使用附加组件之前,我使用for循环从一组co-cordinates创建标记。这些都按预期显示。
但是,当我整合Spiderfier代码时,标记不再添加到地图中。仍会显示地图,但JavaScript控制台正在返回Uncaught Reference Error - OverlappingMarkerSpiderfier is not defined
消息。这是否意味着对加载项的调用不正确?我完全准备好接受我已经错过了一些明显的东西,但迄今为止尝试了以下无济于事:
以下是有关Google地图的代码:
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);
答案 0 :(得分:3)
看起来你在第二个script()函数中输了一个小错误,错过了src和url之间的=
符号。因此,外部Spiderfier脚本未加载,这解释了OverlappingMarkerSpiderfier is not defined
。
所以改变
script(src"http://jawj.github.io/OverlappingMarkerSpiderfier/bin/oms.min.js")
因此它包含=
script(src="http://jawj.github.io/OverlappingMarkerSpiderfier/bin/oms.min.js")