0

Into my application I use L.Draw plugin and I need to use (into a my specific application feature) a custom editing logic (for example I have to change the way to show the edit-markers) for a Polygon.

I analized the L.draw code and I think that I have to override the _initMarkers function that it is present into L.Edit.PolyVerticesEdit.

This L.Edit.PolyVerticesEdit is initialized in the _initHandlers function that it is present into the L.Edit.Poly;

This L.Edit.Poly is initialized in the L.Polyline.addInitHook function.

If this my analysis is correct, I think that I need of:

  • A custom handler (like Rectangle, Polyline, Marker, etc). for example 'L.MyHandler' that it extends the Polygon base handler (I already have others custom handlers).
  • I have to define a custom PolyVerticesEdit and a custom L.Edit.MyHandler to use the custom _initMarkers function only when the custom handler is used;

In theory, I think that is a solution because, in my application, a need to have this custom edit mode and the class L.Draw editing logic also (for other application features);

But I think that it is strange to have this big override flow only to have a custom editing logic.

Is correct this my solution? Is there a different approach?

  • There are two different approaches: one is official and the other is hack. Official and correct one is to modify _initMarkers function by extending original object with extend method (see explanation of concept at leafletjs.com/examples/extending/extending-2-layers.html). The other is of course directly editing relevant plugin code. – TomazicM Nov 22 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.