Skip to content

Commit

Permalink
Merge pull request #3532 from terrestris/fix-feature-clone
Browse files Browse the repository at this point in the history
fix: keep feature id in `CoordinateInfo`
  • Loading branch information
dnlkoch authored Sep 19, 2023
2 parents d009370 + fb7c5c6 commit a983302
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/CoordinateInfo/CoordinateInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import OlMap from 'ol/Map';
import OlMapBrowserEvent from 'ol/MapBrowserEvent';

import _isString from 'lodash/isString';
import _cloneDeep from 'lodash/cloneDeep';

import Logger from '@terrestris/base-util/dist/Logger';

Expand Down Expand Up @@ -233,18 +234,16 @@ export class CoordinateInfo extends React.Component<CoordinateInfoProps, Coordin
}

getCoordinateInfoState(): CoordinateInfoState {
const featuresClone: { [name: string]: OlFeature[] } = {};
Object.entries(this.state.features)
.forEach(([layerName, feats]) => {
featuresClone[layerName] = feats.map(feat => feat.clone());
});

// We're cloning the click coordinate and features to
// not pass the internal state reference to the parent component.
// Also note that we explicitly don't use feature.clone() to
// keep all feature properties (in particular the id) intact.
const coordinateInfoState: CoordinateInfoState = {
clickCoordinate: this.state.clickCoordinate ?
[...this.state.clickCoordinate] :
_cloneDeep(this.state.clickCoordinate) :
null,
loading: this.state.loading,
features: featuresClone
features: _cloneDeep(this.state.features)
};

return coordinateInfoState;
Expand Down

0 comments on commit a983302

Please sign in to comment.