Skip to content

Commit 7196d0d

Browse files
authored
Make add layer menus more consistent (#681)
1 parent 820e4f5 commit 7196d0d

File tree

9 files changed

+111
-278
lines changed

9 files changed

+111
-278
lines changed

packages/base/src/commands.ts

Lines changed: 5 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export function addCommands(
278278
* Source and layers
279279
*/
280280
commands.addCommand(CommandIDs.newRasterEntry, {
281-
label: trans.__('New Raster Layer'),
281+
label: trans.__('New Raster Tile Layer'),
282282
isEnabled: () => {
283283
return tracker.currentWidget
284284
? tracker.currentWidget.model.sharedModel.editable
@@ -287,14 +287,14 @@ export function addCommands(
287287
execute: Private.createEntry({
288288
tracker,
289289
formSchemaRegistry,
290-
title: 'Create Raster Layer',
290+
title: 'Create Raster Tile Layer',
291291
createLayer: true,
292292
createSource: true,
293293
sourceData: {
294294
minZoom: 0,
295295
maxZoom: 24
296296
},
297-
layerData: { name: 'Custom Raster Layer' },
297+
layerData: { name: 'Custom Raster Tile Layer' },
298298
sourceType: 'RasterSource',
299299
layerType: 'RasterLayer'
300300
}),
@@ -508,133 +508,7 @@ export function addCommands(
508508
...icons.get(CommandIDs.newGeoTiffEntry)
509509
});
510510

511-
// Layers only
512-
commands.addCommand(CommandIDs.newRasterLayer, {
513-
label: args =>
514-
args.from === 'contextMenu'
515-
? trans.__('Raster')
516-
: trans.__('Add Raster layer'),
517-
isEnabled: () => {
518-
return tracker.currentWidget
519-
? tracker.currentWidget.model.sharedModel.editable
520-
: false;
521-
},
522-
execute: Private.createEntry({
523-
tracker,
524-
formSchemaRegistry,
525-
title: 'Create Raster Layer',
526-
createLayer: true,
527-
createSource: false,
528-
layerData: {
529-
name: 'Custom Raster Layer'
530-
},
531-
sourceType: 'RasterSource',
532-
layerType: 'RasterLayer'
533-
}),
534-
...icons.get(CommandIDs.newVectorLayer)
535-
});
536-
537-
commands.addCommand(CommandIDs.newVectorLayer, {
538-
label: args =>
539-
args.from === 'contextMenu'
540-
? trans.__('Vector')
541-
: trans.__('Add New Vector layer'),
542-
isEnabled: () => {
543-
return tracker.currentWidget
544-
? tracker.currentWidget.model.sharedModel.editable
545-
: false;
546-
},
547-
execute: Private.createEntry({
548-
tracker,
549-
formSchemaRegistry,
550-
title: 'Create Vector Layer',
551-
createLayer: true,
552-
createSource: false,
553-
layerData: {
554-
name: 'Custom Vector Layer'
555-
},
556-
sourceType: 'VectorTileSource',
557-
layerType: 'VectorTileLayer'
558-
}),
559-
...icons.get(CommandIDs.newVectorLayer)
560-
});
561-
562-
commands.addCommand(CommandIDs.newHillshadeLayer, {
563-
label: args =>
564-
args.from === 'contextMenu'
565-
? trans.__('Hillshade')
566-
: trans.__('Add Hillshade layer'),
567-
isEnabled: () => {
568-
return tracker.currentWidget
569-
? tracker.currentWidget.model.sharedModel.editable
570-
: false;
571-
},
572-
execute: Private.createEntry({
573-
tracker,
574-
formSchemaRegistry,
575-
title: 'Create Hillshade Layer',
576-
createLayer: true,
577-
createSource: false,
578-
layerData: {
579-
name: 'Custom Hillshade Layer'
580-
},
581-
sourceType: 'RasterDemSource',
582-
layerType: 'HillshadeLayer'
583-
}),
584-
...icons.get(CommandIDs.newHillshadeLayer)
585-
});
586-
587-
commands.addCommand(CommandIDs.newImageLayer, {
588-
label: args =>
589-
args.from === 'contextMenu'
590-
? trans.__('Image')
591-
: trans.__('Add Image layer'),
592-
isEnabled: () => {
593-
return tracker.currentWidget
594-
? tracker.currentWidget.model.sharedModel.editable
595-
: false;
596-
},
597-
execute: Private.createEntry({
598-
tracker,
599-
formSchemaRegistry,
600-
title: 'Create Image Layer',
601-
createLayer: true,
602-
createSource: false,
603-
layerData: {
604-
name: 'Custom Image Layer'
605-
},
606-
sourceType: 'ImageSource',
607-
layerType: 'RasterLayer'
608-
}),
609-
...icons.get(CommandIDs.newImageLayer)
610-
});
611-
612-
commands.addCommand(CommandIDs.newVideoLayer, {
613-
label: args =>
614-
args.from === 'contextMenu'
615-
? trans.__('Video')
616-
: trans.__('Add Video layer'),
617-
isEnabled: () => {
618-
return tracker.currentWidget
619-
? tracker.currentWidget.model.sharedModel.editable
620-
: false;
621-
},
622-
execute: Private.createEntry({
623-
tracker,
624-
formSchemaRegistry,
625-
title: 'Create Video Layer',
626-
createLayer: true,
627-
createSource: false,
628-
layerData: {
629-
name: 'Custom Video Layer'
630-
},
631-
sourceType: 'VideoSource',
632-
layerType: 'RasterLayer'
633-
}),
634-
...icons.get(CommandIDs.newVideoLayer)
635-
});
636-
637-
commands.addCommand(CommandIDs.newShapefileLayer, {
511+
commands.addCommand(CommandIDs.newShapefileEntry, {
638512
label: trans.__('New Shapefile Layer'),
639513
isEnabled: () => {
640514
return tracker.currentWidget
@@ -652,30 +526,7 @@ export function addCommands(
652526
sourceType: 'ShapefileSource',
653527
layerType: 'VectorLayer'
654528
}),
655-
...icons.get(CommandIDs.newShapefileLayer)
656-
});
657-
658-
commands.addCommand(CommandIDs.newHeatmapLayer, {
659-
label: args =>
660-
args.from === 'contextMenu'
661-
? trans.__('Heatmap')
662-
: trans.__('Add HeatmapLayer'),
663-
isEnabled: () => {
664-
return tracker.currentWidget
665-
? tracker.currentWidget.model.sharedModel.editable
666-
: false;
667-
},
668-
execute: Private.createEntry({
669-
tracker,
670-
formSchemaRegistry,
671-
title: 'Create Heatmap Layer',
672-
createLayer: true,
673-
createSource: false,
674-
layerData: { name: 'Custom Heatmap Layer' },
675-
sourceType: 'GeoJSONSource',
676-
layerType: 'HeatmapLayer'
677-
}),
678-
...icons.get(CommandIDs.newHeatmapLayer)
529+
...icons.get(CommandIDs.newShapefileEntry)
679530
});
680531

681532
/**

packages/base/src/constants.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export namespace CommandIDs {
2929
// Layer and source
3030
export const newRasterEntry = 'jupytergis:newRasterEntry';
3131
export const newVectorTileEntry = 'jupytergis:newVectorTileEntry';
32+
export const newShapefileEntry = 'jupytergis:newShapefileEntry';
3233
export const newGeoJSONEntry = 'jupytergis:newGeoJSONEntry';
3334
export const newHillshadeEntry = 'jupytergis:newHillshadeEntry';
3435
export const newImageEntry = 'jupytergis:newImageEntry';
@@ -39,16 +40,6 @@ export namespace CommandIDs {
3940
export const buffer = 'jupytergis:buffer';
4041
export const dissolve = 'jupytergis:dissolve';
4142

42-
// Layers only commands
43-
export const newRasterLayer = 'jupytergis:newRasterLayer';
44-
export const newVectorLayer = 'jupytergis:newVectorLayer';
45-
export const newHillshadeLayer = 'jupytergis:newHillshadeLayer';
46-
export const newImageLayer = 'jupytergis:newImageLayer';
47-
export const newVideoLayer = 'jupytergis:newVideoLayer';
48-
export const newShapefileLayer = 'jupytergis:newShapefileLayer';
49-
export const newWebGlTileLayer = 'jupytergis:newWebGlTileLayer';
50-
export const newHeatmapLayer = 'jupytergis:newHeatmapLayer';
51-
5243
// Layer and group actions
5344
export const renameLayer = 'jupytergis:renameLayer';
5445
export const removeLayer = 'jupytergis:removeLayer';
@@ -103,7 +94,7 @@ const iconObject = {
10394
[CommandIDs.newHillshadeEntry]: { icon: moundIcon },
10495
[CommandIDs.newImageEntry]: { iconClass: 'fa fa-image' },
10596
[CommandIDs.newVideoEntry]: { iconClass: 'fa fa-video' },
106-
[CommandIDs.newShapefileLayer]: { iconClass: 'fa fa-file' },
97+
[CommandIDs.newShapefileEntry]: { iconClass: 'fa fa-file' },
10798
[CommandIDs.newGeoTiffEntry]: { iconClass: 'fa fa-image' },
10899
[CommandIDs.symbology]: { iconClass: 'fa fa-brush' },
109100
[CommandIDs.identify]: { icon: infoIcon },

packages/base/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ export * from './tools';
1212
export * from './types';
1313
export * from './widget';
1414
export * from './annotations';
15+
export * from './menus';

packages/base/src/menus.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Menu } from '@lumino/widgets';
2+
import { CommandRegistry } from '@lumino/commands';
3+
4+
import { CommandIDs } from './constants';
5+
import { rasterIcon } from './icons';
6+
7+
export const vectorSubMenu = (commands: CommandRegistry) => {
8+
const subMenu = new Menu({ commands });
9+
10+
subMenu.title.label = 'Add Vector Layer';
11+
subMenu.title.iconClass = 'fa fa-vector-square';
12+
subMenu.id = 'jp-gis-toolbar-vector-menu';
13+
14+
subMenu.addItem({
15+
type: 'command',
16+
command: CommandIDs.newVectorTileEntry
17+
});
18+
19+
subMenu.addItem({
20+
type: 'command',
21+
command: CommandIDs.newGeoJSONEntry
22+
});
23+
24+
subMenu.addItem({
25+
type: 'command',
26+
command: CommandIDs.newShapefileEntry
27+
});
28+
29+
return subMenu;
30+
};
31+
32+
export const rasterSubMenu = (commands: CommandRegistry) => {
33+
const subMenu = new Menu({ commands });
34+
35+
subMenu.title.label = 'Add Raster Layer';
36+
subMenu.title.icon = rasterIcon;
37+
subMenu.id = 'jp-gis-toolbar-raster-menu';
38+
39+
subMenu.addItem({
40+
type: 'command',
41+
command: CommandIDs.newRasterEntry
42+
});
43+
44+
subMenu.addItem({
45+
type: 'command',
46+
command: CommandIDs.newHillshadeEntry
47+
});
48+
49+
subMenu.addItem({
50+
type: 'command',
51+
command: CommandIDs.newImageEntry
52+
});
53+
54+
subMenu.addItem({
55+
type: 'command',
56+
command: CommandIDs.newGeoTiffEntry
57+
});
58+
59+
return subMenu;
60+
};

0 commit comments

Comments
 (0)