2011-07-20 67 views
5

我使用gmaps的jquery-UI-map,並且我想在點擊Gmaps上的地圖時彈出。刪除jquery刪除按鈕上的所有gmaps標記

$(function() {    
       $('#map_canvas').gmap({'center': new google.maps.LatLng(-0.789275, 113.921327), 'callback': function(map) { 
         $(map).click(function(event) { 
          $('#map_canvas').gmap('addMarker', {'position': event.latLng, 'title': '', 'draggable': true, 'bound': false}, function(map, marker) { 
          $('#test').dialog({'modal':true, 'title': 'Edit and save point', 'buttons': { 
          "Remove": function() { 
           $(this).dialog("close"); 
           $(map).setMap(null); 
          }, 
          "Save": function() { 
           $(this).dialog("close"); 
          } 
         }}); 
           findLocation(marker.getPosition(), marker); 
          }).dragend(function(event) { 
           var self = this; 
           findLocation(event.latLng, this); 
          }).click(function() { 
           openDialog(this); 
          }) 
         }); 
        }}); 

我要刪除所有標記時,我在此代碼點擊刪除按鈕:

"Remove": function() { 
          $(this).dialog("close"); 
          $(map).setMap(null);} 

但標誌依然存在,有人請幫助我。謝謝

回答

6

你應該叫

$('#map_canvas').gmap('clearMarkers'); 
+0

你是天才johansalllarsson,謝謝。有用 ! –

+3

Np,我寫了插件,所以我應該知道:)。請接受答案,只要你有時間:) – johansalllarsson

+0

我得到'未捕獲TypeError:無法讀取屬性'應用'未定義'當我調用此代碼,任何想法爲什麼? –

0

還沒有和之前的插件,但在API文檔快速瀏覽工作似乎表明,這可能工作:

"Remove": function() { 
     $(this).dialog("close"); 
     $(map).clearMarkers(); 
} 
17

在插件版本3應該使用:

$('#map_canvas').gmap('clear', 'markers');