@@ -104,6 +104,7 @@ export function createLayer(layerConfig, map) {
104
104
} ) ,
105
105
} ) ;
106
106
case 'geojson' :
107
+ console . log ( JSON . stringify ( layerConfig . source ?. data || { } ) )
107
108
return new VectorLayer ( {
108
109
name : layerConfig . label ,
109
110
title : layerConfig . title || layerConfig . name ,
@@ -118,7 +119,7 @@ export function createLayer(layerConfig, map) {
118
119
splitscreen : layerConfig . splitscreen ,
119
120
displayInLayerSwitcher : layerConfig . userVisible ,
120
121
source : new VectorSource ( {
121
- features : new GeoJSON ( ) . readFeatures ( JSON . stringify ( layerConfig . source . data , null ) , {
122
+ features : new GeoJSON ( ) . readFeatures ( JSON . stringify ( layerConfig . source ? .data || { } ) , {
122
123
// Ensure the features are read with the correct projection
123
124
dataProjection : layerConfig . source . projection || 'EPSG:4326' , // Assuming the GeoJSON is in WGS 84
124
125
featureProjection : map . getView ( ) . getProjection ( ) || 'EPSG:3857' // Assuming the map projection
@@ -254,51 +255,49 @@ export function findLayer(map, name) {
254
255
}
255
256
256
257
export function setFeatures ( map , data , name , clear ) {
257
- return new Promise ( ( resolve , reject ) => {
258
- const layer = findLayer ( map , name ) ;
259
- if ( layer ) {
260
- const source = layer . getSource ( )
261
- //Check if there is a undo stack connected to this source, if so clear and disable
262
- var undos = [ ]
263
- //Disable all undo stacks
264
- map . getControls ( ) . forEach ( ( c ) => {
265
- if ( c instanceof UndoRedo && c . getActive ( ) ) {
266
- undos . push ( c )
267
- c . setActive ( false )
268
- }
269
- } )
270
-
271
- //Check if we should clear te source
272
- if ( clear ) {
273
- source . clear ( )
274
- undos . forEach ( ( c ) => { c . clear ( ) } )
258
+ const layer = findLayer ( map , name ) ;
259
+ if ( layer ) {
260
+ const source = layer . getSource ( )
261
+ //Check if there is a undo stack connected to this source, if so clear and disable
262
+ var undos = [ ]
263
+ //Disable all undo stacks
264
+ map . getControls ( ) . forEach ( ( c ) => {
265
+ if ( c instanceof UndoRedo && c . getActive ( ) ) {
266
+ undos . push ( c )
267
+ c . setActive ( false )
275
268
}
276
- const reader = ( source . getFormat ? source . getFormat ( ) : null ) || new GeoJSON ( )
277
- if ( reader && data ) {
278
- //Now add the features based on types
279
- if ( Array . isArray ( data ) ) {
280
- data . forEach ( ( rec ) => {
281
- if ( source . setFeatures ) {
282
- source . setFeatures ( reader . readFeatures ( rec ) )
283
- } else {
284
- source . addFeatures ( reader . readFeatures ( rec ) )
285
- }
286
- } )
287
- } else {
269
+ } )
270
+
271
+ //Check if we should clear te source
272
+ if ( clear ) {
273
+ source . clear ( )
274
+ undos . forEach ( ( c ) => { c . clear ( ) } )
275
+ }
276
+ const reader = ( source . getFormat ? source . getFormat ( ) : null ) || new GeoJSON ( )
277
+ if ( reader && data ) {
278
+ //Now add the features based on types
279
+ if ( Array . isArray ( data ) ) {
280
+ data . forEach ( ( rec ) => {
288
281
if ( source . setFeatures ) {
289
- source . setFeatures ( reader . readFeatures ( data ) )
282
+ source . setFeatures ( reader . readFeatures ( rec ) )
290
283
} else {
291
- source . addFeatures ( reader . readFeatures ( data ) )
284
+ source . addFeatures ( reader . readFeatures ( rec ) )
292
285
}
286
+ } )
287
+ } else {
288
+ if ( source . setFeatures ) {
289
+ source . setFeatures ( reader . readFeatures ( data ) )
290
+ } else {
291
+ source . addFeatures ( reader . readFeatures ( data ) )
293
292
}
294
293
}
295
- //Enable the undo stack
296
- undos . forEach ( ( c ) => { c . setActive ( true ) } )
297
- //Enable the connected undo check
298
- return resolve ( ) //Exit, work is done
299
294
}
300
- return reject ( )
301
- } )
295
+ //Enable the undo stack
296
+ undos . forEach ( ( c ) => { c . setActive ( true ) } )
297
+ //Enable the connected undo check
298
+ return true //Exit, work is done
299
+ }
300
+ return false
302
301
}
303
302
304
303
//Read feature of map
@@ -309,15 +308,15 @@ export function getFeatures(map, name) {
309
308
//Check if there is a undo stack connected to this source, if so clear and disable
310
309
return new GeoJSON ( ) . writeFeaturesObject ( source . getFeatures ( ) )
311
310
}
312
- return Promise . reject ( )
311
+ return false
313
312
}
314
313
315
314
//Clear feature of map
316
315
export function clearFeatures ( map , name ) {
317
316
const layer = findLayer ( map , name ) ;
318
317
if ( layer ) {
319
318
layer . getSource ( ) . clear ( )
320
- return Promise . resolve ( )
319
+ return true
321
320
}
322
- return Promise . reject ( )
321
+ return false
323
322
}
0 commit comments