11import Map from "ol/Map" ;
2- import { MapContext , MapContextLayer , MapContextLayerXyz , MapContextView } from "@geospatial-sdk/core" ;
2+ import {
3+ MapContext ,
4+ MapContextLayer ,
5+ MapContextView ,
6+ } from "@geospatial-sdk/core" ;
37import { toLonLat , get as getProjection } from "ol/proj" ;
48import Layer from "ol/layer/Layer" ;
59import TileLayer from "ol/layer/Tile" ;
@@ -22,20 +26,20 @@ const GEOJSON = new GeoJSON();
2226 */
2327function extractLayerModel ( layer : Layer ) : MapContextLayer | null {
2428 const source = layer . getSource ( ) ;
25-
29+
2630 if ( ! source ) {
2731 return null ;
2832 }
2933
3034 // Common properties
3135 const attributionsFn = source . getAttributions ( ) ;
3236 let attributionsString : string | undefined = undefined ;
33-
37+
3438 if ( attributionsFn ) {
3539 // @ts -expect-error- OpenLayers AttributionLike can be called without arguments
3640 const attributionsResult = attributionsFn ( ) ;
3741 if ( attributionsResult ) {
38- attributionsString = Array . isArray ( attributionsResult )
42+ attributionsString = Array . isArray ( attributionsResult )
3943 ? attributionsResult . join ( ", " )
4044 : attributionsResult ;
4145 }
@@ -143,29 +147,28 @@ function extractLayerModel(layer: Layer): MapContextLayer | null {
143147 }
144148
145149 // Vector layers (GeoJSON, WFS)
146- if ( layer instanceof VectorLayer && source instanceof VectorSource ) {
150+ if ( layer instanceof VectorLayer && source instanceof VectorSource ) {
147151 const getStyle = layer . getStyle ( ) ;
148152 let style : string | undefined = undefined ;
149153 if ( getStyle && typeof getStyle === "string" ) {
150154 style = getStyle ;
151- }
152- else {
153- style = undefined ;
155+ } else {
156+ style = undefined ;
154157 }
155158
156159 const url = source . getUrl ( ) ;
157-
160+
158161 // WFS layers have a function URL, not a string
159162 if ( url && typeof url === "function" ) {
160163 // Call the function with dummy parameters to get the actual URL
161164 const dummyExtent : [ number , number , number , number ] = [ 0 , 0 , 1 , 1 ] ;
162165 const dummyResolution = 1 ;
163166 const dummyProjection = getProjection ( "EPSG:3857" ) ! ;
164167 const urlString = url ( dummyExtent , dummyResolution , dummyProjection ) ;
165-
168+
166169 // Extract the base URL (before the ?)
167170 const baseUrl = urlString . split ( "?" ) [ 0 ] ;
168-
171+
169172 return {
170173 type : "wfs" ,
171174 url : baseUrl ,
@@ -174,7 +177,7 @@ function extractLayerModel(layer: Layer): MapContextLayer | null {
174177 ...baseProperties ,
175178 } ;
176179 }
177-
180+
178181 if ( url && typeof url === "string" ) {
179182 // Check if it's a WFS layer by looking at the URL
180183 if ( url . includes ( "wfs" ) || url . includes ( "WFS" ) ) {
@@ -207,8 +210,7 @@ function extractLayerModel(layer: Layer): MapContextLayer | null {
207210 data : featureCollection ,
208211 ...baseProperties ,
209212 } ;
210- }
211- else {
213+ } else {
212214 return null ;
213215 }
214216 }
@@ -234,7 +236,7 @@ function extractViewModel(map: Map): MapContextView | null {
234236 }
235237
236238 const centerLonLat = toLonLat ( center , view . getProjection ( ) ) ;
237-
239+
238240 return {
239241 center : centerLonLat as [ number , number ] ,
240242 zoom,
@@ -247,11 +249,11 @@ function extractViewModel(map: Map): MapContextView | null {
247249 */
248250export function createContextFromMap ( map : Map ) : MapContext {
249251 const layers : MapContextLayer [ ] = [ ] ;
250-
252+
251253 map . getLayers ( ) . forEach ( ( layer ) => {
252254 const layerModel = extractLayerModel ( layer as Layer ) ;
253255 if ( layerModel ) {
254- layers . push ( layerModel ) ;
256+ layers . push ( layerModel ) ;
255257 }
256258 } ) ;
257259
0 commit comments