bluehalo / ngx-leaflet-draw

MIT License
88 stars 29 forks source link

instantiate a new drawing with a custom control #145

Open cscrum opened 1 year ago

cscrum commented 1 year ago

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 commented 10 months ago

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...