Answer the question
In order to leave comments, you need to log in
How to limit viewport in leaflet?
How to limit the area available for viewing in a leaflet so that the map cannot be moved outside the area? For example, to show only Moscow and the region, maybe by setting the coordinates somehow. Are there additional plugins for this or the basic functionality of the library?
Answer the question
In order to leave comments, you need to log in
var map = L.map('map').setView([20.5, -0.09], 3);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png').addTo(map);
var southWest = L.latLng(-60.5, -90),
northEast = L.latLng(60.5, 90);
var bounds = L.latLngBounds(southWest, northEast);
map.setMaxBounds(bounds);
map.on('drag', function() {
map.panInsideBounds(bounds, { animate: false });
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question