Google지도에 2 개의 cricle 개체가 있다고 가정 해 보겠습니다.
생성 후 3 초 후에지도에서 각 원을 제거하고 싶습니다.
이것은 코드입니다. 문제는
내가 만든 마지막 서클에 대해서만 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);
}
변수를 로컬로 만듭니다.
//note the var-keyword
var cityCircle = new google.maps.Circle(alarmPosition);
그렇지 않으면의 각 호출에 덮어 쓰여 setAlarm
지며 마지막 호출에서 생성 된 원만 제거 할 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다