@@ -14,6 +14,7 @@ import * as React from 'react';
14
14
15
15
import { deepCopy } from '@/src/tools' ;
16
16
import { getLayerTypeForm , getSourceTypeForm } from './formselectors' ;
17
+ import { loadFile } from '@/src/tools' ;
17
18
18
19
export interface ICreationFormProps {
19
20
/**
@@ -80,9 +81,15 @@ export class CreationForm extends React.Component<ICreationFormProps, any> {
80
81
super ( props ) ;
81
82
82
83
this . filePath = props . model . filePath ;
84
+ console . log ( 'filePath:' , this . filePath ) ;
83
85
this . jGISModel = props . model ;
84
86
}
85
87
88
+ async loadData ( path : string ) {
89
+ const data = await loadFile ( { filepath : path , type : this . props . sourceType , model : this . jGISModel } ) ;
90
+ return data
91
+ }
92
+
86
93
render ( ) {
87
94
const sourceId = UUID . uuid4 ( ) ;
88
95
let layerSchema : IDict | undefined = undefined ;
@@ -186,56 +193,152 @@ export class CreationForm extends React.Component<ICreationFormProps, any> {
186
193
visible : true ,
187
194
name : actualName ,
188
195
} ;
189
-
190
- this . jGISModel . addLayer ( UUID . uuid4 ( ) , layerModel ) ;
196
+ console . log ( 'layerModel:' , layerModel ) ;
197
+
198
+
199
+ if ( this . props . layerType === 'VectorLayer' && this . props . sourceType === 'GeoJSONSource' ) {
200
+ const data = await this . loadData ( this . props ?. sourceData ?. path )
201
+ const features = data . features ;
202
+
203
+ let points : any = [ ] ;
204
+ let lineStrings : any = [ ] ;
205
+ let polygons : any = [ ] ;
206
+
207
+ features . forEach ( ( feature : any ) => {
208
+ if ( feature . geometry . type === 'Point' ) {
209
+ points . push ( feature ) ;
210
+ } else if ( feature . geometry . type === 'LineString' ) {
211
+ lineStrings . push ( feature ) ;
212
+ } else if ( feature . geometry . type === 'Polygon' ) {
213
+ polygons . push ( feature ) ;
214
+ }
215
+ } )
216
+ const pointsData = {
217
+ type : 'FeatureCollection' ,
218
+ features : points ,
219
+ } ;
220
+
221
+ const lineStringsData = {
222
+ type : 'FeatureCollection' ,
223
+ features : lineStrings ,
224
+ } ;
225
+
226
+ const polygonData = {
227
+ type : 'FeatureCollection' ,
228
+ features : polygons ,
229
+ } ;
230
+
231
+
232
+ const pointSource : IJGISSource = {
233
+ name : "Point Source" ,
234
+ type : "GeoJSONSource" ,
235
+ parameters : {
236
+ data : pointsData ,
237
+ } ,
238
+ } ;
239
+
240
+ const lineStringSource : IJGISSource = {
241
+ name : "LineString Source" ,
242
+ type : "GeoJSONSource" ,
243
+ parameters : {
244
+ data : lineStringsData ,
245
+ } ,
246
+ } ;
247
+
248
+ const polygonSource : IJGISSource = {
249
+ name : "" ,
250
+ type : "GeoJSONSource" ,
251
+ parameters : {
252
+ data : polygonData ,
253
+ } ,
254
+ } ;
255
+
256
+ const pointLayer : IJGISLayer = {
257
+ type : 'VectorLayer' ,
258
+ visible : true ,
259
+ name : 'Point Vector Layer' ,
260
+ parameters : {
261
+ type : 'point' ,
262
+ source : pointSource ,
263
+ } ,
264
+ } ;
265
+
266
+ const lineStringLayer : IJGISLayer = {
267
+ type : 'VectorLayer' ,
268
+ visible : true ,
269
+ name : 'LineString Vector Layer' ,
270
+ parameters : {
271
+ type : 'lineString' ,
272
+ source : lineStringSource ,
273
+ } ,
274
+ } ;
275
+
276
+ const polygonLayer : IJGISLayer = {
277
+ type : 'VectorLayer' ,
278
+ visible : true ,
279
+ name : 'Polygon Vector Layer' ,
280
+ parameters : {
281
+ type : 'polygon' ,
282
+ source : polygonSource ,
283
+ } ,
284
+ } ;
285
+ //this.jGISModel.addLayer(UUID.uuid4(), layerModel);
286
+ this . jGISModel . addLayer ( UUID . uuid4 ( ) , pointLayer ) ;
287
+ this . jGISModel . addLayer ( UUID . uuid4 ( ) , lineStringLayer ) ;
288
+ this . jGISModel . addLayer ( UUID . uuid4 ( ) , polygonLayer ) ;
289
+ }
191
290
}
192
291
} ) ;
193
292
194
293
return (
195
294
< div >
196
- { this . props . createSource && (
197
- < div >
198
- < h3 > Source Properties</ h3 >
199
- < SourceForm
200
- formContext = "create"
201
- model = { this . jGISModel }
202
- filePath = { this . filePath }
203
- schema = { sourceSchema }
204
- sourceData = { this . props . sourceData }
205
- syncData = { ( properties : { [ key : string ] : any } ) => {
206
- sourceCreationPromise ?. resolve ( properties ) ;
207
- } }
208
- ok = { this . props . ok }
209
- cancel = { this . props . cancel }
210
- formChangedSignal = { this . sourceFormChangedSignal }
211
- formErrorSignal = { this . props . formErrorSignal }
212
- dialogOptions = { this . props . dialogOptions }
213
- sourceType = { this . props . sourceType }
214
- />
215
- </ div >
216
- ) }
217
- { this . props . createLayer && (
218
- < div >
219
- < h3 > Layer Properties</ h3 >
220
- < LayerForm
221
- formContext = "create"
222
- sourceType = { this . props . sourceType }
223
- model = { this . jGISModel }
224
- filePath = { this . filePath }
225
- schema = { layerSchema }
226
- sourceData = { layerData }
227
- syncData = { ( properties : { [ key : string ] : any } ) => {
228
- layerCreationPromise ?. resolve ( properties ) ;
229
- } }
230
- ok = { this . props . ok }
231
- cancel = { this . props . cancel }
232
- sourceFormChangedSignal = { this . sourceFormChangedSignal }
233
- formErrorSignal = { this . props . formErrorSignal }
234
- dialogOptions = { this . props . dialogOptions }
235
- />
236
- </ div >
237
- ) }
238
- </ div >
295
+ {
296
+ this . props . createSource && (
297
+ < div >
298
+ < h3 > Source Properties</ h3 >
299
+ < SourceForm
300
+ formContext = "create"
301
+ model = { this . jGISModel }
302
+ filePath = { this . filePath }
303
+ schema = { sourceSchema }
304
+ sourceData = { this . props . sourceData }
305
+ syncData = { ( properties : { [ key : string ] : any } ) => {
306
+ sourceCreationPromise ?. resolve ( properties ) ;
307
+ } }
308
+ ok = { this . props . ok }
309
+ cancel = { this . props . cancel }
310
+ formChangedSignal = { this . sourceFormChangedSignal }
311
+ formErrorSignal = { this . props . formErrorSignal }
312
+ dialogOptions = { this . props . dialogOptions }
313
+ sourceType = { this . props . sourceType }
314
+ />
315
+ </ div >
316
+ )
317
+ }
318
+ {
319
+ this . props . createLayer && (
320
+ < div >
321
+ < h3 > Layer Properties</ h3 >
322
+ < LayerForm
323
+ formContext = "create"
324
+ sourceType = { this . props . sourceType }
325
+ model = { this . jGISModel }
326
+ filePath = { this . filePath }
327
+ schema = { layerSchema }
328
+ sourceData = { layerData }
329
+ syncData = { ( properties : { [ key : string ] : any } ) => {
330
+ layerCreationPromise ?. resolve ( properties ) ;
331
+ } }
332
+ ok = { this . props . ok }
333
+ cancel = { this . props . cancel }
334
+ sourceFormChangedSignal = { this . sourceFormChangedSignal }
335
+ formErrorSignal = { this . props . formErrorSignal }
336
+ dialogOptions = { this . props . dialogOptions }
337
+ />
338
+ </ div >
339
+ )
340
+ }
341
+ </ div >
239
342
) ;
240
343
}
241
344
0 commit comments