Skip to content

Commit 5dd5eca

Browse files
committedJun 17, 2025
Take review comments into account.
1 parent 0459a30 commit 5dd5eca

File tree

4 files changed

+49
-51
lines changed

4 files changed

+49
-51
lines changed
 

‎packages/base/src/commands.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -948,9 +948,9 @@ export function addCommands(
948948
if (!selectedLayer) {
949949
return false;
950950
} else if (model.checkIfIsADrawVectorLayer(selectedLayer) === true) {
951-
return model.isDrawVectorLayerEnabled;
951+
return model.editingVectorLayer;
952952
} else {
953-
model.isDrawVectorLayerEnabled === false;
953+
model.editingVectorLayer === false;
954954
return false;
955955
}
956956
} else {
@@ -983,14 +983,14 @@ export function addCommands(
983983
if (!selectedLayer) {
984984
return false;
985985
} else {
986-
if (model.isDrawVectorLayerEnabled === false) {
987-
model.isDrawVectorLayerEnabled = true;
986+
if (model.editingVectorLayer === false) {
987+
model.editingVectorLayer = true;
988988
} else {
989-
model.isDrawVectorLayerEnabled = false;
989+
model.editingVectorLayer = false;
990990
}
991991
}
992992

993-
model.updateIsDrawVectorLayerEnabled();
993+
model.updateEditingVectorLayer();
994994
commands.notifyCommandChanged(CommandIDs.toggleDrawFeatures);
995995
}
996996
},

‎packages/base/src/mainview/mainView.tsx

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ interface IStates {
117117
loadingErrors: Array<{ id: string; error: any; index: number }>;
118118
displayTemporalController: boolean;
119119
filterStates: IDict<IJGISFilterItem | undefined>;
120-
isDrawVectorLayerEnabled: boolean;
120+
editingVectorLayer: boolean;
121121
drawGeometryLabel: string | undefined;
122122
}
123123

@@ -170,8 +170,8 @@ export class MainView extends React.Component<IProps, IStates> {
170170
this._handleGeolocationChanged,
171171
this,
172172
);
173-
this._model.drawVectorLayerChanged.connect(
174-
this._updateIsDrawVectorLayerEnabled,
173+
this._model.editingVectorLayerChanged.connect(
174+
this._updateEditingVectorLayer,
175175
this,
176176
);
177177

@@ -201,7 +201,7 @@ export class MainView extends React.Component<IProps, IStates> {
201201
loadingErrors: [],
202202
displayTemporalController: false,
203203
filterStates: {},
204-
isDrawVectorLayerEnabled: false,
204+
editingVectorLayer: false,
205205
drawGeometryLabel: '',
206206
};
207207

@@ -250,7 +250,7 @@ export class MainView extends React.Component<IProps, IStates> {
250250

251251
this._model.sharedModel.awareness.off(
252252
'change',
253-
this._onSelectedLayerChangeHandler,
253+
this._onSelectedLayerChange,
254254
);
255255
this._mainViewModel.dispose();
256256
}
@@ -408,24 +408,13 @@ export class MainView extends React.Component<IProps, IStates> {
408408
},
409409
}));
410410

411-
/* generate select, modify and snap interactions for features of layers already added to the Map */
412-
this._select = new Select();
413-
this._modify = new Modify({
414-
features: this._select.getFeatures(),
415-
});
416-
417-
this._Map.addInteraction(this._select);
418-
this._Map.addInteraction(this._modify);
419-
420-
this._select.setActive(true);
421-
this._modify.setActive(true);
422-
411+
423412
/* Track changes of selected layers
424413
Get the vector source of the selected layer
425414
Edit the vector layer*/
426415
this._model.sharedModel.awareness.on(
427416
'change',
428-
this._onSelectedLayerChangeHandler,
417+
this._onSelectedLayerChange,
429418
);
430419
}
431420
}
@@ -1379,8 +1368,8 @@ export class MainView extends React.Component<IProps, IStates> {
13791368
const parsedGeometry = isOlGeometry
13801369
? geometry
13811370
: new GeoJSON().readGeometry(geometry, {
1382-
featureProjection: this._Map.getView().getProjection(),
1383-
});
1371+
featureProjection: this._Map.getView().getProjection(),
1372+
});
13841373

