Leaflet / Leaflet.Editable

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

Add Leaflet.Editable after map creation? #165

Closed ThomasDaheim closed 6 years ago

ThomasDaheim commented 6 years ago

Hi,

I would like to add Leaflet.Editable to a map that has already been created elsewhere. So far I have tried something like

var options = L.Util.extend(myMap.options, {editable: true});
myMap.initialize(myMap._leaflet_id, options);

but that leads to an error in map.initialize.

Is there any way to make an existing map editable? Unfortunately, I don't have control over the code that creates the map in the first place.

vlasvlasvlas commented 6 years ago

same here!

yohanboniface commented 6 years ago

Basically what's done here:

https://github.com/Leaflet/Leaflet.Editable/blob/master/src/Leaflet.Editable.js#L432

In other words

map.editTools = L.Editable(myMap, {options goes here})
ThomasDaheim commented 6 years ago

Thanks! But if I do

myMap.editTools = L.Editable(myMap, {editable: true});

I get

TypeError: this.callInitHooks is not a function. (In 'this.callInitHooks()', 'this.callInitHooks' is undefined)

Any other ideas?

yohanboniface commented 6 years ago

Sorry, missing "new" keyword:

map.editTools = new L.Editable(myMap, {options goes here})
ThomasDaheim commented 6 years ago

Thanks! Works like a charm now :-)