bluehalo / ngx-leaflet-draw

MIT License
88 stars 29 forks source link

Initiating Edit and Delete function without toolbar does not work #72

Closed 666Ben closed 5 years ago

666Ben commented 5 years ago

Hi,

I use my own toolbar for drawing polygons,.... using ngx-leaflet-draw this works perfect using the following code

const drawer = new L.Draw.Polygon(this.map, cOptions);
drawer.enable();

Now I also want to add Edit and Delete functionality to my own toolbar. I found JS examples how to initiate edit / delete :

new L.EditToolbar.Edit(map, {
                featureGroup: drawControl.options.featureGroup,
                selectedPathOptions: drawControl.options.edit.selectedPathOptions
            })

Unfortunately this does not seem to work in my Angular 7, ngx-leaflet-draw setup. L.EditToolbar.Edit is known to typescript, but as a second parameter it expects toolbaroptions. which I can not find anywhere. And it does not seem to correspond with the JS examples I found. So, I'm not sure if this is a ngx-leaflet-draw thing or maybe an error in the typedefinitions for leaflet-draw. Any suggestion how I can make this work?

reblace commented 5 years ago

A lot of times, it's a typings issue with getting the compiler to recognize the parameters as the correct type. It's not really an ngx-leaflet specific issue, and more of a Typescript and type definitions issue. But, the solution is usually pretty straightforward. You can usually just cast to any to get it to work, e.g.,

new L.EditToolbar.Edit(map, {
                featureGroup: drawControl.options.featureGroup,
                selectedPathOptions: drawControl.options.edit.selectedPathOptions
            } as any) // <==
666Ben commented 5 years ago

That works! Many Thanks!