Skip to content

Commit 673bfd6

Browse files
Take review comments into account.
1 parent 0459a30 commit 673bfd6

File tree

4 files changed

+45
-49
lines changed

4 files changed

+45
-49
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: 18 additions & 35 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,12 @@ 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-
423411
/* Track changes of selected layers
424412
Get the vector source of the selected layer
425413
Edit the vector layer*/
426414
this._model.sharedModel.awareness.on(
427415
'change',
428-
this._onSelectedLayerChangeHandler,
416+
this._onSelectedLayerChange,
429417
);
430418
}
431419
}
@@ -1515,8 +1503,8 @@ export class MainView extends React.Component<IProps, IStates> {
15151503
const JGISLayer = this._model.getLayer(selectedLayerID);
15161504
if (JGISLayer) {
15171505
if (this._model.checkIfIsADrawVectorLayer(JGISLayer) === false) {
1518-
this._model.isDrawVectorLayerEnabled = false;
1519-
this._updateIsDrawVectorLayerEnabled();
1506+
this._model.editingVectorLayer = false;
1507+
this._updateEditingVectorLayer();
15201508
}
15211509
}
15221510

@@ -1767,8 +1755,8 @@ export class MainView extends React.Component<IProps, IStates> {
17671755
if (
17681756
this._model.checkIfIsADrawVectorLayer(oldLayer as IJGISLayer) === true
17691757
) {
1770-
this._model.isDrawVectorLayerEnabled = false;
1771-
this._updateIsDrawVectorLayerEnabled();
1758+
this._model.editingVectorLayer = false;
1759+
this._updateEditingVectorLayer();
17721760
this._mainViewModel.commands.notifyCommandChanged(
17731761
CommandIDs.toggleDrawFeatures,
17741762
);
@@ -2093,11 +2081,10 @@ export class MainView extends React.Component<IProps, IStates> {
20932081
// TODO SOMETHING
20942082
};
20952083

2096-
private _updateIsDrawVectorLayerEnabled() {
2097-
const isDrawVectorLayerEnabled: boolean =
2098-
this._model.isDrawVectorLayerEnabled;
2099-
this.setState(old => ({ ...old, isDrawVectorLayerEnabled }));
2100-
if (isDrawVectorLayerEnabled === false && this._draw) {
2084+
private _updateEditingVectorLayer() {
2085+
const editingVectorLayer: boolean = this._model.editingVectorLayer;
2086+
this.setState(old => ({ ...old, editingVectorLayer }));
2087+
if (editingVectorLayer === false && this._draw) {
21012088
this._removeDrawInteraction();
21022089
}
21032090
}
@@ -2181,7 +2168,7 @@ export class MainView extends React.Component<IProps, IStates> {
21812168

21822169
_updateDrawSource = () => {
21832170
if (this._currentVectorSource) {
2184-
this._currentVectorSource.on('change', this._onVectorSourceChangeHandler);
2171+
this._currentVectorSource.on('change', this._onVectorSourceChange);
21852172
}
21862173
};
21872174

@@ -2253,11 +2240,7 @@ export class MainView extends React.Component<IProps, IStates> {
22532240
this._Map.removeInteraction(this._modify);
22542241
};
22552242

2256-
private _onVectorSourceChangeHandler = () => {
2257-
this._onVectorSourceChange();
2258-
};
2259-
2260-
private _onSelectedLayerChangeHandler = () => {
2243+
private _onSelectedLayerChange = () => {
22612244
const selectedLayers =
22622245
this._model.sharedModel.awareness.getLocalState()?.selected?.value;
22632246
const selectedLayerId = selectedLayers
@@ -2298,7 +2281,7 @@ export class MainView extends React.Component<IProps, IStates> {
22982281
);
22992282
})}
23002283

2301-
{this.state.isDrawVectorLayerEnabled && (
2284+
{this.state.editingVectorLayer && (
23022285
<div
23032286
style={{
23042287
position: 'absolute',
@@ -2325,7 +2308,7 @@ export class MainView extends React.Component<IProps, IStates> {
23252308
<option value="Select Geometry" selected hidden>
23262309
Geometry type
23272310
</option>
2328-
{drawGeometries.map(geometryType => (
2311+
{DRAW_GEOMETRIES.map(geometryType => (
23292312
<option key={geometryType} value={geometryType}>
23302313
{geometryType}
23312314
</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)