我有一个由Google Maps
和using MarkerClusterer
构建的网站。此网站在大多数情况下都能正常运行,但有时会有多个用户在线,并且过滤的标记集请求将被错误地返回。
示例:我根据一组过滤器参数过滤到一组标记。由于这是处理其他人也过滤到一组不同的标记,这些标记将返回给我而不是我的请求。
如果我坐在页面上并点击刷新,我也会看到此问题。我已在2个用户的测试环境中测试过。通过让一个用户过滤到一组标记,当第二个用户刷新其浏览器窗口时,他们会看到同一组过滤的标记。第一个用户的标记。
我见过示例修复,如果通过向URL添加日期来讨论使用CacheBuster
,但在使用MarkerCluserer
代码时,我看不到将其添加到选项的位置。它也被要求不要这样做。
数据来自服务器中的数组对象。 markerclusterer.js位于Visual Studio项目的本地。以下是生成地图的页面上的脚本:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.11&sensor=false"></script>
<script type="text/javascript" src="/Scripts/markerclusterer.js"></script>
<script type="text/javascript">
var infowindow;
var map;
var markerdataLength; //en - 5-8-2013
var prev;
$(document).ready(function () {
setTimeout("gmarkers()", 500);
});
function gmarkers() {
markerdataLength = 0;
$("#map_canvas").fadeTo(500, 0.3);
$("#pwait").show();
$.ajax({
type: "POST",
url: "MapSearch.aspx/GetMarkers",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$("#map_canvas").fadeTo(0, 0.3);
$("#pwait").show();
var markerdata;
markerdata = msg.d;
msg = null;
var latlng = new google.maps.LatLng(52.50, -98.35);
var myOptions = {
zoom: 3,
center: latlng,
//mapTypeId: google.maps.MapTypeId.HYBRID,
mapTypeId: google.maps.MapTypeId.TERRAIN,
mapTypeControl: true,
mapTypeControlOptions: {
position: google.maps.ControlPosition.TOP_RIGHT
},
panControl: true,
panControlOptions: {
position: google.maps.ControlPosition.TOP_LEFT
},
zoomControl: true,
zoomControlOptions: {
position: google.maps.ControlPosition.TOP_LEFT
},
scaleControl: true,
scaleControlOptions: {
position: google.maps.ControlPosition.BOTTOM_CENTER
},
streetViewControl: true,
streetViewControlOptions: {
position: google.maps.ControlPosition.TOP_LEFT
}
};
//initialize the info window (balloon popup)
infowindow = new google.maps.InfoWindow();
//draw the map with the above settings
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
/***************************MARKER CLUSTERER **********************************************/
var imageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x24&chco=' +
'FFFFFF,008CFF,000000&ext=.png'; //Blue
var markers = [];
if (markerdata != "undefined" & markerdata.length > 0) { //run this code if the data is not null. data is the markers in json format
markerdataLength = markerdata.length; //en - 5-8-2013
var i = 0;
var ro = new RepeatingOperation(function () {
var dataWell = markerdata[i];
var mlatLng = new google.maps.LatLng(dataWell.la, dataWell.lo);
var marker = new google.maps.Marker({
id: dataWell.id,
position: mlatLng,
title: dataWell.t,
icon: imageUrl //iconstring
});
//set the marker click code to show the info window
var fn = markerClick(dataWell.id);
google.maps.event.addListener(marker, 'click', fn);
google.maps.event.addListener(marker, 'clusteringend', clusteringDone()); //en - 5-8-2013
markers.push(marker);
if (++i < markerdata.length) { ro.step(); }
else {
var mcOptions = {
gridSize: 90, //default grid size is 60 was using 35. higher #'s draw faster.
maxZoom: 20, //defines how close u are before no more clusters are drawn
minimumClusterSize: 15
};
var mc = new MarkerClusterer(map, markers, mcOptions);
}
}, 100);
ro.step();
}
else {
alert("No wells were found.");
$("#map_canvas").fadeTo(300, 1);
$("#pwait").hide();
}
}
});
}