Skip to content

Commit 3b09d6b

Browse files
authored
Indicate the point being identified on GeoTiFF (#659)
* Indicate the point being identified on GeoTiFF * lint * disable highlight button of geotiff
1 parent 5a2634b commit 3b09d6b

File tree

3 files changed

+55
-21
lines changed

3 files changed

+55
-21
lines changed

packages/base/src/mainview/mainView.tsx

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ import { FollowIndicator } from './FollowIndicator';
8585
import TemporalSlider from './TemporalSlider';
8686
import { MainViewModel } from './mainviewmodel';
8787
import { Spinner } from './spinner';
88-
import { Geometry } from 'ol/geom';
88+
import { Geometry, Point } from 'ol/geom';
8989

9090
interface IProps {
9191
viewModel: MainViewModel;
@@ -1295,24 +1295,31 @@ export class MainView extends React.Component<IProps, IStates> {
12951295
});
12961296
}
12971297

1298-
private highlightFeatureOnMap(sender: IJupyterGISModel, feature: any): void {
1299-
console.log('highlightFeatureOnMap', feature);
1298+
private highlightFeatureOnMap(
1299+
sender: IJupyterGISModel,
1300+
featureOrGeometry: any
1301+
): void {
1302+
const geometry =
1303+
featureOrGeometry?.geometry ||
1304+
featureOrGeometry?._geometry ||
1305+
featureOrGeometry;
13001306

1301-
const geometry = feature._geometry || feature.geometry;
13021307
if (!geometry) {
1303-
console.warn('No geometry found on feature:', feature);
1308+
console.warn('No geometry found in feature:', featureOrGeometry);
13041309
return;
13051310
}
13061311

13071312
const isOlGeometry = typeof geometry.getCoordinates === 'function';
13081313

1314+
const parsedGeometry = isOlGeometry
1315+
? geometry
1316+
: new GeoJSON().readGeometry(geometry, {
1317+
featureProjection: this._Map.getView().getProjection()
1318+
});
1319+
13091320
const olFeature = new Feature({
1310-
geometry: isOlGeometry
1311-
? geometry
1312-
: new GeoJSON().readGeometry(geometry, {
1313-
featureProjection: this._Map.getView().getProjection()
1314-
}),
1315-
...feature
1321+
geometry: parsedGeometry,
1322+
...(geometry !== featureOrGeometry ? featureOrGeometry : {})
13161323
});
13171324

13181325
if (!this._highlightLayer) {
@@ -1925,6 +1932,12 @@ export class MainView extends React.Component<IProps, IStates> {
19251932
this._mainViewModel.id
19261933
);
19271934

1935+
const coordinate = this._Map.getCoordinateFromPixel(e.pixel);
1936+
const point = new Point(coordinate);
1937+
1938+
// trigger highlight via signal
1939+
this._model.highlightFeatureSignal.emit(point);
1940+
19281941
break;
19291942
}
19301943
}

packages/base/src/panelview/components/identify-panel/IdentifyPanel.tsx

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,31 @@ const IdentifyPanelComponent = ({
176176
<span>Feature {featureIndex + 1}</span>
177177
</span>
178178

179-
<button
180-
className="jgis-highlight-button"
181-
onClick={e => {
182-
e.stopPropagation();
183-
highlightFeatureOnMap(feature);
184-
}}
185-
title="Highlight feature on map"
186-
>
187-
<FontAwesomeIcon icon={faMagnifyingGlass} />
188-
</button>
179+
{(() => {
180+
const isRasterFeature =
181+
!feature.geometry &&
182+
!feature._geometry &&
183+
typeof feature?.x !== 'number' &&
184+
typeof feature?.y !== 'number';
185+
186+
return (
187+
<button
188+
className="jgis-highlight-button"
189+
onClick={e => {
190+
e.stopPropagation();
191+
highlightFeatureOnMap(feature);
192+
}}
193+
title={
194+
isRasterFeature
195+
? 'Highlight not available for raster features'
196+
: 'Highlight feature on map'
197+
}
198+
disabled={isRasterFeature}
199+
>
200+
<FontAwesomeIcon icon={faMagnifyingGlass} />
201+
</button>
202+
);
203+
})()}
189204
</div>
190205
{visibleFeatures[featureIndex] && (
191206
<>

python/jupytergis_lab/style/base.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,3 +773,9 @@ div.jGIS-toolbar-widget > div.jp-Toolbar-item:last-child {
773773
.jgis-highlight-button:hover {
774774
color: var(--jp-brand-color1);
775775
}
776+
777+
.jgis-highlight-button:disabled {
778+
opacity: 0.4;
779+
cursor: not-allowed;
780+
pointer-events: auto;
781+
}

0 commit comments

Comments
 (0)