Skip to content

Commit 5d8651f

Browse files
Add logics to use the source of the currently selected layer in the _handleDrawGeometryTypeChange method of the MainView class.
1 parent 28b6649 commit 5d8651f

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

packages/base/src/commands.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,6 @@ export function addCommands(
173173
},
174174
isEnabled: () => {
175175
const selectedLayer = getSingleSelectedLayer(tracker);
176-
console.log('In Identify, selected Type:', selectedLayer?.type);
177-
178176
if (!selectedLayer) {
179177
return false;
180178
}
@@ -887,6 +885,7 @@ export function addCommands(
887885
if (!selectedLayer) {
888886
return false;
889887
}
888+
890889
const canDrawVectorLayer = ['VectorLayer'].includes(selectedLayer.type);
891890

892891
if (
@@ -895,6 +894,12 @@ export function addCommands(
895894
) {
896895
const model = tracker.currentWidget?.content.currentViewModel
897896
.jGISModel as IJupyterGISModel;
897+
const parameters = selectedLayer.parameters;
898+
if (parameters) {
899+
const selectedvectorLayerSourceId = parameters?.source;
900+
model.selectedVectorLayerSourceId = selectedvectorLayerSourceId;
901+
}
902+
898903
return model.isDrawVectorLayerEnabled;
899904
} else {
900905
return false;

packages/base/src/mainview/mainView.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,19 +2037,31 @@ export class MainView extends React.Component<IProps, IStates> {
20372037
if (this._currentDrawInteraction) {
20382038
this._removeCurrentDrawInteraction();
20392039
}
2040-
const source = new VectorSource();
2040+
2041+
const layers = this._Map.getLayers().getArray();
2042+
const matchingLayer = layers.find(layer => {
2043+
const layerSource = layer.get('source');
2044+
return (
2045+
layerSource.get('id') === this._model.selectedVectorLayerSourceId
2046+
);
2047+
});
2048+
let source;
2049+
if (matchingLayer) {
2050+
source = matchingLayer.get('source');
2051+
} else {
2052+
source = new VectorSource();
2053+
}
20412054
const vectorLayer = new VectorLayer({
2042-
source: source,
2043-
style: {
2055+
source: source
2056+
/*style: {
20442057
'fill-color': 'rgba(255, 255, 255, 0.2)',
20452058
'stroke-color': '#ffcc33',
20462059
'stroke-width': 2,
20472060
'circle-radius': 7,
20482061
'circle-fill-color': '#ffcc33'
2049-
}
2062+
}*/
20502063
});
20512064
this._Map.addLayer(vectorLayer);
2052-
console.log('vector layer:', vectorLayer.getSource()?.getFeatures());
20532065
const modify = new Modify({ source: source });
20542066
this._Map.addInteraction(modify);
20552067
const draw = new Draw({

packages/schema/src/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ export interface IJupyterGISModel extends DocumentRegistry.IModel {
235235
disposed: ISignal<any, void>;
236236
isDrawVectorLayerEnabled: boolean;
237237
updateIsDrawVectorLayerEnabled(): void;
238+
selectedVectorLayerSourceId: string;
238239
}
239240

240241
export interface IUserData {

packages/schema/src/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,6 @@ export class JupyterGISModel implements IJupyterGISModel {
735735

736736
updateIsDrawVectorLayerEnabled() {
737737
this.drawVectorLayerChanged.emit(this.isDrawVectorLayerEnabled);
738-
console.log('Signal emitted');
739738
}
740739

741740
get geolocation(): JgisCoordinates {
@@ -792,6 +791,7 @@ export class JupyterGISModel implements IJupyterGISModel {
792791

793792
public isDrawVectorLayerEnabled: boolean;
794793
public drawVectorLayerChanged = new Signal<this, boolean>(this);
794+
public selectedVectorLayerSourceId = '';
795795
}
796796

797797
export namespace JupyterGISModel {

0 commit comments

Comments
 (0)