Skip to content

Commit ec064da

Browse files
Fix double click bug while identifying vectorTileLayers (#908)
* Fix double click bug while identifying vectorTileLayers * move property to bottom * Add TODO comment --------- Co-authored-by: martinRenou <[email protected]>
1 parent 634a4be commit ec064da

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

packages/base/src/mainview/mainView.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,30 +2104,48 @@ export class MainView extends React.Component<IProps, IStates> {
21042104
case 'VectorTileLayer': {
21052105
const geometries: Geometry[] = [];
21062106
const features: any[] = [];
2107+
let foundAny = false;
21072108

21082109
this._Map.forEachFeatureAtPixel(e.pixel, (feature: FeatureLike) => {
2110+
foundAny = true;
2111+
21092112
let geom: Geometry | undefined;
2113+
let props = {};
21102114

21112115
if (feature instanceof RenderFeature) {
21122116
geom = toGeometry(feature);
21132117
} else if ('getGeometry' in feature) {
21142118
geom = feature.getGeometry();
21152119
}
21162120

2117-
const props = feature.getProperties();
2121+
const rawProps = feature.getProperties();
2122+
const fid = feature.getId?.() ?? rawProps?.fid;
2123+
2124+
if (rawProps && Object.keys(rawProps).length > 1) {
2125+
const { geometry, ...clean } = rawProps;
2126+
props = clean;
2127+
if (fid !== null) {
2128+
// TODO Clean the cache under some condition?
2129+
this._featurePropertyCache.set(fid, props);
2130+
}
2131+
} else if (fid !== null && this._featurePropertyCache.has(fid)) {
2132+
props = this._featurePropertyCache.get(fid);
2133+
}
21182134

21192135
if (geom) {
21202136
geometries.push(geom);
21212137
}
2122-
features.push({
2123-
...props,
2124-
});
2138+
if (props && Object.keys(props).length > 0) {
2139+
features.push(props);
2140+
}
21252141

21262142
return true;
21272143
});
21282144

21292145
if (features.length > 0) {
21302146
this._model.syncIdentifiedFeatures(features, this._mainViewModel.id);
2147+
} else if (!foundAny) {
2148+
this._model.syncIdentifiedFeatures([], this._mainViewModel.id);
21312149
}
21322150

21332151
if (geometries.length > 0) {
@@ -2335,4 +2353,5 @@ export class MainView extends React.Component<IProps, IStates> {
23352353
private _state?: IStateDB;
23362354
private _formSchemaRegistry?: IJGISFormSchemaRegistry;
23372355
private _annotationModel?: IAnnotationModel;
2356+
private _featurePropertyCache: Map<string | number, any> = new Map();
23382357
}

0 commit comments

Comments
 (0)