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 drawing programatically #116

Open
cscrum opened this issue Aug 17, 2021 · 1 comment
Open

instantiate drawing programatically #116

cscrum opened this issue Aug 17, 2021 · 1 comment

Comments

@cscrum
Copy link

cscrum commented Aug 17, 2021

I am needing to draw a rectangle on the map without having to press a button. I'm having difficulty figuring out how to put the map into drawing mode without the button. I've tried based on examples from leaflet-draw, but nothing seems to be working for me. Is there a way to enable the drawing mode to add a rectangle programatically?

@cscrum
Copy link
Author

cscrum commented Aug 17, 2021

I have tried this based on other issues here, but I keep getting an error.
setRectmode(){
var self = this;
var shapeOptions = {
stroke: true,
color: '#f06eaa',
weight: 4,
opacity: 0.5,
fill: true,
fillColor: null, //same as color by default
fillOpacity: 0.2,
clickable: true,
editable: true
};
var rectDraw = new (L as any).Draw.Rectangle(self.map, shapeOptions); <<<error here
rectDraw.enable();
this.drawnItems.addLayer(rectDraw);
}

ERROR TypeError: Cannot read property 'Rectangle' of undefined

  I've also tried changing the line where the error occurs to this
  var rectDraw = new (L as any).Rectangle(self.map, shapeOptions);

  ERROR TypeError: Cannot read property 'lat' of undefined

Any pointers as to what I might be doing wrong? The goal is to put the map into a mode where I can draw a rectangle on the map.

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

1 participant