2013-05-02 26 views
0

我正在使用谷歌地圖,我有這個_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

怎樣才能刪除一個標誌?通過點擊地圖?如果是這樣,回調應該是在點擊事件之後而不是在動畫事件之後。 – specialscope 2013-05-02 03:55:05

+0

當地圖加載&'$(document).ready()'時, – ThomasReggi 2013-05-02 20:29:37

回答

0

這裏是一個delayMarker功能樣的工作方式和原來的一樣,除非有,可以讓你不顯示它創建一個標記,然後顯示和動畫它的方法,我不知道是否有一個更好的方法。

Demo on JSBIN

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') 
    }) 

}