我目前有一个在onclick上创建的poly,点击一个标记就会被删除,并从最后一个标记创建一条线。按下时,每个标记在infowindow内都有另一个地图。
我的问题是,当我创建一个新标记时,所有以前的标记都会获得相同的信息窗口,现在我明白为什么会这样做,只是不确定如何解决它!我可以告诉markerReg被设置为所有标记。首先调用函数region(),然后是代码:
function region()
{
bounds = new google.maps.LatLngBounds();
listener = google.maps.event.addListener(map, 'click', addPoint);
path.clear();
while (markers.length) {
markers.pop().setMap(null);
}
if (poly)
{
poly.setMap(null);
}
var colour = document.getElementById("regionColour");
var pickedColour = colour.options[colour.selectedIndex].value;
poly = new google.maps.Polygon({
strokeWeight: 3,
strokeOpacity: 0.7,
fillOpacity: 0.9,
fillColor: pickedColour
});
poly.setMap(map);
poly.setPaths(new google.maps.MVCArray([path]));
markerCenter.setMap(null);
}
function stopPath()
{
google.maps.event.clearListeners(map, 'click');
}
function clearPath()
{
bounds = null;
google.maps.event.clearListeners(map, 'click');
path.clear();
poly.setMap(null);
while (markers.length) {
markers.pop().setMap(null);
}
markerCenter.setMap(null);
}
function addPoint(event) {
path.insertAt(path.length, event.latLng);
markerReg = new google.maps.Marker({
position: event.latLng,
map: map
});
google.maps.event.addListener(markerReg, 'rightclick', function () {
var detailDiv = document.createElement('div');
detailDiv.style.width = '200px';
detailDiv.style.height = '200px';
document.getElementById('googleMap').appendChild(detailDiv);
var overviewOpts = {
zoom: 15,
center: markerReg.getPosition(),
mapTypeId: map.getMapTypeId(),
disableDefaultUI: true
};
var detailMap = new google.maps.Map(detailDiv, overviewOpts);
if (!infoWindowMini)
infoWindowMini = new google.maps.InfoWindow();
infoWindowMini.setContent(detailDiv);
infoWindowMini.open(map, markerReg);
});
markers.push(markerReg);
markerReg.setTitle("#" + path.length);
centerMarker();
}