react-leaflet-draw
react-leaflet-draw copied to clipboard
How to use ref to programmatically activate edit
I want to activate drawing mode from outside of leaflet-draw component (without requiring the user to click on the the Edit icon). I tried to set up a ref
but it's 'undefined' - understandably so the first time render() is called. How do I use ref in this case to make direct calls to draw plugin methods?
render() {
console.log(this.editControl); // undefined
return (<EditControl ref={(ref)=>{
this.editControl=ref;
console.log(this.editControl)}} // Object {.. }
...
/>);
}
Did you ever find an answer for this @vietnugent ?
@vietnugent @iredmedia hello guys, have you solved this?
var toolbar;
let drawControl = this.props.editControlRef.leafletElement;
for (var toolbarId in drawControl._toolbars) {
toolbar = drawControl._toolbars[toolbarId];
if (toolbar instanceof L.EditToolbar) {
console.log(" costum edit toolbar issss", toolbar)
toolbar._modes.edit.handler.enable();
}
}
-this.props.editControlRef is a reference to your EditControl component