geoman-io / leaflet-geoman

🍂🗺️ The most powerful leaflet plugin for drawing and editing geometry layers
https://geoman.io
MIT License
2.21k stars 433 forks source link

Set maximum bound problem #341

Closed ismaildervisoglu closed 6 years ago

ismaildervisoglu commented 6 years ago

@codeofsumit I want the drawings to be made within a certain area. To do this, I tried to set the boundary with the setMaxBounds function on the map object, but it didn't work. How could I do that?

codeofsumit commented 6 years ago

Hi @ismaildervisoglu, hmm from the top of my head I would approach it like this:

I would draw an invisible polygon to set the area where you want the drawings to be made. Whenever the user draws, I would leverage the leaflet.pm events to constantly check if the currently drawn shape is within that boundry polygon. For the comparison, I would use the library turf.

This is a similar way how I disallow polygon self-intersection for example.

Hope this helps!

By the way, I'm also building a tool for more advanced geo editing like changing styles and so on. It's Geoman and I will release version 1.0 soon. You can check the current beta already here though: https//geoman.io