Not sure how to ask this; but Is there a way of keeping the map in the canvas?

477 Views Asked by At

Hi I was wondering if there was a way to limit the amount you can move the map so that you can't get to a gray area off the map. For instance having the initial view of the map be the farthest you can zoom out and that map would not move at all. However, when you zoom you would be able to move the map only to the edges of the map. Thanks.

1

There are 1 best solutions below

0
On

maxBoundsViscosity of 1 makes the bounds fully solid, preventing the user from dragging outside the bounds.

      <MapContainer
        maxBounds={[[-90, -360], [90, 360]]}
        maxBoundsViscosity={1}
      >
      </MapContainer