13851374
const olFeature = new Feature({
13861375
geometry: parsedGeometry,
@@ -1515,8 +1504,8 @@ export class MainView extends React.Component<IProps, IStates> {
15151504
const JGISLayer = this._model.getLayer(selectedLayerID);
15161505
if (JGISLayer) {
15171506
if (this._model.checkIfIsADrawVectorLayer(JGISLayer) === false) {
1518-
this._model.isDrawVectorLayerEnabled = false;
1519-
this._updateIsDrawVectorLayerEnabled();
1507+
this._model.editingVectorLayer = false;
1508+
this._updateEditingVectorLayer();
15201509
}
15211510
}
15221511

@@ -1767,8 +1756,8 @@ export class MainView extends React.Component<IProps, IStates> {
17671756
if (
17681757
this._model.checkIfIsADrawVectorLayer(oldLayer as IJGISLayer) === true
17691758
) {
1770-
this._model.isDrawVectorLayerEnabled = false;
1771-
this._updateIsDrawVectorLayerEnabled();
1759+
this._model.editingVectorLayer = false;
1760+
this._updateEditingVectorLayer();
17721761
this._mainViewModel.commands.notifyCommandChanged(
17731762
CommandIDs.toggleDrawFeatures,
17741763
);
@@ -2093,11 +2082,11 @@ export class MainView extends React.Component<IProps, IStates> {
20932082
// TODO SOMETHING
20942083
};
20952084

2096-
private _updateIsDrawVectorLayerEnabled() {
2097-
const isDrawVectorLayerEnabled: boolean =
2098-
this._model.isDrawVectorLayerEnabled;
2099-
this.setState(old => ({ ...old, isDrawVectorLayerEnabled }));
2100-
if (isDrawVectorLayerEnabled === false && this._draw) {
2085+
private _updateEditingVectorLayer() {
2086+
const editingVectorLayer: boolean =
2087+
this._model.editingVectorLayer;
2088+
this.setState(old => ({ ...old, editingVectorLayer }));
2089+
if (editingVectorLayer === false && this._draw) {
21012090
this._removeDrawInteraction();
21022091
}
21032092
}
@@ -2181,7 +2170,7 @@ export class MainView extends React.Component<IProps, IStates> {
21812170

21822171
_updateDrawSource = () => {
21832172
if (this._currentVectorSource) {
2184-
this._currentVectorSource.on('change', this._onVectorSourceChangeHandler);
2173+
this._currentVectorSource.on('change', this._onVectorSourceChange);
21852174
}
21862175
};
21872176

@@ -2253,11 +2242,7 @@ export class MainView extends React.Component<IProps, IStates> {
22532242
this._Map.removeInteraction(this._modify);
22542243
};
22552244

2256-
private _onVectorSourceChangeHandler = () => {
2257-
this._onVectorSourceChange();
2258-
};
2259-
2260-
private _onSelectedLayerChangeHandler = () => {
2245+
private _onSelectedLayerChange = () => {
22612246
const selectedLayers =
22622247
this._model.sharedModel.awareness.getLocalState()?.selected?.value;
22632248
const selectedLayerId = selectedLayers
@@ -2298,7 +2283,7 @@ export class MainView extends React.Component<IProps, IStates> {
22982283
);
22992284
})}
23002285

2301-
{this.state.isDrawVectorLayerEnabled && (
2286+
{this.state.editingVectorLayer && (
23022287
<div
23032288
style={{
23042289
position: 'absolute',
@@ -2325,7 +2310,7 @@ export class MainView extends React.Component<IProps, IStates> {
23252310
<option value="Select Geometry" selected hidden>
23262311
Geometry type
23272312
</option>
2328-
{drawGeometries.map(geometryType => (
2313+
{DRAW_GEOMETRIES.map(geometryType => (
23292314
<option key={geometryType} value={geometryType}>
23302315
{geometryType}
23312316
</option>

‎packages/schema/src/interfaces.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export interface IJupyterGISModel extends DocumentRegistry.IModel {
179179
geolocationChanged: Signal<IJupyterGISModel, JgisCoordinates>;
180180
flyToGeometrySignal: Signal<IJupyterGISModel, any>;
181181
highlightFeatureSignal: Signal<IJupyterGISModel, any>;
182-
drawVectorLayerChanged: Signal<IJupyterGISModel, boolean>;
182+
editingVectorLayerChanged: Signal<IJupyterGISModel, boolean>;
183183

184184
contentsManager: Contents.IManager | undefined;
185185
filePath: string;
@@ -235,9 +235,9 @@ export interface IJupyterGISModel extends DocumentRegistry.IModel {
235235
triggerLayerUpdate(layerId: string, layer: IJGISLayer): void;
236236

237237
disposed: ISignal<any, void>;
238-
isDrawVectorLayerEnabled: boolean;
238+
editingVectorLayer: boolean;
239239
checkIfIsADrawVectorLayer(JGISlayer: IJGISLayer): boolean;
240-
updateIsDrawVectorLayerEnabled(): void;
240+
updateEditingVectorLayer(): void;
241241
}
242242

243243
export interface IUserData {

‎packages/schema/src/model.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class JupyterGISModel implements IJupyterGISModel {
5555
this,
5656
);
5757
this.annotationModel = annotationModel;
58-
this.isDrawVectorLayerEnabled = false;
58+
this._editingVectorLayer = false;
5959
this.settingRegistry = settingRegistry;
6060
this._pathChanged = new Signal<JupyterGISModel, string>(this);
6161
}
@@ -740,8 +740,8 @@ export class JupyterGISModel implements IJupyterGISModel {
740740
this.updateLayerSignal.emit(JSON.stringify({ layerId, layer }));
741741
};
742742

743-
updateIsDrawVectorLayerEnabled() {
744-
this.drawVectorLayerChanged.emit(this.isDrawVectorLayerEnabled);
743+
updateEditingVectorLayer() {
744+
this._editingVectorLayerChanged.emit(this._editingVectorLayer);
745745
}
746746

747747
checkIfIsADrawVectorLayer(layer: IJGISLayer): boolean {
@@ -769,6 +769,19 @@ export class JupyterGISModel implements IJupyterGISModel {
769769
return this._geolocationChanged;
770770
}
771771

772+
get editingVectorLayer(): boolean {
773+
return this._editingVectorLayer;
774+
}
775+
776+
set editingVectorLayer(editingVectorLayer: boolean) {
777+
this._editingVectorLayer = editingVectorLayer;
778+
this.editingVectorLayerChanged.emit(this.editingVectorLayer);
779+
}
780+
781+
get editingVectorLayerChanged() {
782+
return this._editingVectorLayerChanged;
783+
}
784+
772785
readonly defaultKernelName: string = '';
773786
readonly defaultKernelLanguage: string = '';
774787
readonly annotationModel?: IAnnotationModel;
@@ -810,8 +823,8 @@ export class JupyterGISModel implements IJupyterGISModel {
810823
private _geolocation: JgisCoordinates;
811824
private _geolocationChanged = new Signal<this, JgisCoordinates>(this);
812825

813-
private editingVectorLayer: boolean;
814-
private editingVectorLayerChanged = new Signal<this, boolean>(this);
826+
private _editingVectorLayer: boolean;
827+
private _editingVectorLayerChanged = new Signal<this, boolean>(this);
815828
}
816829

817830
export namespace JupyterGISModel {

0 commit comments

Comments
 (0)