react-leaflet-draw icon indicating copy to clipboard operation
react-leaflet-draw copied to clipboard

How to use ref to programmatically activate edit

Open ghost opened this issue 7 years ago • 3 comments

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 {.. }
    ...
    />);
}

ghost avatar May 03 '17 23:05 ghost

Did you ever find an answer for this @vietnugent ?

iredmedia avatar Mar 28 '18 06:03 iredmedia

@vietnugent @iredmedia hello guys, have you solved this?

klijakub avatar Aug 22 '18 08:08 klijakub


                            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

MehdiJarraya avatar Feb 21 '19 11:02 MehdiJarraya