Skip to content

Commit

Permalink
Respect selectedFeatureIndex passed from user
Browse files Browse the repository at this point in the history
  • Loading branch information
Xintong Xia committed Sep 30, 2019
1 parent 65bb8c9 commit f4fdc62
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/api-reference/react-map-gl-draw/react-map-gl-draw.md
Expand Up @@ -12,8 +12,8 @@
- `EditorModes.DRAW_POINT` - Lets you draw a GeoJson `Point` feature.
- `EditorModes.DRAW_RECTANGLE` - Lets you draw a `Rectangle` (represented as GeoJson `Polygon` feature).

- `features` (Feature[], Optional) - List of features in GeoJson format. If `features` are provided from users, then `react-map-gl-draw` respect the users' input, and therefore ignore any internal `features`. But if `features` are not provided, then `react-map-gl-draw` manages `features` internally, and users can access and manipulate the features by calling `getFeatures`, `addFeatures`, and `deleteFeatures`.
- `selectedFeatureIndex` (String, Optional) - Index of the selected feature.
- `features` (Feature[], Optional) - List of features in GeoJson format. `react-map-gl-draw` respect the user' input `features`. If not provided, will manage `features` internally, and user can access and manipulate the `features` by calling `getFeatures`, `addFeatures`, and `deleteFeatures`.
- `selectedFeatureIndex` (String, Optional) - Index of the selected feature. If not provided, will manage it internally.
- `clickRadius` (Number, Optional) - Radius to detect features around a hovered or clicked point. Default value is `0`

- `onSelect` (Function, Optional) - callback when clicking a position under `SELECT` and `EDITTING` mode. Receives an object containing the following parameters
Expand Down
2 changes: 0 additions & 2 deletions examples/react-map-gl-draw/app.js
Expand Up @@ -27,7 +27,6 @@ export default class App extends Component {
features: [],
selectedFeatureIndex: null
};
this._mapRef = null;
this._editorRef = null;
}

Expand Down Expand Up @@ -68,7 +67,6 @@ export default class App extends Component {
return (
<MapGL
{...viewport}
ref={_ => (this._mapRef = _)}
width="100%"
height="100%"
mapStyle={MAP_STYLE}
Expand Down
7 changes: 4 additions & 3 deletions modules/react-map-gl-draw/src/mode-handler.js
Expand Up @@ -204,9 +204,10 @@ export default class ModeHandler extends PureComponent<EditorProps, EditorState>
};

_getSelectedFeatureIndex = () => {
return isNumeric(this.props.selectedFeatureIndex)
? this.props.selectedFeatureIndex
: this.state.selectedFeatureIndex;
if ('selectedFeatureIndex' in this.props) {
return this.props.selectedFeatureIndex;
}
return this.state.selectedFeatureIndex;
};

_getSelectedFeature = (featureIndex: ?number) => {
Expand Down

0 comments on commit f4fdc62

Please sign in to comment.