我正在使用谷歌地图,我有这个_marker()
功能。我目前正在使用setTimeout
6秒来延迟回调,以便在标记被删除后运行。我一直在查看文档并尝试了类似gmaps.event.addListenerOnce(marker, 'idle', function(...
的内容而没有运气。有没有人知道标记动画丢弃事件,所以我可以合法化这个回调?
var _marker = function(place, map, callback){
var marker = new gmaps.Marker({
clickable: false,
draggable: false,
position: new gmaps.LatLng(place.latitude, place.longitude),
map: map,
animation: gmaps.Animation.DROP,
icon: new gmaps.MarkerImage(
'http://maps.google.com/mapfiles/ms/micons/red-dot.png',
new gmaps.Size(32, 32),
new gmaps.Point(0,0),
new gmaps.Point(16, 32)
)
});
if(typeof callback !== "undefined"){
setTimeout(function(){
return callback(marker);
}, 600);
}else{
return marker;
}
}
答案 0 :(得分:0)
这里的delayMarker函数与原始函数的工作方式相同,除非有一种方法允许你创建一个标记而不显示它,然后显示并设置它的动画,我不确定是否有更好的方法。
function initMap() {
var myLatLng = {lat: -25.363, lng: 131.044};
var googleMapsIcon = new google.maps.MarkerImage(
'http://maps.google.com/mapfiles/ms/micons/red-dot.png',
new google.maps.Size(32, 32),
new google.maps.Point(0,0),
new google.maps.Point(16, 32)
)
function delayMarker ({place = {}, position, map, timeout}, callback) {
var marker = {
clickable: false,
draggable: false,
position: new google.maps.LatLng(position.lat, position.lng),
map: map,
animation: google.maps.Animation.DROP,
icon: googleMapsIcon
}
if (timeout && callback) {
return setTimeout(function(){
return callback(new google.maps.Marker(marker))
}, timeout)
} else {
return marker
}
}
var map = new google.maps.Map(document.getElementById('map-canvas'), {
center: myLatLng,
scrollwheel: false,
zoom: 4
})
var marker = delayMarker({
map: map,
position: myLatLng,
timeout: 2000,
}, () => {
console.log('done')
})
}