Skip to content

Commit 014cf57

Browse files
Automatically switch to identify panel when identifying (#900)
* Automatically switch to identify panel when identifying * Introduce model.currentMode + activate tab everytime the identified features change --------- Co-authored-by: martinRenou <[email protected]>
1 parent fa4ad30 commit 014cf57

File tree

7 files changed

+67
-38
lines changed

7 files changed

+67
-38
lines changed

packages/base/src/commands/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,14 @@ export function addCommands(
160160
'WebGlLayer',
161161
'VectorTileLayer',
162162
].includes(selectedLayer.type);
163-
const isIdentifying = current.model.isIdentifying;
164163

165-
if (isIdentifying && !canIdentify) {
166-
current.model.isIdentifying = false;
164+
if (current.model.currentMode === 'identifying' && !canIdentify) {
165+
current.model.currentMode = 'panning';
167166
current.node.classList.remove('jGIS-identify-tool');
168167
return false;
169168
}
170169

171-
return isIdentifying;
170+
return current.model.currentMode === 'identifying';
172171
},
173172
isEnabled: () => {
174173
if (tracker.currentWidget?.model.jgisSettings.identifyDisabled) {
@@ -198,7 +197,7 @@ export function addCommands(
198197
if (luminoEvent) {
199198
const keysPressed = luminoEvent.keys as string[] | undefined;
200199
if (keysPressed?.includes('Escape')) {
201-
current.model.isIdentifying = false;
200+
current.model.currentMode = 'panning';
202201
current.node.classList.remove('jGIS-identify-tool');
203202
commands.notifyCommandChanged(CommandIDs.identify);
204203
return;
@@ -207,6 +206,7 @@ export function addCommands(
207206

208207
current.node.classList.toggle('jGIS-identify-tool');
209208
current.model.toggleIdentify();
209+
210210
commands.notifyCommandChanged(CommandIDs.identify);
211211
},
212212
...icons.get(CommandIDs.identify),

packages/base/src/mainview/mainView.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ export class MainView extends React.Component<IProps, IStates> {
211211

212212
// Watch isIdentifying and clear the highlight when Identify Tool is turned off
213213
this._model.sharedModel.awareness.on('change', () => {
214-
const isIdentifying = this._model.isIdentifying;
215-
if (!isIdentifying && this._highlightLayer) {
214+
if (this._model.currentMode !== 'identifying' && this._highlightLayer) {
216215
this._highlightLayer.getSource()?.clear();
217216
}
218217
});
@@ -519,7 +518,7 @@ export class MainView extends React.Component<IProps, IStates> {
519518
return layer === this.getLayer(selectedLayerId);
520519
},
521520
condition: (event: MapBrowserEvent<any>) => {
522-
return singleClick(event) && this._model.isIdentifying;
521+
return singleClick(event) && this._model.currentMode === 'identifying';
523522
},
524523
style: styleFunction,
525524
});
@@ -2086,7 +2085,7 @@ export class MainView extends React.Component<IProps, IStates> {
20862085
});
20872086

20882087
private _identifyFeature(e: MapBrowserEvent<any>) {
2089-
if (!this._model.isIdentifying) {
2088+
if (this._model.currentMode !== 'identifying') {
20902089
return;
20912090
}
20922091

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ export const IdentifyPanelComponent: React.FC<IIdentifyComponentProps> = ({
5858
return;
5959
}
6060

61-
if (model.isIdentifying && featuresRef.current !== identifiedFeatures) {
61+
if (
62+
model.currentMode === 'identifying' &&
63+
featuresRef.current !== identifiedFeatures
64+
) {
6265
setFeatures(identifiedFeatures);
6366
}
6467
};

packages/base/src/panelview/rightpanel.tsx

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
IAnnotationModel,
33
IJGISFormSchemaRegistry,
4+
IJupyterGISClientState,
45
IJupyterGISModel,
56
} from '@jupytergis/schema';
67
import * as React from 'react';
@@ -23,15 +24,50 @@ interface IRightPanelProps {
2324

2425
export const RightPanel: React.FC<IRightPanelProps> = props => {
2526
const [settings, setSettings] = React.useState(props.model.jgisSettings);
27+
const tabInfo = [
28+
!settings.objectPropertiesDisabled
29+
? { name: 'objectProperties', title: 'Object Properties' }
30+
: false,
31+
!settings.annotationsDisabled
32+
? { name: 'annotations', title: 'Annotations' }
33+
: false,
34+
!settings.identifyDisabled
35+
? { name: 'identifyPanel', title: 'Identified Features' }
36+
: false,
37+
].filter(Boolean) as { name: string; title: string }[];
38+
39+
const [curTab, setCurTab] = React.useState<string | undefined>(
40+
tabInfo.length > 0 ? tabInfo[0].name : undefined,
41+
);
2642

2743
React.useEffect(() => {
2844
const onSettingsChanged = () => {
2945
setSettings({ ...props.model.jgisSettings });
3046
};
47+
let currentlyIdentifiedFeatures: any = undefined;
48+
const onAwerenessChanged = (
49+
_: IJupyterGISModel,
50+
clients: Map<number, IJupyterGISClientState>,
51+
) => {
52+
const clientId = props.model.getClientId();
53+
const localState = clientId ? clients.get(clientId) : null;
54+
55+
if (
56+
localState &&
57+
localState.identifiedFeatures?.value &&
58+
localState.identifiedFeatures.value !== currentlyIdentifiedFeatures
59+
) {
60+
currentlyIdentifiedFeatures = localState.identifiedFeatures.value;
61+
setCurTab('identifyPanel');
62+
}
63+
};
3164

3265
props.model.settingsChanged.connect(onSettingsChanged);
66+
props.model.clientStateChanged.connect(onAwerenessChanged);
67+
3368
return () => {
3469
props.model.settingsChanged.disconnect(onSettingsChanged);
70+
props.model.clientStateChanged.disconnect(onAwerenessChanged);
3571
};
3672
}, [props.model]);
3773

@@ -43,22 +79,6 @@ export const RightPanel: React.FC<IRightPanelProps> = props => {
4379
const rightPanelVisible =
4480
!settings.rightPanelDisabled && !allRightTabsDisabled;
4581

46-
const tabInfo = [
47-
!settings.objectPropertiesDisabled
48-
? { name: 'objectProperties', title: 'Object Properties' }
49-
: false,
50-
!settings.annotationsDisabled
51-
? { name: 'annotations', title: 'Annotations' }
52-
: false,
53-
!settings.identifyDisabled
54-
? { name: 'identifyPanel', title: 'Identified Features' }
55-
: false,
56-
].filter(Boolean) as { name: string; title: string }[];
57-
58-
const [curTab, setCurTab] = React.useState<string | undefined>(
59-
tabInfo.length > 0 ? tabInfo[0].name : undefined,
60-
);
61-
6282
const [selectedObjectProperties, setSelectedObjectProperties] =
6383
React.useState(undefined);
6484

packages/schema/src/interfaces.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ export interface IJupyterGISModel extends DocumentRegistry.IModel {
162162
localState: IJupyterGISClientState | null;
163163
annotationModel?: IAnnotationModel;
164164

165+
// TODO Add more modes: "annotating"
166+
currentMode: 'panning' | 'identifying';
167+
165168
themeChanged: Signal<
166169
IJupyterGISModel,
167170
IChangedArgs<string, string | null, string>
@@ -244,7 +247,6 @@ export interface IJupyterGISModel extends DocumentRegistry.IModel {
244247
centerOnPosition(id: string): void;
245248

246249
toggleIdentify(): void;
247-
isIdentifying: boolean;
248250

249251
isTemporalControllerActive: boolean;
250252
toggleTemporalController(): void;

packages/schema/src/model.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,6 @@ export class JupyterGISModel implements IJupyterGISModel {
291291
return this._zoomToPositionSignal;
292292
}
293293

294-
set isIdentifying(isIdentifying: boolean) {
295-
this._isIdentifying = isIdentifying;
296-
}
297-
298-
get isIdentifying(): boolean {
299-
return this._isIdentifying;
300-
}
301-
302294
set isTemporalControllerActive(isActive: boolean) {
303295
this._isTemporalControllerActive = isActive;
304296
}
@@ -767,7 +759,19 @@ export class JupyterGISModel implements IJupyterGISModel {
767759
}
768760

769761
toggleIdentify() {
770-
this._isIdentifying = !this._isIdentifying;
762+
if (this._currentMode === 'identifying') {
763+
this._currentMode = 'panning';
764+
} else {
765+
this._currentMode = 'identifying';
766+
}
767+
}
768+
769+
get currentMode(): 'panning' | 'identifying' {
770+
return this._currentMode;
771+
}
772+
773+
set currentMode(value: 'panning' | 'identifying') {
774+
this._currentMode = value;
771775
}
772776

773777
toggleTemporalController() {
@@ -865,6 +869,8 @@ export class JupyterGISModel implements IJupyterGISModel {
865869
private _settingsChanged: Signal<JupyterGISModel, string>;
866870
private _jgisSettings: IJupyterGISSettings;
867871

872+
private _currentMode: 'panning' | 'identifying';
873+
868874
private _sharedModel: IJupyterGISDoc;
869875
private _filePath: string;
870876
private _contentsManager?: Contents.IManager;
@@ -892,7 +898,6 @@ export class JupyterGISModel implements IJupyterGISModel {
892898

893899
private _updateLayerSignal = new Signal<this, string>(this);
894900

895-
private _isIdentifying = false;
896901
private _isTemporalControllerActive = false;
897902

898903
static worker: Worker;

python/jupytergis_lab/src/notebookrenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import {
2020
JupyterFrontEnd,
2121
JupyterFrontEndPlugin,
2222
} from '@jupyterlab/application';
23-
import { ISettingRegistry } from '@jupyterlab/settingregistry';
2423
import { showErrorMessage } from '@jupyterlab/apputils';
2524
import { ConsolePanel } from '@jupyterlab/console';
2625
import { PathExt } from '@jupyterlab/coreutils';
2726
import { NotebookPanel } from '@jupyterlab/notebook';
2827
import { Contents } from '@jupyterlab/services';
28+
import { ISettingRegistry } from '@jupyterlab/settingregistry';
2929
import { IStateDB } from '@jupyterlab/statedb';
3030
import { Toolbar } from '@jupyterlab/ui-components';
3131
import { CommandRegistry } from '@lumino/commands';

0 commit comments

Comments
 (0)