E
E
Evgeny Perin2017-03-28 19:05:54
JavaScript
Evgeny Perin, 2017-03-28 19:05:54

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

3 answer(s)
M
Moskus, 2017-03-28
@Moskus

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 });
});

V
Vitaly Stolyarov, 2017-03-28
@Ni55aN

Is it leafletjs.com/reference.html#map-maxbounds?

I
ipatovstyle, 2017-04-03
@ipatovstyle

It's called EXTENT look for a lot of solutions there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question