Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instantiate a new drawing with a custom control #145

Open
cscrum opened this issue May 16, 2023 · 1 comment
Open

instantiate a new drawing with a custom control #145

cscrum opened this issue May 16, 2023 · 1 comment

Comments

@cscrum
Copy link

cscrum commented May 16, 2023

I'm attempting to create a custom control to draw a polygon. I can successfully add the toolbar and draw a polygon using the buttons, but I want to do this through a custom toolbar. I'm trying this:

this.polygonDrawer = new Draw.Polygon(this.map,{
metric: false,
feet: false,
shapeOptions: {
color: '#85bb65',
},
})

however it doesn't like the this.map argument. this.map is the instance of my leaflet map in the Angular project. I get an error:
Argument of type 'Map' is not assignable to parameter of type 'DrawMap'.
Type 'Map' is missing the following properties from type 'DrawMap': mergeOptions, addInitHook

DrawMap seems to be a specific type that I can't find a reference for, but TS tells me it is this:
DrawMap(element: string | HTMLElement, options?: MapOptions): DrawMap
I'm not sure how this is supposed to relate to the leaflet map. Why would I need a different reference to the map other than the map I already have?

@nikoes
Copy link

nikoes commented Oct 26, 2023

import * as L from 'leaflet';

this.currentlyDrawnShape = new L.Draw.Circle(this.mapInstance as L.DrawMap, this.drawOptions.draw.circle); this.currentlyDrawnShape.enable();

This is how I made it and it works...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants