Skip to content

Commit 340db85

Browse files
Add a toggle button to enable to add a draw vector layer.
Add a isDrawVectorLayerEnabled property to the JupyterGISModel.
1 parent 93689d8 commit 340db85

File tree

8 files changed

+60
-2
lines changed

8 files changed

+60
-2
lines changed

packages/base/src/commands.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
} from './processing';
3434
import { fromLonLat } from 'ol/proj';
3535
import { Coordinate } from 'ol/coordinate';
36-
import { targetWithCenterIcon } from './icons';
36+
import { pencilSolidIcon, targetWithCenterIcon } from './icons';
3737

3838
interface ICreateEntry {
3939
tracker: JupyterGISTracker;
@@ -1027,6 +1027,32 @@ export function addCommands(
10271027
icon: targetWithCenterIcon
10281028
});
10291029

1030+
commands.addCommand(CommandIDs.newDrawVectorLayer, {
1031+
label: trans.__('Create New Draw Vector Layer'),
1032+
isToggled: () => {
1033+
if (tracker.currentWidget instanceof JupyterGISDocumentWidget) {
1034+
const model = tracker.currentWidget?.content.currentViewModel
1035+
.jGISModel as IJupyterGISModel;
1036+
return model.isDrawVectorLayerEnabled;
1037+
} else {
1038+
return false;
1039+
}
1040+
},
1041+
execute: async () => {
1042+
if (tracker.currentWidget instanceof JupyterGISDocumentWidget) {
1043+
const model = tracker.currentWidget?.content.currentViewModel
1044+
.jGISModel as IJupyterGISModel;
1045+
if (model.isDrawVectorLayerEnabled === true) {
1046+
model.isDrawVectorLayerEnabled = false;
1047+
} else {
1048+
model.isDrawVectorLayerEnabled = true;
1049+
}
1050+
commands.notifyCommandChanged(CommandIDs.newDrawVectorLayer);
1051+
}
1052+
},
1053+
icon: pencilSolidIcon
1054+
});
1055+
10301056
loadKeybindings(commands, keybindings);
10311057
}
10321058

packages/base/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export namespace CommandIDs {
4848
export const newShapefileLayer = 'jupytergis:newShapefileLayer';
4949
export const newWebGlTileLayer = 'jupytergis:newWebGlTileLayer';
5050
export const newHeatmapLayer = 'jupytergis:newHeatmapLayer';
51+
export const newDrawVectorLayer = 'jupytergis:newDrawVectorLayer';
5152

5253
// Layer and group actions
5354
export const renameLayer = 'jupytergis:renameLayer';

packages/base/src/icons.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import terminalToolbarSvgStr from '../style/icons/terminal_toolbar.svg';
2323
import geolocationSvgStr from '../style/icons/geolocation.svg';
2424
import targetWithoutCenterSvgStr from '../style/icons/target_without_center.svg';
2525
import targetWithCenterSvgStr from '../style/icons/target_with_center.svg';
26+
import pencilSolidSvgStr from '../style/icons/pencil_solid.svg';
2627

2728
export const logoIcon = new LabIcon({
2829
name: 'jupytergis::logo',
@@ -108,3 +109,8 @@ export const targetWithCenterIcon = new LabIcon({
108109
name: 'jupytergis::targetWithoutCenter',
109110
svgstr: targetWithoutCenterSvgStr
110111
});
112+
113+
export const pencilSolidIcon = new LabIcon({
114+
name: 'jupytergis::pencilSolid',
115+
svgstr: pencilSolidSvgStr
116+
});

packages/base/src/mainview/mainView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ interface IStates {
106106
loadingErrors: Array<{ id: string; error: any; index: number }>;
107107
displayTemporalController: boolean;
108108
filterStates: IDict<IJGISFilterItem | undefined>;
109+
drawVectorLayerEnabled: boolean;
109110
}
110111

111112
export class MainView extends React.Component<IProps, IStates> {
@@ -168,7 +169,8 @@ export class MainView extends React.Component<IProps, IStates> {
168169
scale: 0,
169170
loadingErrors: [],
170171
displayTemporalController: false,
171-
filterStates: {}
172+
filterStates: {},
173+
drawVectorLayerEnabled: false
172174
};
173175

174176
this._sources = [];

packages/base/src/toolbar/widget.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ export class ToolbarWidget extends ReactiveToolbar {
101101

102102
geolocationButton.node.dataset.testid = 'geolocation-button';
103103

104+
const newDrawVectorLayerButton = new CommandToolbarButton({
105+
id: CommandIDs.newDrawVectorLayer,
106+
commands: options.commands,
107+
label: ''
108+
});
109+
this.addItem('DrawVectorLayer', newDrawVectorLayerButton);
110+
111+
newDrawVectorLayerButton.node.dataset.testid =
112+
'new-draw-vector-layer-button';
113+
104114
// vector sub menu
105115
const vectorSubMenu = new Menu({ commands: options.commands });
106116

Lines changed: 9 additions & 0 deletions
Loading

packages/schema/src/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ export interface IJupyterGISModel extends DocumentRegistry.IModel {
231231
triggerLayerUpdate(layerId: string, layer: IJGISLayer): void;
232232

233233
disposed: ISignal<any, void>;
234+
isDrawVectorLayerEnabled: boolean;
234235
}
235236

236237
export interface IUserData {

packages/schema/src/model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class JupyterGISModel implements IJupyterGISModel {
5050
this
5151
);
5252
this.annotationModel = annotationModel;
53+
this.isDrawVectorLayerEnabled = false;
5354
}
5455

5556
private _onSharedModelChanged = (sender: any, changes: any): void => {
@@ -757,6 +758,8 @@ export class JupyterGISModel implements IJupyterGISModel {
757758

758759
private _geolocation: JgisCoordinates;
759760
private _geolocationChanged = new Signal<this, JgisCoordinates>(this);
761+
762+
public isDrawVectorLayerEnabled: boolean;
760763
}
761764

762765
export namespace JupyterGISModel {

0 commit comments

Comments
 (0)