0
可以說我在我的谷歌地圖上有兩個cricle物體。
我想在創建3秒後從地圖中刪除每個圓。如何在不同的時間間隔後隱藏Google地圖圈對象?
這是代碼。問題是,setTimeout只適用於我創建的最後一個圓。
我該如何讓它工作?
var map;
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(centerLan, centerLon),
zoom: 10
};
map = new google.maps.Map(document.getElementById("map"), mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
function setAlarm(lon, lat) {
var alarmPosition = {
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 0,
fillColor: '#FF0000',
fillOpacity: 0.35,
map: map,
center: new google.maps.LatLng(lon, lat),
radius: Math.sqrt(150) * 100
};
// Add the circle for this city to the map.
cityCircle = new google.maps.Circle(alarmPosition);
//trying to remove the circle after some time
setTimeout(function() {
cityCircle.setMap(null);
}, 3000);
}
你在哪裏調用'setAlarm'?我猜你已經三次叫它了? – putvande
@putvande我從json文件讀取cordinations,然後將這些線纜發送到setAlarm()函數來創建一個圓。圈數是動態的。但是對於這個例子,我只用了2.所以,circle的數量=對setAlarm()的調用次數。 – Vandervidi