Skip to content

Commit cc32a54

Browse files
committed
fix: default feature object
1 parent bb338ba commit cc32a54

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/vendors/helpers/Layers.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,17 @@ export function createLayer(layerConfig, map) {
127127
splitscreen: layerConfig.splitscreen,
128128
displayInLayerSwitcher: layerConfig.userVisible,
129129
source: new VectorSource({
130-
features: layerConfig.source.data ? new GeoJSON().readFeatures(
131-
(typeof layerConfig.source.data == "string") ?
130+
features: new GeoJSON().readFeatures(
131+
(layerConfig.source.data && typeof layerConfig.source.data == "string") ?
132132
layerConfig.source.data :
133-
JSON.stringify(layerConfig.source.data || {}), {
133+
JSON.stringify(layerConfig.source.data || {
134+
"type": "FeatureCollection",
135+
"features": []
136+
}), {
134137
// Ensure the features are read with the correct projection
135138
dataProjection: layerConfig.source.projection || 'EPSG:4326', // Assuming the GeoJSON is in WGS 84
136139
featureProjection: map.getView().getProjection() || 'EPSG:3857' // Assuming the map projection
137-
}) : []
140+
})
138141
}),
139142
// Add this line to apply a generic style to the layer
140143
style: geoJsonStyleFunction

0 commit comments

Comments
 (0)