Leaflet / Leaflet.draw

Vector drawing and editing plugin for Leaflet
https://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html
MIT License
1.96k stars 992 forks source link

Display unit (km/miles/feet) options don't work for edit mode #992

Open thully opened 4 years ago

thully commented 4 years ago

If I draw a circle with Leaflet.draw, it will show the current radius in the units specified in the options ( feet, yards/miles, or m/km). However, if I later edit that circle, the radius does not appear in current versions of Leaflet.draw.

The lack of display of the radius seems to have been caused by a previous commit: https://github.com/Leaflet/Leaflet.draw/commit/c6b1532b0cb0ca51e231bc80e7bb886726140b13#diff-0a330404f4aac96edc644bfa17041f90

I suspect the intention was to test this._map._editTooltip instead of this._map.editTooltip.

If I make that change locally, the radius display works when editing, but the units used are always km/m, regardless of any options set. This seems to be caused by a combination of issues - _resize in L.Edit.Circle always passes true for the metric argument to readableDistance, and the options in L.Edit.Circle for units are never set regardless.

Fixing the lack of options in L.Edit.Circle (and other Edit classes) is a bit more complex - that object is constructed via an input hook to L.Circle, the latter which doesn't have the options used for units. To fix this locally, I ended up modifying the _fireCreatedEvent in L.Draw.Feature to set the options in layer.editing (the L.Edit object) to those from the L.Draw object. That way, the options are supplied for all L.Edit objects. It would be perhaps cleaner to supply these in the constructor to the L.Edit object, but that would require constructing this somewhere other than an init hook on the Leaflet object (and thus require more refactoring).

Here's a JSFiddle which shows some basic edit controls that can demonstrate the issue:

https://jsfiddle.net/sp80brge/