@@ -17,7 +17,7 @@ import { geoJsonStyleFunction } from './Styles'
17
17
import { applyBackground , applyStyle } from 'ol-mapbox-style' ;
18
18
import { createXYZ } from 'ol/tilegrid.js' ;
19
19
20
- export function createLayer ( layerConfig ) {
20
+ export function createLayer ( layerConfig , map ) {
21
21
if ( ! layerConfig || ! layerConfig . type ) {
22
22
console . warn ( "Skipping layer due to missing type or configuration:" , layerConfig ) ;
23
23
return null ;
@@ -90,7 +90,7 @@ export function createLayer(layerConfig) {
90
90
features : new GeoJSON ( ) . readFeatures ( layerConfig . source . data , {
91
91
// Ensure the features are read with the correct projection
92
92
dataProjection : layerConfig . source . projection || 'EPSG:4326' , // Assuming the GeoJSON is in WGS 84
93
- featureProjection : 'EPSG:3857' // Assuming the map projection
93
+ featureProjection : map . getView ( ) . getProjection ( ) || 'EPSG:3857' // Assuming the map projection
94
94
} ) ,
95
95
} ) ,
96
96
// Add this line to apply a generic style to the layer
@@ -132,7 +132,7 @@ export function createLayer(layerConfig) {
132
132
opacity : layerConfig . opacity ,
133
133
selectable : layerConfig . selectable ,
134
134
source : new VectorTileSource ( {
135
- projection : layerConfig . source ?. projection ,
135
+ projection : layerConfig . source ?. projection || 'EPSG:3857' ,
136
136
} ) ,
137
137
style : layerConfig . source . style ,
138
138
} ) ;
0 commit comments