1
1
import { JupyterFrontEnd } from '@jupyterlab/application' ;
2
- import { Dialog , WidgetTracker } from '@jupyterlab/apputils' ;
2
+ import { WidgetTracker } from '@jupyterlab/apputils' ;
3
3
import { ITranslator } from '@jupyterlab/translation' ;
4
4
import { redoIcon , undoIcon } from '@jupyterlab/ui-components' ;
5
5
6
6
import {
7
- IDict ,
8
7
IJGISFormSchemaRegistry ,
9
- IJGISLayer ,
10
- IJGISLayerBrowserRegistry ,
11
- IJGISSource ,
12
- IJupyterGISModel
8
+ IJGISLayerBrowserRegistry
13
9
} from '@jupytergis/schema' ;
14
- import { UUID } from '@lumino/coreutils' ;
15
- import { FormDialog } from './formdialog' ;
16
10
17
11
import { LayerBrowserWidget } from './layerBrowser/layerBrowserDialog' ;
18
12
import { JupyterGISWidget } from './widget' ;
@@ -65,17 +59,6 @@ export function addCommands(
65
59
icon : undoIcon
66
60
} ) ;
67
61
68
- commands . addCommand ( CommandIDs . newRasterLayer , {
69
- label : trans . __ ( 'New Tile Layer' ) ,
70
- isEnabled : ( ) => {
71
- return tracker . currentWidget
72
- ? tracker . currentWidget . context . model . sharedModel . editable
73
- : false ;
74
- } ,
75
- iconClass : 'fa fa-map' ,
76
- execute : Private . createRasterSourceAndLayer ( tracker )
77
- } ) ;
78
-
79
62
commands . addCommand ( CommandIDs . openLayerBrowser , {
80
63
label : trans . __ ( 'Open Layer Browser' ) ,
81
64
isEnabled : ( ) => {
@@ -84,7 +67,11 @@ export function addCommands(
84
67
: false ;
85
68
} ,
86
69
iconClass : 'fa fa-book-open' ,
87
- execute : Private . createLayerBrowser ( tracker , layerBrowserRegistry )
70
+ execute : Private . createLayerBrowser (
71
+ tracker ,
72
+ layerBrowserRegistry ,
73
+ formSchemaRegistry
74
+ )
88
75
} ) ;
89
76
}
90
77
@@ -95,7 +82,6 @@ export namespace CommandIDs {
95
82
export const redo = 'jupytergis:redo' ;
96
83
export const undo = 'jupytergis:undo' ;
97
84
98
- export const newRasterLayer = 'jupytergis:newRasterLayer' ;
99
85
export const openLayerBrowser = 'jupytergis:openLayerBrowser' ;
100
86
}
101
87
@@ -121,7 +107,8 @@ namespace Private {
121
107
122
108
export function createLayerBrowser (
123
109
tracker : WidgetTracker < JupyterGISWidget > ,
124
- layerBrowserRegistry : IJGISLayerBrowserRegistry
110
+ layerBrowserRegistry : IJGISLayerBrowserRegistry ,
111
+ formSchemaRegistry : IJGISFormSchemaRegistry
125
112
) {
126
113
return async ( ) => {
127
114
const current = tracker . currentWidget ;
@@ -130,83 +117,10 @@ namespace Private {
130
117
return ;
131
118
}
132
119
133
- const dialog = new Dialog ( {
134
- body : new LayerBrowserWidget (
135
- current . context . model ,
136
- layerBrowserRegistry . getRegistryLayers ( )
137
- ) ,
138
- buttons : [ Dialog . cancelButton ( ) , Dialog . okButton ( ) ]
139
- } ) ;
140
- await dialog . launch ( ) ;
141
- } ;
142
- }
143
-
144
- // TODO Allow for creating only a source (e.g. loading a CSV file)
145
- // TODO Allow for creating only a layer (e.g. creating a vector layer given a source selected from a dropdown)
146
- export function createRasterSourceAndLayer (
147
- tracker : WidgetTracker < JupyterGISWidget >
148
- ) {
149
- return async ( args : any ) => {
150
- const current = tracker . currentWidget ;
151
-
152
- if ( ! current ) {
153
- return ;
154
- }
155
-
156
- const form = {
157
- title : 'Raster Layer parameters' ,
158
- default : ( model : IJupyterGISModel ) => {
159
- return {
160
- name : 'RasterSource' ,
161
- url : 'https://tile.openstreetmap.org/{z}/{x}/{y}.png' ,
162
- maxZoom : 24 ,
163
- minZoom : 0
164
- } ;
165
- }
166
- } ;
167
-
168
- current . context . model . syncFormData ( form ) ;
169
-
170
- const dialog = new FormDialog ( {
171
- context : current . context ,
172
- title : form . title ,
173
- sourceData : form . default ( current . context . model ) ,
174
- schema : FORM_SCHEMA [ 'RasterSource' ] ,
175
- syncData : ( props : IDict ) => {
176
- const sharedModel = current . context . model . sharedModel ;
177
- if ( ! sharedModel ) {
178
- return ;
179
- }
180
-
181
- const { name, ...parameters } = props ;
182
-
183
- const sourceId = UUID . uuid4 ( ) ;
184
-
185
- const sourceModel : IJGISSource = {
186
- type : 'RasterSource' ,
187
- name,
188
- parameters : {
189
- url : parameters . url ,
190
- minZoom : parameters . minZoom ,
191
- maxZoom : parameters . maxZoom
192
- }
193
- } ;
194
-
195
- const layerModel : IJGISLayer = {
196
- type : 'RasterLayer' ,
197
- parameters : {
198
- source : sourceId
199
- } ,
200
- visible : true ,
201
- name : name + ' Layer'
202
- } ;
203
-
204
- sharedModel . addSource ( sourceId , sourceModel ) ;
205
- current . context . model . addLayer ( UUID . uuid4 ( ) , layerModel ) ;
206
- } ,
207
- cancelButton : ( ) => {
208
- current . context . model . syncFormData ( undefined ) ;
209
- }
120
+ const dialog = new LayerBrowserWidget ( {
121
+ model : current . context . model ,
122
+ registry : layerBrowserRegistry . getRegistryLayers ( ) ,
123
+ formSchemaRegistry
210
124
} ) ;
211
125
await dialog . launch ( ) ;
212
126
} ;
0 commit comments