2014-01-22 23 views
0

我使用的地圖工具執行JavaScript的谷歌地圖API V3: http://nettique.free.fr/gmap/toolbar.html谷歌地圖API V3 - 地圖工具實現 - setTimeout的爲DBLCLICK變焦

它的工作太棒了!我唯一的問題是,我想讓dblclick事件在創建多邊形時縮放,但現在,如果我雙擊,我創建一個新標記並立即刪除它。

使用舊版本的我的代碼,我使用的是像超時這裏解釋: https://stackoverflow.com/a/8417447/1895428

但現在,無論在哪裏我把setTimeout函數,它沒有任何變化。有誰知道把它放在哪裏?

我試圖修改的js代碼(http://nettique.free.fr/gmap/lib/mapToolbar.js)的addPoint功能,但它沒有工作:

addPoint : function(e, poly, index) { //alert(MapToolbar["shapeCounter"]); 
     update_timeout = setTimeout(function(){ 
     var e = (typeof e.latLng != "undefined")? e.latLng : e, 
      image = new google.maps.MarkerImage('/image/marker-edition.png', 
      new google.maps.Size(9, 9), 
      new google.maps.Point(0, 0), 
      new google.maps.Point(5, 5)), 
     imageover = new google.maps.MarkerImage('/image/marker-edition-over.png', 
      new google.maps.Size(9, 9), 
      new google.maps.Point(0, 0), 
      new google.maps.Point(5, 5)), 
       path = poly.getPath(), 
       index = (typeof index != "undefined")? index : path.length, 
       markers = (poly.markers)? poly.markers : new google.maps.MVCArray, 
     marker = new google.maps.Marker({ 
        position: e, 
        map: map[mapkey], 
        draggable: true, 
        icon: image 
     }); 

     marker.index = index;  
     path.insertAt(index, e); 
     markers.insertAt(index, marker) 
     if(arguments[2]){ 
      MapToolbar.reindex(markers);  
     } }, 200); 

//click on a polymarker will delete it 

     google.maps.event.addListener(marker, 'click', function() { 
      marker.setMap(null); 
      markers.removeAt(marker.index); 
      path.removeAt(marker.index); 
      MapToolbar.reindex(markers);     
      if(markers.getLength() == 0){ 
       MapToolbar.removeFeature(poly.id); 
      } 
     }); 

/* 
     google.maps.event.addListener(marker, 'dragstart', function() { 
       MapToolbar.currentlyDragging = true; 
     }) 
*/  
     google.maps.event.addListener(marker, 'position_changed', function() { 
       path.setAt(marker.index, marker.getPosition()); 
     }) 

     google.maps.event.addListener(marker, 'dragend', function() { 
       //MapToolbar.currentlyDragging = false; 
      path.setAt(marker.index, marker.getPosition()); 
      var position = marker.getPosition(), 
        p; 

//get previous point 

      if(typeof path.getAt(marker.index-1) != "undefined"){ 
       var m1 = path.getAt(marker.index -1); 
         p = MapToolbar.getMidPoint(position, m1);  
         MapToolbar.addPoint(p, poly, marker.index);      
      } 

// get next point 

      if(typeof path.getAt(marker.index+1) != "undefined"){ 
       var m2 = path.getAt(marker.index+1); 
         p = MapToolbar.getMidPoint(position, m2);  
         MapToolbar.addPoint(p, poly, marker.index+1);      
      }   
     }); 

     google.maps.event.addListener(marker, 'mouseover', function() { 
       this.setIcon(imageover); 
     }); 

     google.maps.event.addListener(marker, 'mouseout', function() { 
       this.setIcon(image); 
     }); 

     MapToolbar["isStarted"]++; 
    } 

回答

0

不知道這是否會工作,但下面的例子計算器你必須改變只監聽器代碼:

addPoint : function(e, poly, index) { 
    var e = (typeof e.latLng != "undefined")? e.latLng : e, 
    ... 

//click on a polymarker will delete it 

    var update_timeout = null; 

    google.maps.event.addListener(marker, 'click', function() { 
     update_timeout = setTimeout(function() { 
      marker.setMap(null); 
      markers.removeAt(marker.index); 
      path.removeAt(marker.index); 
      MapToolbar.reindex(markers);     
      if(markers.getLength() == 0){ 
       MapToolbar.removeFeature(poly.id); 
      } 
     }, 200); 
    }); 

    google.maps.event.addListener(marker, 'dblclick', function(event) {  
     clearTimeout(update_timeout); 
    }); 
    ... 
+0

仍然沒有工作......無論如何,這click事件是,如果你點擊它來刪除標記,我更找上addPoint事件設置超時。 – pmrotule