Skip to content

Map.clear()

wf9a5m75 edited this page Sep 24, 2014 · 5 revisions

Remove all mark-ups, such as marker.

###Description Removes all markers, polylines, polygons, overlays, etc from the map.

Important! This method does not remove event listeners. You need to call map.off() separately if you want to reset.


###Code

map.getVisibleRegion(function(latLngBounds) {
  var sw = latLngBounds.southwest;
  var ne = latLngBounds.northeast;
  var diffY = (ne.lat - sw.lat);
  var diffX = (ne.lng - sw.lng);
  
  for (var i = 0; i < 10; i++) {
    var latLng = new plugin.google.maps.LatLng(sw.lat + diffY * Math.random() , sw.lng  + diffX * Math.random());
    
    map.addMarker({
      'position': latLng
    }, function(marker) {
      map.on("test", function() {
        alert("test");
      });
    });
  }
});

$("#clearBtn").click(function() {
  map.clear();
  map.off();
  map.trigger("test");
});

Join the official community

New versions will be announced through the official community. Stay tune!

Do you have a question or feature request?

Feel free to ask me on the issues tracker.

Or on the official community is also welcome!


New version 2.0-beta2 is available.

The cordova-googlemaps-plugin v2.0 has more faster, more features.

https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/tree/master/v2.0.0/README.md

Clone this wiki locally