Skip to content

Commit fe750d8

Browse files
Support identifying features in vector tile layers (#852)
* Restore earthquakes.jGIS example * Made identify features work with vector tile * Solve lint * Made suggested changes and add simple highlighting * Made suggested changes * Better highlighting logic * Update packages/base/src/mainview/mainView.tsx * lint --------- Co-authored-by: Arjun Verma <[email protected]> Co-authored-by: arjxn-py <[email protected]>
1 parent f930954 commit fe750d8

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed

examples/earthquakes.jGIS

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@
194194
"options": {
195195
"bearing": 0.0,
196196
"extent": [
197-
-18039043.293897964,
198-
-4847443.5412946865,
199-
1383665.5829297584,
200-
13318211.842235815
197+
-19456309.48732131,
198+
-3639686.263420881,
199+
2800931.776353102,
200+
12110454.564362008
201201
],
202202
"latitude": 35.52446437432016,
203203
"longitude": -74.80890180273175,

packages/base/src/commands/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export function addCommands(
158158
'VectorLayer',
159159
'ShapefileLayer',
160160
'WebGlLayer',
161+
'VectorTileLayer',
161162
].includes(selectedLayer.type);
162163
const isIdentifying = current.model.isIdentifying;
163164

@@ -174,9 +175,12 @@ export function addCommands(
174175
if (!selectedLayer) {
175176
return false;
176177
}
177-
return ['VectorLayer', 'ShapefileLayer', 'WebGlLayer'].includes(
178-
selectedLayer.type,
179-
);
178+
return [
179+
'VectorLayer',
180+
'ShapefileLayer',
181+
'WebGlLayer',
182+
'VectorTileLayer',
183+
].includes(selectedLayer.type);
180184
},
181185
execute: args => {
182186
const current = tracker.currentWidget;

packages/base/src/mainview/mainView.tsx

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import {
7272
transformExtent,
7373
} from 'ol/proj';
7474
import { register } from 'ol/proj/proj4.js';
75-
import RenderFeature from 'ol/render/Feature';
75+
import RenderFeature, { toGeometry } from 'ol/render/Feature';
7676
import {
7777
GeoTIFF as GeoTIFFSource,
7878
ImageTile as ImageTileSource,
@@ -650,7 +650,10 @@ export class MainView extends React.Component<IProps, IStates> {
650650
const features = tile.getFeatures();
651651

652652
if (features && features.length > 0) {
653-
this._model.syncTileFeatures({ sourceId: id, features });
653+
this._model.syncTileFeatures({
654+
sourceId: id,
655+
features,
656+
});
654657
}
655658
});
656659

@@ -2101,6 +2104,48 @@ export class MainView extends React.Component<IProps, IStates> {
21012104
const jgisLayer = this._model.getLayer(layerId);
21022105

21032106
switch (jgisLayer?.type) {
2107+
case 'VectorTileLayer': {
2108+
const geometries: Geometry[] = [];
2109+
const features: any[] = [];
2110+
2111+
this._Map.forEachFeatureAtPixel(e.pixel, (feature: FeatureLike) => {
2112+
let geom: Geometry | undefined;
2113+
2114+
if (feature instanceof RenderFeature) {
2115+
geom = toGeometry(feature);
2116+
} else if ('getGeometry' in feature) {
2117+
geom = feature.getGeometry();
2118+
}
2119+
2120+
const props = feature.getProperties();
2121+
2122+
if (geom) {
2123+
geometries.push(geom);
2124+
}
2125+
features.push({
2126+
...props,
2127+
});
2128+
2129+
return true;
2130+
});
2131+
2132+
if (features.length > 0) {
2133+
this._model.syncIdentifiedFeatures(features, this._mainViewModel.id);
2134+
}
2135+
2136+
if (geometries.length > 0) {
2137+
for (const geom of geometries) {
2138+
this._model.highlightFeatureSignal.emit(geom);
2139+
}
2140+
} else {
2141+
const coordinate = this._Map.getCoordinateFromPixel(e.pixel);
2142+
const point = new Point(coordinate);
2143+
this._model.highlightFeatureSignal.emit(point);
2144+
}
2145+
2146+
break;
2147+
}
2148+
21042149
case 'WebGlLayer': {
21052150
const layer = this.getLayer(layerId) as WebGlTileLayer;
21062151
const data = layer.getData(e.pixel);

0 commit comments

Comments
 (0)