@@ -104,7 +104,6 @@ export function createLayer(layerConfig, map) {
104
104
} ) ,
105
105
} ) ;
106
106
case 'geojson' :
107
- console . log ( JSON . stringify ( layerConfig . source ?. data || { } ) )
108
107
return new VectorLayer ( {
109
108
name : layerConfig . label ,
110
109
title : layerConfig . title || layerConfig . name ,
@@ -119,11 +118,15 @@ export function createLayer(layerConfig, map) {
119
118
splitscreen : layerConfig . splitscreen ,
120
119
displayInLayerSwitcher : layerConfig . userVisible ,
121
120
source : new VectorSource ( {
122
- features : new GeoJSON ( ) . readFeatures ( JSON . stringify ( layerConfig . source ?. data || { } ) , {
121
+ features : new GeoJSON ( ) . readFeatures (
122
+ ( typeof layerConfig . source . data == "string" ) ?
123
+ layerConfig . source . data :
124
+ JSON . stringify ( layerConfig . source . data || { } ) , {
123
125
// Ensure the features are read with the correct projection
124
126
dataProjection : layerConfig . source . projection || 'EPSG:4326' , // Assuming the GeoJSON is in WGS 84
125
127
featureProjection : map . getView ( ) . getProjection ( ) || 'EPSG:3857' // Assuming the map projection
126
- } ) ,
128
+ } )
129
+
127
130
} ) ,
128
131
// Add this line to apply a generic style to the layer
129
132
style : geoJsonStyleFunction
@@ -255,9 +258,15 @@ export function findLayer(map, name) {
255
258
}
256
259
257
260
export function setFeatures ( map , data , name , clear ) {
261
+
258
262
const layer = findLayer ( map , name ) ;
259
263
if ( layer ) {
260
264
const source = layer . getSource ( )
265
+ const reader = ( source . getFormat ? source . getFormat ( ) : null ) || new GeoJSON ( {
266
+ dataProjection : source . get ( 'projection' ) || 'EPSG:4326' , // Assuming the GeoJSON is in WGS 84,
267
+ featureProjection : map . getView ( ) . getProjection ( ) || 'EPSG:3857' // Assuming the map projection
268
+ } )
269
+
261
270
//Check if there is a undo stack connected to this source, if so clear and disable
262
271
var undos = [ ]
263
272
//Disable all undo stacks
@@ -273,7 +282,6 @@ export function setFeatures(map, data, name, clear) {
273
282
source . clear ( )
274
283
undos . forEach ( ( c ) => { c . clear ( ) } )
275
284
}
276
- const reader = ( source . getFormat ? source . getFormat ( ) : null ) || new GeoJSON ( )
277
285
if ( reader && data ) {
278
286
//Now add the features based on types
279
287
if ( Array . isArray ( data ) ) {
0 commit comments