Give the everything example add/remove buttons

This commit is contained in:
danzel
2012-07-20 16:27:50 +12:00
parent d8317c04ba
commit 643757df40

View File

@@ -19,6 +19,8 @@
<body>
<div id="map"></div>
<button id="populate">Populate 1 marker</button>
<button id="remove">Remove 1 marker</button>
<span>Mouse over a cluster to see the bounds of its children and click a cluster to zoom to those bounds</span>
<script type="text/javascript">
@@ -87,6 +89,25 @@
populate();
map.addLayer(markers);
//Ugly add/remove code
L.DomUtil.get('populate').onclick = function () {
var bounds = map.getBounds(),
southWest = bounds.getSouthWest(),
northEast = bounds.getNorthEast(),
lngSpan = northEast.lng - southWest.lng,
latSpan = northEast.lat - southWest.lat;
var m = new L.Marker(new L.LatLng(
southWest.lat + latSpan * 0.5,
southWest.lng + lngSpan * 0.5));
markersList.push(m);
markers.addLayer(m);
};
L.DomUtil.get('remove').onclick = function () {
markers.removeLayer(markersList.pop());
};
</script>
</body>
</html>