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

Error: You must provide a featureId to enter direct_select mode #18

Open
HuangLiPang opened this issue Aug 12, 2020 · 3 comments
Open

Comments

@HuangLiPang
Copy link

Got this error when using change mode example.

image
For reproducing it, create a line or polygon and then click the map (the feature now cannot be edited) and then double click the feature.

@garretteklof
Copy link

This seems to have to do with how the component is updating currently with mode changes:

    if (prevProps.mode !== this.props.mode) {
      this._draw.changeMode(this.props.mode, this.props.modeOptions);
    }

With a mode change, it looks like you have to account for passing in modeOptions (empty {} by default). A switch to direct_select mode requires that you pass in which featureId is being selected through the options. I haven't really dug in enough to see why this isn't a problem with simple_select -> as you can see selections still occur even with empty options. Honestly the component API (updating two separate props) for this is a little clunky, and I was running into race conditions with rendering.

The way around it for me was to forego manipulating mode in React state altogether, and handle the mode changes by manipulating them yourself with the MapboxDraw instance (via ref), which then can be listened / captured in the various event handlers.

@SebastianCJ
Copy link

This seems to have to do with how the component is updating currently with mode changes:

    if (prevProps.mode !== this.props.mode) {
      this._draw.changeMode(this.props.mode, this.props.modeOptions);
    }

With a mode change, it looks like you have to account for passing in modeOptions (empty {} by default). A switch to direct_select mode requires that you pass in which featureId is being selected through the options. I haven't really dug in enough to see why this isn't a problem with simple_select -> as you can see selections still occur even with empty options. Honestly the component API (updating two separate props) for this is a little clunky, and I was running into race conditions with rendering.

The way around it for me was to forego manipulating mode in React state altogether, and handle the mode changes by manipulating them yourself with the MapboxDraw instance (via ref), which then can be listened / captured in the various event handlers.

Do you happen to have an example of this? I'm trying to manipulate mode with React State to no avail

@hermanmitish
Copy link

This worked for me:

<Draw
      mode={mode}
      modeOptions={ {featureId: selectedFeatures[0]?.id||''} }
      onDrawSelectionChange={ (e:any)=>setSelectedFeatures(e?.features||[]) }       
      onDrawModeChange={ ({mode}:any)=>setMode(mode) } />

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

4 participants