Skip to content

Commit

Permalink
[fix] previous drawn-selected geometries are lost after click Select …
Browse files Browse the repository at this point in the history
…geometry (#2175)

Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
Co-authored-by: Xun Li <lixun910@gmail.com>
  • Loading branch information
igorDykhta and lixun910 committed Apr 4, 2023
1 parent 79d8c75 commit 4c6e99e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/components/src/map-container.tsx
Expand Up @@ -620,6 +620,7 @@ export default function MapContainerFactory(
isBase={compareMode}
onSetFeatures={this.props.visStateActions.setFeatures}
setSelectedFeature={this.props.visStateActions.setSelectedFeature}
featureCollection={this.featureCollectionSelector(this.props)}
/>
)}
{layerHoverProp && (!layerPinnedProp || compareMode) && (
Expand All @@ -632,6 +633,7 @@ export default function MapContainerFactory(
coordinate={interactionConfig.coordinate.enabled && coordinate}
onSetFeatures={this.props.visStateActions.setFeatures}
setSelectedFeature={this.props.visStateActions.setSelectedFeature}
featureCollection={this.featureCollectionSelector(this.props)}
/>
)}
</ErrorBoundary>
Expand Down
14 changes: 11 additions & 3 deletions src/components/src/map/map-popover.tsx
Expand Up @@ -229,6 +229,10 @@ export type MapPopoverProps = {
onClose: () => void;
onSetFeatures: (features: Feature[]) => any;
setSelectedFeature: (feature: Feature, clickContext: object) => any;
featureCollection?: {
type: string;
features: Feature[];
};
};

type IntlProps = {
Expand All @@ -249,7 +253,8 @@ export default function MapPopoverFactory(
container,
onClose,
onSetFeatures,
setSelectedFeature
setSelectedFeature,
featureCollection
}) => {
const [horizontalPlacement, setHorizontalPlacement] = useState('start');
const moveLeft = () => setHorizontalPlacement('end');
Expand All @@ -264,10 +269,13 @@ export default function MapPopoverFactory(
const selectedFeature = getSelectedFeature(layerHoverProp);
if (selectedFeature) {
setSelectedFeature(selectedFeature, clickContext);
onSetFeatures([selectedFeature]);
const updatedFeatures = featureCollection
? [...featureCollection.features, selectedFeature]
: [selectedFeature];
onSetFeatures(updatedFeatures);
}
onClose();
}, [onClose, onSetFeatures, x, y, setSelectedFeature, layerHoverProp]);
}, [onClose, onSetFeatures, x, y, setSelectedFeature, layerHoverProp, featureCollection]);

return (
<RootContext.Consumer>
Expand Down
3 changes: 2 additions & 1 deletion test/browser-headless/component/map-container-test.js
Expand Up @@ -301,7 +301,8 @@ function testMapPopoverProp(t, mapPopoverProp) {
y: 200,
zoom: 13,
onSetFeatures: sinon.spy(),
setSelectedFeature: sinon.spy()
setSelectedFeature: sinon.spy(),
featureCollection: {type: 'FeatureCollection', features: []}
};
t.deepEqual(
Object.keys(mapPopoverProp).sort(),
Expand Down

0 comments on commit 4c6e99e

Please sign in to comment.