Leaflet / Leaflet.Editable

Make geometries editable in Leaflet.
http://leaflet.github.io/Leaflet.Editable/doc/api.html
553 stars 198 forks source link

Limit radius of editable circle #201

Open magnuswikhog opened 4 years ago

magnuswikhog commented 4 years ago

I can't find a way to limit the radius of an editable circle. For example, I want the smallest possible radius to be 1000 meters, and if the user tries to make it smaller the radius just stays at 1000 meters.

I looked at cancelable events in the API documentation, but I can't see any that would fit my use case.

HIRANO-Satoshi commented 4 years ago

Hi, set limit like this.

    mapEventHandler(evt: Leaflet.LeafletEvent) {
       if (evt.type === 'editable:vertex:dragend' || evt.type === 'editable:vertex:drag') {
           if (circle.getRadius() > 1000) 
                 circle.setRadius(1000);
HIRANO-Satoshi commented 4 years ago

Do you have a good way to limit the size of rectangles?

iyuuya commented 10 months ago

Hi, set limit like this.

    mapEventHandler(evt: Leaflet.LeafletEvent) {
       if (evt.type === 'editable:vertex:dragend' || evt.type === 'editable:vertex:drag') {
           if (circle.getRadius() > 1000) 
                 circle.setRadius(1000);

Its good, but there was still a problem. Marker no longer follows the circle.

https://github.com/Leaflet/Leaflet.Editable/assets/147351/4269b9e3-39a5-4bcc-9037-4f0952ccd83d

https://github.com/Leaflet/Leaflet.Editable/issues/204#issuecomment-1766495572

The only workaround I have found so far is to call disableEdit() before and enableEdit() after changing bounds. This does not allow changing bounds in real time and only reliably works on dragend and editable:vertex:dragend events.

I tried this, but it difficult to operate.