删除jquery删除按钮上的所有gmaps标记

Bij*_*ufi 5 jquery-ui jquery-gmap

我使用jquery-UI-map作为gmaps,我想在点击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);
                            })
                        });
                    }});
Run Code Online (Sandbox Code Playgroud)

我想在此代码中单击删除按钮时删除所有标记:

 "Remove": function() {
                            $(this).dialog( "close" );
                           $(map).setMap(null);}
Run Code Online (Sandbox Code Playgroud)

但标记仍然存在,有人请帮助我.谢谢

Gat*_*ics 17

在插件版本3中应该使用:

$('#map_canvas').gmap('clear', 'markers');
Run Code Online (Sandbox Code Playgroud)


joh*_*son 6

你应该打电话

$('#map_canvas').gmap('clearMarkers');
Run Code Online (Sandbox Code Playgroud)

  • Np,我写了插件所以我应该知道:).只要你有时间,请接受答案:) (3认同)