I have a leaflet map with a lot of polygons (borders). I would like to zoom to the bounds on the polygon, when the user click.
Until now its only possible for me to zoom to the the bounds of all the polygons in the GeoJSON file.
var map = L.map('map')
.addLayer(mapboxTiles)
.setView([50.444508, -80.499491], 10);
var markers = new L.geoJson(null, {
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {})
}
});
markers.on('click', function() {
map.fitBounds(markers.getBounds());
});
markers.addTo(map);
$.getJSON('contry.php', function (data) {
markers.addData(data)
});
what to change here?
markers.on('click', function() {
map.fitBounds(markers.getBounds());
});