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