@geospatial-sdk/openlayers 0.0.5-dev.56 → 0.0.5-dev.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"create-map.d.ts","sourceRoot":"","sources":["../../lib/map/create-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,eAAe,EACf,cAAc,EAEf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,IAAI,MAAM,YAAY,CAAC;AAC9B,OAAO,KAAK,MAAM,mBAAmB,CAAC;AAwDtC,wBAAsB,WAAW,CAAC,UAAU,EAAE,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,CAoQ7E;AAED,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,eAAe,EAC3B,aAAa,EAAE,MAAM,EACrB,kBAAkB,EAAE,eAAe,GAClC,OAAO,CAAC,IAAI,CAAC,CAgBf;AAED,wBAAgB,UAAU,CAAC,SAAS,EAAE,cAAc,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAkC3E;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,UAAU,EACnB,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,GAC5B,OAAO,CAAC,GAAG,CAAC,CAKd;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,GAAG,CAAC,CAUd"}
1
+ {"version":3,"file":"create-map.d.ts","sourceRoot":"","sources":["../../lib/map/create-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,eAAe,EACf,cAAc,EAEf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,IAAI,MAAM,YAAY,CAAC;AAC9B,OAAO,KAAK,MAAM,mBAAmB,CAAC;AA0DtC,wBAAsB,WAAW,CAAC,UAAU,EAAE,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,CAgR7E;AAED,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,eAAe,EAC3B,aAAa,EAAE,MAAM,EACrB,kBAAkB,EAAE,eAAe,GAClC,OAAO,CAAC,IAAI,CAAC,CAgBf;AAED,wBAAgB,UAAU,CAAC,SAAS,EAAE,cAAc,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAkC3E;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,UAAU,EACnB,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,GAC5B,OAAO,CAAC,GAAG,CAAC,CAKd;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,GAAG,CAAC,CAUd"}
@@ -26,6 +26,8 @@ import { canDoIncrementalUpdate, updateLayerProperties, } from "./layer-update.j
26
26
  import { initHoverLayer } from "./feature-hover.js";
27
27
  import { emitLayerCreationError, emitLayerLoadingError, emitLayerLoadingStatusSuccess, propagateLayerStateChangeEventToMap, } from "./register-events.js";
28
28
  import { GEOSPATIAL_SDK_PREFIX } from "./constants.js";
29
+ import ImageLayer from "ol/layer/Image.js";
30
+ import ImageWMS from "ol/source/ImageWMS.js";
29
31
  // Register proj4 with OpenLayers so that arbitrary EPSG codes
30
32
  // (e.g., UTM zones from GeoTIFF metadata) can be reprojected to the map projection
31
33
  register(proj4);
@@ -66,20 +68,33 @@ export async function createLayer(layerModel) {
66
68
  break;
67
69
  case "wms":
68
70
  {
69
- layer = new TileLayer({});
70
- const source = new TileWMS({
71
- url: removeSearchParams(layerModel.url, ["request", "service"]),
72
- params: {
73
- LAYERS: layerModel.name,
74
- ...(layerModel.style && { STYLES: layerModel.style }),
75
- },
76
- gutter: 20,
77
- attributions: layerModel.attributions,
78
- });
79
- source.setTileLoadFunction(function (tile, src) {
80
- return tileLoadErrorCatchFunction(layer, tile, src);
81
- });
82
- layer.setSource(source);
71
+ const url = removeSearchParams(layerModel.url, ["request", "service"]);
72
+ const params = {
73
+ LAYERS: layerModel.name,
74
+ ...(layerModel.style && { STYLES: layerModel.style }),
75
+ };
76
+ if (layerModel.useTiles === false) {
77
+ layer = new ImageLayer({
78
+ source: new ImageWMS({
79
+ url,
80
+ params,
81
+ attributions: layerModel.attributions,
82
+ }),
83
+ });
84
+ }
85
+ else {
86
+ layer = new TileLayer({
87
+ source: new TileWMS({
88
+ url,
89
+ params: { ...params, TILED: true },
90
+ gutter: 20,
91
+ attributions: layerModel.attributions,
92
+ tileLoadFunction: function (tile, src) {
93
+ return tileLoadErrorCatchFunction(layer, tile, src);
94
+ },
95
+ }),
96
+ });
97
+ }
83
98
  defer().then(() => emitLayerLoadingStatusSuccess(layer));
84
99
  }
85
100
  break;
@@ -46,6 +46,8 @@ import {
46
46
  } from "./create-map.js";
47
47
  import { tileLoadErrorCatchFunction } from "./handle-errors.js";
48
48
  import { GEOSPATIAL_SDK_PREFIX } from "./constants.js";
49
+ import ImageLayer from "ol/layer/Image.js";
50
+ import ImageWMS from "ol/source/ImageWMS.js";
49
51
 
50
52
  vi.mock("./handle-errors", async (importOriginal) => {
51
53
  const actual =
@@ -185,8 +187,11 @@ describe("MapContextService", () => {
185
187
  it("set correct WMS params", () => {
186
188
  const source = layer.getSource() as TileWMS;
187
189
  const params = source.getParams();
188
- expect(params.LAYERS).toBe((layerModel as MapContextLayerWms).name);
189
- expect(params.STYLES).toBe((layerModel as MapContextLayerWms).style);
190
+ expect(params).toEqual({
191
+ LAYERS: (layerModel as MapContextLayerWms).name,
192
+ STYLES: (layerModel as MapContextLayerWms).style,
193
+ TILED: true,
194
+ });
190
195
  });
191
196
  it("set correct url without existing REQUEST and SERVICE params", () => {
192
197
  const source = layer.getSource() as TileWMS;
@@ -225,6 +230,50 @@ describe("MapContextService", () => {
225
230
  type: `${GEOSPATIAL_SDK_PREFIX}layer-loading-status`,
226
231
  });
227
232
  });
233
+
234
+ describe("not using tiles", () => {
235
+ beforeEach(async () => {
236
+ layerModel = { ...MAP_CTX_LAYER_WMS_FIXTURE, useTiles: false };
237
+ layer = await createLayer(layerModel);
238
+ layer.on(
239
+ `${GEOSPATIAL_SDK_PREFIX}layer-loading-status`,
240
+ eventCallback,
241
+ );
242
+ layer.on(`${GEOSPATIAL_SDK_PREFIX}layer-data-info`, eventCallback);
243
+ });
244
+ it("create an image layer", () => {
245
+ expect(layer).toBeTruthy();
246
+ expect(layer).toBeInstanceOf(ImageLayer);
247
+ });
248
+ it("set correct layer properties", () => {
249
+ expect(layer.getVisible()).toBe(false);
250
+ expect(layer.getOpacity()).toBe(0.5);
251
+ expect(layer.get("label")).toBe("Communes");
252
+ // @ts-expect-error TS2554 we're not providing a view extent here
253
+ expect(layer.getSource()?.getAttributions()!()).toEqual([
254
+ "camptocamp",
255
+ ]);
256
+ });
257
+ it("create an ImageWMS source", () => {
258
+ const source = layer.getSource();
259
+ expect(source).toBeInstanceOf(ImageWMS);
260
+ });
261
+ it("set correct WMS params", () => {
262
+ const source = layer.getSource() as ImageWMS;
263
+ const params = source.getParams();
264
+ expect(params).toEqual({
265
+ LAYERS: (layerModel as MapContextLayerWms).name,
266
+ STYLES: (layerModel as MapContextLayerWms).style,
267
+ });
268
+ });
269
+ it("set correct url without existing REQUEST and SERVICE params", () => {
270
+ const source = layer.getSource() as ImageWMS;
271
+ const url = source.getUrl();
272
+ expect(url).toBe(
273
+ "https://www.datagrandest.fr/geoserver/region-grand-est/ows",
274
+ );
275
+ });
276
+ });
228
277
  });
229
278
 
230
279
  describe("WFS", () => {
@@ -50,6 +50,8 @@ import {
50
50
  propagateLayerStateChangeEventToMap,
51
51
  } from "./register-events.js";
52
52
  import { GEOSPATIAL_SDK_PREFIX } from "./constants.js";
53
+ import ImageLayer from "ol/layer/Image.js";
54
+ import ImageWMS from "ol/source/ImageWMS.js";
53
55
 
54
56
  // Register proj4 with OpenLayers so that arbitrary EPSG codes
55
57
  // (e.g., UTM zones from GeoTIFF metadata) can be reprojected to the map projection
@@ -99,24 +101,36 @@ export async function createLayer(layerModel: MapContextLayer): Promise<Layer> {
99
101
 
100
102
  case "wms":
101
103
  {
102
- layer = new TileLayer({});
103
- const source = new TileWMS({
104
- url: removeSearchParams(layerModel.url, ["request", "service"]),
105
- params: {
106
- LAYERS: layerModel.name,
107
- ...(layerModel.style && { STYLES: layerModel.style }),
108
- },
109
- gutter: 20,
110
- attributions: layerModel.attributions,
111
- });
112
- source.setTileLoadFunction(function (tile: Tile, src: string) {
113
- return tileLoadErrorCatchFunction(
114
- layer as TileLayer<TileWMS>,
115
- tile,
116
- src,
117
- );
118
- });
119
- layer.setSource(source);
104
+ const url = removeSearchParams(layerModel.url, ["request", "service"]);
105
+ const params = {
106
+ LAYERS: layerModel.name,
107
+ ...(layerModel.style && { STYLES: layerModel.style }),
108
+ };
109
+ if (layerModel.useTiles === false) {
110
+ layer = new ImageLayer({
111
+ source: new ImageWMS({
112
+ url,
113
+ params,
114
+ attributions: layerModel.attributions,
115
+ }),
116
+ });
117
+ } else {
118
+ layer = new TileLayer({
119
+ source: new TileWMS({
120
+ url,
121
+ params: { ...params, TILED: true },
122
+ gutter: 20,
123
+ attributions: layerModel.attributions,
124
+ tileLoadFunction: function (tile: Tile, src: string) {
125
+ return tileLoadErrorCatchFunction(
126
+ layer as TileLayer<TileWMS>,
127
+ tile,
128
+ src,
129
+ );
130
+ },
131
+ }),
132
+ });
133
+ }
120
134
  defer().then(() => emitLayerLoadingStatusSuccess(layer));
121
135
  }
122
136
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geospatial-sdk/openlayers",
3
- "version": "0.0.5-dev.56+eae591c",
3
+ "version": "0.0.5-dev.57+457e2f3",
4
4
  "description": "OpenLayers-related utilities",
5
5
  "keywords": [
6
6
  "ol",
@@ -37,9 +37,9 @@
37
37
  "ol": ">9.x"
38
38
  },
39
39
  "dependencies": {
40
- "@geospatial-sdk/core": "^0.0.5-dev.56+eae591c",
40
+ "@geospatial-sdk/core": "^0.0.5-dev.57+457e2f3",
41
41
  "lodash.throttle": "^4.1.1",
42
42
  "ol-mapbox-style": "12.4.0"
43
43
  },
44
- "gitHead": "eae591cfcca0346c3cac6fe7d5dcddf88fe408f4"
44
+ "gitHead": "457e2f3e1cf7b542bee94549314405cd4a2b983e"
45
45
  }