这很奇怪。我正在使用标记clusterer来捆绑我的所有标记然而第一次当地图呈现时以及当我尝试拖动它或平移它时 - 它挂起并且firefox告诉我脚本正在减慢它因此我必须停止脚本。但是如果我把它缩小 - 它会正常变焦并从那时起平移就不会引起任何问题 - 我不知道这里出了什么问题。这是我的代码我在这里遗漏了一些东西 - 我的初始化肯定有问题:
var map = null;
function initializeGMaps() {
if (GBrowserIsCompatible())
{
map = new GMap2(document.getElementById("map_canvas"));
{
var side_bar_html = "";
var gmarkers = [];
var htmls = [];
var i = 0;
iconBlue = new GIcon();
// A function to create the marker and set up the event window
function createMarker(point,name,html) {
iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_yellow.png';
iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
iconBlue.iconSize = new GSize(12, 20);
iconBlue.shadowSize = new GSize(22, 20);
iconBlue.iconAnchor = new GPoint(6, 20);
iconBlue.infoWindowAnchor = new GPoint(5, 1);
var marker = new GMarker(point,{ icon:iconBlue, });
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
});
gmarkers[i] = marker;
htmls[i] = html;
side_bar_html += '<a href="javascript:myclick(' + i + ')">' + name + '<\/a><br>';
i++;
return marker;
}
// This function picks up the click and opens the corresponding info window
function myclick(i) {
gmarkers[i].openInfoWindowHtml(htmls[i]);
}
// create the map
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng( 43.907787, -50.359741), 5);
var customUI = map.getDefaultUI();
customUI.controls.maptypecontrol = false;
customUI.controls.menumaptypecontrol = true;
map.setUI(customUI);
// A function to read the data
function readMap() {
var url='get-map-markers.php';
var request = GXmlHttp.create();
request.open("GET", url, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = request.responseXML;
// obtain the array of markers and loop through it
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
// hide the info window, otherwise it still stays open where the removed marker used to be
map.getInfoWindow().hide();
map.clearOverlays();
// empty the array
allmarkers = [];
//var clusterer = new Clusterer( map );
for (var i = 0; i < markers.length; i++) {
// obtain the attribues of each marker
var lat = parseFloat(markers[i].getAttribute("lat"));
var lng = parseFloat(markers[i].getAttribute("lng"));
var point = new GLatLng(lat,lng);
var html = markers[i].getAttribute("html");
var label = markers[i].getAttribute("label");
// create the marker
var marker = createMarker(point,label,html);
//map.addOverlay(marker);
allmarkers.push(marker);
//clusterer.AddMarker( marker, html );
}
var markerCluster = new MarkerClusterer(map, allmarkers);
// put the assembled side_bar_html contents into the side_bar div
}
}
request.send(null);
}
readMap();
}
}
}
$(document).ready(function() { initializeGMaps(); } );
$('body').unload( function () { GUnload(); } );
更新:我刚刚注意到google.com上的脚本导致页面变慢:(我该如何解决这个问题?我在代码中做了什么来实现此行为。< / p>
答案 0 :(得分:0)
Markerclusterer很糟糕。使用这个:
http://googlemapsapi.martinpearman.co.uk/clustermarker
我的演示:http://www.stopdetelefoongids.nl/stats/(来自/includes/maps.js)