Skip to content

Commit 76f7c94

Browse files
committed
formatting
1 parent 6f65e68 commit 76f7c94

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

packages/openlayers/lib/map/create-context.test.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ describe("createContextFromMap", () => {
145145
});
146146

147147
it("extracts the style", () => {
148-
expect((extractedLayerModel as MapContextLayerWms).style).toBe("default");
148+
expect((extractedLayerModel as MapContextLayerWms).style).toBe(
149+
"default",
150+
);
149151
});
150152

151153
it("extracts layer properties", () => {
@@ -169,12 +171,15 @@ describe("createContextFromMap", () => {
169171
const map = new Map({});
170172
map.addLayer(layer);
171173
// Wait for the promise chain to complete (mock resolves immediately but .then is async)
172-
await vi.waitFor(() => {
173-
const source = layer.getSource();
174-
if (!source) {
175-
throw new Error("Source not ready yet");
176-
}
177-
}, { timeout: 1000, interval: 10 });
174+
await vi.waitFor(
175+
() => {
176+
const source = layer.getSource();
177+
if (!source) {
178+
throw new Error("Source not ready yet");
179+
}
180+
},
181+
{ timeout: 1000, interval: 10 },
182+
);
178183
const context = createContextFromMap(map);
179184
extractedLayerModel = context.layers[0];
180185
});
@@ -258,7 +263,9 @@ describe("createContextFromMap", () => {
258263
});
259264

260265
it("does not have inline data", () => {
261-
expect((extractedLayerModel as MapContextLayerGeojson).data).toBeUndefined();
266+
expect(
267+
(extractedLayerModel as MapContextLayerGeojson).data,
268+
).toBeUndefined();
262269
});
263270

264271
it("extracts layer properties", () => {
@@ -293,7 +300,9 @@ describe("createContextFromMap", () => {
293300
});
294301

295302
it("extracts the layer name", () => {
296-
expect((extractedLayerModel as MapContextLayerWmts)?.name).toBeDefined();
303+
expect(
304+
(extractedLayerModel as MapContextLayerWmts)?.name,
305+
).toBeDefined();
297306
});
298307

299308
it("extracts layer properties", () => {
@@ -452,7 +461,9 @@ describe("createContextFromMap", () => {
452461
it("extracts the view", () => {
453462
expect(extractedContext.view).toBeTruthy();
454463
expect((extractedContext.view as any)?.center).toBeDefined();
455-
expect((extractedContext.view as any)?.zoom).toBe((originalContext.view as any)?.zoom);
464+
expect((extractedContext.view as any)?.zoom).toBe(
465+
(originalContext.view as any)?.zoom,
466+
);
456467
});
457468
});
458469

@@ -517,7 +528,9 @@ describe("createContextFromMap", () => {
517528
);
518529

519530
// Compare view zoom
520-
expect((extractedContext2.view as any)?.zoom).toBe((extractedContext.view as any)?.zoom);
531+
expect((extractedContext2.view as any)?.zoom).toBe(
532+
(extractedContext.view as any)?.zoom,
533+
);
521534

522535
// Compare view center with tolerance
523536
expect((extractedContext2.view as any)?.center[0]).toBeCloseTo(

packages/openlayers/lib/map/create-context.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import 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";
37
import { toLonLat, get as getProjection } from "ol/proj";
48
import Layer from "ol/layer/Layer";
59
import TileLayer from "ol/layer/Tile";
@@ -22,20 +26,20 @@ const GEOJSON = new GeoJSON();
2226
*/
2327
function 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
*/
248250
export 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

Comments
 (0)