💚 This is the latest document.
Removes all markers, polylines, polygons, overlays, etc from the map.
<div class="map" id="map_canvas">
<span class="smallPanel"><button>Click here</button></span>
</div>
var div = document.getElementById("map_canvas");
var map = plugin.google.maps.Map.getMap(div);
var button = div.getElementsByTagName('button')[0];
button.addEventListener('click', function() {
// Removes the markers completely.
map.clear(function() {
alert("completed");
});
});
// In order to get the visible region safely, you need to wait the MAP_READY event.
map.one(plugin.google.maps.event.MAP_READY, createMarkers);
function createMarkers() {
var latLngBounds = map.getVisibleRegion();
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 < 100; i++) {
map.addMarker({
'position': {
'lat': sw.lat + diffY * Math.random(),
'lng': sw.lng + diffX * Math.random()
}
});
}
}