In Leaflet, I am trying to create a function that restores the initial position and zoom level of a layer containing coordinates. The code below
function refresh() {
map.fitBounds(coordLayer.getBounds();
}
centers the marker but is zoomed in to the maxZoom I had set:
var map = L.map('map').setView([lat, lon], 6);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' {
maxZoom: 13,
minZoom: 2,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
The default zoom level on page refresh is 6, but I don't know how to create a function that centers the marker at zoom level 6.
Found a simple solution after reading the Documentation:
function refresh() {
map.setView([lat, lon], 6);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With