@geospatial-sdk/openlayers 0.0.5-dev.40 → 0.0.5-dev.42

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.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./map";
1
+ export * from "./map/index.js";
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AACA,cAAc,OAAO,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // PUBLIC API
2
- export * from "./map";
2
+ export * from "./map/index.js";
@@ -1,4 +1,4 @@
1
- import Map from "ol/Map";
1
+ import Map from "ol/Map.js";
2
2
  import { MapContextDiff } from "@geospatial-sdk/core";
3
3
  /**
4
4
  * Apply a context diff to an OpenLayers map
@@ -1 +1 @@
1
- {"version":3,"file":"apply-context-diff.d.ts","sourceRoot":"","sources":["../../lib/map/apply-context-diff.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,QAAQ,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAQtD;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,cAAc,GAC1B,OAAO,CAAC,GAAG,CAAC,CA2Fd"}
1
+ {"version":3,"file":"apply-context-diff.d.ts","sourceRoot":"","sources":["../../lib/map/apply-context-diff.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAQtD;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,cAAc,GAC1B,OAAO,CAAC,GAAG,CAAC,CA2Fd"}
@@ -1,100 +1,89 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { createLayer, createView } from "./create-map";
11
- import { fromLonLat, transformExtent } from "ol/proj";
12
- import GeoJSON from "ol/format/GeoJSON";
1
+ import { createLayer, createView } from "./create-map.js";
2
+ import { fromLonLat, transformExtent } from "ol/proj.js";
3
+ import GeoJSON from "ol/format/GeoJSON.js";
13
4
  const GEOJSON = new GeoJSON();
14
5
  /**
15
6
  * Apply a context diff to an OpenLayers map
16
7
  * @param map
17
8
  * @param contextDiff
18
9
  */
19
- export function applyContextDiffToMap(map, contextDiff) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const layers = map.getLayers();
22
- // removed layers (sorted by descending position)
23
- if (contextDiff.layersRemoved.length > 0) {
24
- const removed = contextDiff.layersRemoved.sort((a, b) => b.position - a.position);
25
- for (const layerRemoved of removed) {
26
- layers.item(layerRemoved.position).dispose();
27
- layers.removeAt(layerRemoved.position);
28
- }
10
+ export async function applyContextDiffToMap(map, contextDiff) {
11
+ const layers = map.getLayers();
12
+ // removed layers (sorted by descending position)
13
+ if (contextDiff.layersRemoved.length > 0) {
14
+ const removed = contextDiff.layersRemoved.sort((a, b) => b.position - a.position);
15
+ for (const layerRemoved of removed) {
16
+ layers.item(layerRemoved.position).dispose();
17
+ layers.removeAt(layerRemoved.position);
18
+ }
19
+ }
20
+ // insert added layers
21
+ const newLayers = await Promise.all(contextDiff.layersAdded.map((layerAdded) => createLayer(layerAdded.layer)));
22
+ newLayers.forEach((layer, index) => {
23
+ const position = contextDiff.layersAdded[index].position;
24
+ if (position >= layers.getLength()) {
25
+ layers.push(layer);
26
+ }
27
+ else {
28
+ layers.insertAt(position, layer);
29
+ }
30
+ });
31
+ // move reordered layers (sorted by ascending new position)
32
+ if (contextDiff.layersReordered.length > 0) {
33
+ const reordered = contextDiff.layersReordered.sort((a, b) => a.newPosition - b.newPosition);
34
+ const olLayers = reordered.map((layer) => layers.item(layer.previousPosition));
35
+ const layersArray = layers.getArray();
36
+ for (let i = 0; i < reordered.length; i++) {
37
+ layersArray[reordered[i].newPosition] = olLayers[i];
29
38
  }
30
- // insert added layers
31
- const newLayers = yield Promise.all(contextDiff.layersAdded.map((layerAdded) => createLayer(layerAdded.layer)));
32
- newLayers.forEach((layer, index) => {
33
- const position = contextDiff.layersAdded[index].position;
34
- if (position >= layers.getLength()) {
35
- layers.push(layer);
36
- }
37
- else {
38
- layers.insertAt(position, layer);
39
- }
39
+ map.setLayers([...layersArray]);
40
+ }
41
+ // recreate changed layers
42
+ for (const layerChanged of contextDiff.layersChanged) {
43
+ layers.item(layerChanged.position).dispose();
44
+ createLayer(layerChanged.layer).then((layer) => {
45
+ layers.setAt(layerChanged.position, layer);
40
46
  });
41
- // move reordered layers (sorted by ascending new position)
42
- if (contextDiff.layersReordered.length > 0) {
43
- const reordered = contextDiff.layersReordered.sort((a, b) => a.newPosition - b.newPosition);
44
- const olLayers = reordered.map((layer) => layers.item(layer.previousPosition));
45
- const layersArray = layers.getArray();
46
- for (let i = 0; i < reordered.length; i++) {
47
- layersArray[reordered[i].newPosition] = olLayers[i];
48
- }
49
- map.setLayers([...layersArray]);
47
+ }
48
+ if (typeof contextDiff.viewChanges !== "undefined") {
49
+ const { viewChanges } = contextDiff;
50
+ const view = map.getView();
51
+ const projection = view.getProjection();
52
+ if (viewChanges === null) {
53
+ map.setView(createView(viewChanges, map));
54
+ return map;
50
55
  }
51
- // recreate changed layers
52
- for (const layerChanged of contextDiff.layersChanged) {
53
- layers.item(layerChanged.position).dispose();
54
- createLayer(layerChanged.layer).then((layer) => {
55
- layers.setAt(layerChanged.position, layer);
56
+ if (viewChanges.maxZoom) {
57
+ view.setMaxZoom(viewChanges.maxZoom);
58
+ }
59
+ if ("geometry" in viewChanges) {
60
+ const geom = GEOJSON.readGeometry(viewChanges.geometry, {
61
+ dataProjection: "EPSG:4326",
62
+ featureProjection: projection,
63
+ });
64
+ view.fit(geom, {
65
+ size: map.getSize(),
56
66
  });
57
67
  }
58
- if (typeof contextDiff.viewChanges !== "undefined") {
59
- const { viewChanges } = contextDiff;
60
- const view = map.getView();
61
- const projection = view.getProjection();
62
- if (viewChanges === null) {
63
- map.setView(createView(viewChanges, map));
64
- return map;
65
- }
66
- if (viewChanges.maxZoom) {
67
- view.setMaxZoom(viewChanges.maxZoom);
68
- }
69
- if ("geometry" in viewChanges) {
70
- const geom = GEOJSON.readGeometry(viewChanges.geometry, {
71
- dataProjection: "EPSG:4326",
72
- featureProjection: projection,
73
- });
74
- view.fit(geom, {
75
- size: map.getSize(),
76
- });
77
- }
78
- else if ("extent" in viewChanges) {
79
- view.fit(transformExtent(viewChanges.extent, "EPSG:4326", projection), {
80
- size: map.getSize(),
81
- });
82
- }
83
- else {
84
- const { center: centerInViewProj, zoom } = viewChanges;
85
- const center = centerInViewProj
86
- ? fromLonLat(centerInViewProj, projection)
87
- : [0, 0];
88
- view.setCenter(center);
89
- view.setZoom(zoom);
90
- // TODO: factorize this better
91
- // if (viewChanges.maxExtent) {
92
- // map.setView(new View({
93
- //
94
- // }))
95
- // }
96
- }
68
+ else if ("extent" in viewChanges) {
69
+ view.fit(transformExtent(viewChanges.extent, "EPSG:4326", projection), {
70
+ size: map.getSize(),
71
+ });
97
72
  }
98
- return map;
99
- });
73
+ else {
74
+ const { center: centerInViewProj, zoom } = viewChanges;
75
+ const center = centerInViewProj
76
+ ? fromLonLat(centerInViewProj, projection)
77
+ : [0, 0];
78
+ view.setCenter(center);
79
+ view.setZoom(zoom);
80
+ // TODO: factorize this better
81
+ // if (viewChanges.maxExtent) {
82
+ // map.setView(new View({
83
+ //
84
+ // }))
85
+ // }
86
+ }
87
+ }
88
+ return map;
100
89
  }
@@ -1,7 +1,7 @@
1
1
  import { MapContext, MapContextLayer, MapContextView } from "@geospatial-sdk/core";
2
- import Map from "ol/Map";
3
- import View from "ol/View";
4
- import Layer from "ol/layer/Layer";
2
+ import Map from "ol/Map.js";
3
+ import View from "ol/View.js";
4
+ import Layer from "ol/layer/Layer.js";
5
5
  export declare function createLayer(layerModel: MapContextLayer): Promise<Layer>;
6
6
  export declare function createView(viewModel: MapContextView | null, map: Map): View;
7
7
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"create-map.d.ts","sourceRoot":"","sources":["../../lib/map/create-map.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,eAAe,EACf,cAAc,EAEf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,GAAG,MAAM,QAAQ,CAAC;AACzB,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,KAAK,MAAM,gBAAgB,CAAC;AAkCnC,wBAAsB,WAAW,CAAC,UAAU,EAAE,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,CA8N7E;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,CAQd"}
1
+ {"version":3,"file":"create-map.d.ts","sourceRoot":"","sources":["../../lib/map/create-map.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,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;AAkCtC,wBAAsB,WAAW,CAAC,UAAU,EAAE,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,CA8N7E;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,CAQd"}
@@ -1,72 +1,45 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { removeSearchParams, } from "@geospatial-sdk/core";
11
- import Map from "ol/Map";
12
- import View from "ol/View";
13
- import TileLayer from "ol/layer/Tile";
14
- import XYZ from "ol/source/XYZ";
15
- import TileWMS from "ol/source/TileWMS";
16
- import VectorLayer from "ol/layer/Vector";
17
- import VectorSource from "ol/source/Vector";
18
- import GeoJSON from "ol/format/GeoJSON";
19
- import { fromLonLat, transformExtent } from "ol/proj";
20
- import { bbox as bboxStrategy } from "ol/loadingstrategy";
21
- import { defaultStyle } from "./styles";
22
- import VectorTileLayer from "ol/layer/VectorTile";
23
- import OGCMapTile from "ol/source/OGCMapTile";
24
- import OGCVectorTile from "ol/source/OGCVectorTile";
25
- import WMTS from "ol/source/WMTS";
26
- import MVT from "ol/format/MVT";
2
+ import Map from "ol/Map.js";
3
+ import View from "ol/View.js";
4
+ import TileLayer from "ol/layer/Tile.js";
5
+ import XYZ from "ol/source/XYZ.js";
6
+ import TileWMS from "ol/source/TileWMS.js";
7
+ import VectorLayer from "ol/layer/Vector.js";
8
+ import VectorSource from "ol/source/Vector.js";
9
+ import GeoJSON from "ol/format/GeoJSON.js";
10
+ import { fromLonLat, transformExtent } from "ol/proj.js";
11
+ import { bbox as bboxStrategy } from "ol/loadingstrategy.js";
12
+ import { defaultStyle } from "./styles.js";
13
+ import VectorTileLayer from "ol/layer/VectorTile.js";
14
+ import OGCMapTile from "ol/source/OGCMapTile.js";
15
+ import OGCVectorTile from "ol/source/OGCVectorTile.js";
16
+ import WMTS from "ol/source/WMTS.js";
17
+ import MVT from "ol/format/MVT.js";
27
18
  import { OgcApiEndpoint, WfsEndpoint, WmtsEndpoint, } from "@camptocamp/ogc-client";
28
19
  import { MapboxVectorLayer } from "ol-mapbox-style";
29
- import { handleEndpointError, tileLoadErrorCatchFunction, } from "./handle-errors";
30
- import VectorTile from "ol/source/VectorTile";
20
+ import { handleEndpointError, tileLoadErrorCatchFunction, } from "./handle-errors.js";
21
+ import VectorTile from "ol/source/VectorTile.js";
31
22
  const GEOJSON = new GeoJSON();
32
23
  const WFS_MAX_FEATURES = 10000;
33
- export function createLayer(layerModel) {
34
- var _a, _b, _c, _d, _e;
35
- return __awaiter(this, void 0, void 0, function* () {
36
- const { type } = layerModel;
37
- let layer;
38
- switch (type) {
39
- case "xyz":
40
- {
41
- if (layerModel.tileFormat === "application/vnd.mapbox-vector-tile") {
42
- layer = new VectorTileLayer({
43
- source: new VectorTile({
44
- format: new MVT(),
45
- url: layerModel.url,
46
- attributions: layerModel.attributions,
47
- }),
48
- });
49
- }
50
- else {
51
- layer = new TileLayer({});
52
- const source = new XYZ({
24
+ export async function createLayer(layerModel) {
25
+ const { type } = layerModel;
26
+ let layer;
27
+ switch (type) {
28
+ case "xyz":
29
+ {
30
+ if (layerModel.tileFormat === "application/vnd.mapbox-vector-tile") {
31
+ layer = new VectorTileLayer({
32
+ source: new VectorTile({
33
+ format: new MVT(),
53
34
  url: layerModel.url,
54
35
  attributions: layerModel.attributions,
55
- });
56
- source.setTileLoadFunction(function (tile, src) {
57
- return tileLoadErrorCatchFunction(layer, tile, src);
58
- });
59
- layer.setSource(source);
60
- }
36
+ }),
37
+ });
61
38
  }
62
- break;
63
- case "wms":
64
- {
39
+ else {
65
40
  layer = new TileLayer({});
66
- const source = new TileWMS({
67
- url: removeSearchParams(layerModel.url, ["request", "service"]),
68
- params: Object.assign({ LAYERS: layerModel.name }, (layerModel.style && { STYLES: layerModel.style })),
69
- gutter: 20,
41
+ const source = new XYZ({
42
+ url: layerModel.url,
70
43
  attributions: layerModel.attributions,
71
44
  });
72
45
  source.setTileLoadFunction(function (tile, src) {
@@ -74,167 +47,183 @@ export function createLayer(layerModel) {
74
47
  });
75
48
  layer.setSource(source);
76
49
  }
77
- break;
78
- case "wmts": {
79
- const olLayer = new TileLayer({});
80
- const endpoint = new WmtsEndpoint(layerModel.url);
81
- endpoint
82
- .isReady()
83
- .then((endpoint) => __awaiter(this, void 0, void 0, function* () {
84
- var _f;
85
- const layerName = (_f = endpoint.getSingleLayerName()) !== null && _f !== void 0 ? _f : layerModel.name;
86
- const layer = endpoint.getLayerByName(layerName);
87
- const matrixSet = layer.matrixSets[0];
88
- const tileGrid = yield endpoint.getOpenLayersTileGrid(layer.name);
89
- if (tileGrid === null) {
90
- console.warn("A WMTS tile grid could not be created", layerModel);
91
- return;
92
- }
93
- const resourceUrl = layer.resourceLinks[0];
94
- const dimensions = endpoint.getDefaultDimensions(layer.name);
95
- olLayer.setSource(new WMTS({
96
- layer: layer.name,
97
- style: layer.defaultStyle,
98
- matrixSet: matrixSet.identifier,
99
- format: resourceUrl.format,
100
- url: resourceUrl.url,
101
- requestEncoding: resourceUrl.encoding,
102
- tileGrid,
103
- projection: matrixSet.crs,
104
- dimensions,
105
- attributions: layerModel.attributions,
106
- }));
107
- }))
108
- .catch((e) => {
109
- handleEndpointError(olLayer, e);
110
- });
111
- return olLayer;
112
50
  }
113
- case "wfs": {
114
- const olLayer = new VectorLayer({
115
- style: (_a = layerModel.style) !== null && _a !== void 0 ? _a : defaultStyle,
51
+ break;
52
+ case "wms":
53
+ {
54
+ layer = new TileLayer({});
55
+ const source = new TileWMS({
56
+ url: removeSearchParams(layerModel.url, ["request", "service"]),
57
+ params: {
58
+ LAYERS: layerModel.name,
59
+ ...(layerModel.style && { STYLES: layerModel.style }),
60
+ },
61
+ gutter: 20,
62
+ attributions: layerModel.attributions,
63
+ });
64
+ source.setTileLoadFunction(function (tile, src) {
65
+ return tileLoadErrorCatchFunction(layer, tile, src);
116
66
  });
117
- new WfsEndpoint(layerModel.url)
118
- .isReady()
119
- .then((endpoint) => {
120
- var _a;
121
- const featureType = (_a = endpoint.getSingleFeatureTypeName()) !== null && _a !== void 0 ? _a : layerModel.featureType;
122
- olLayer.setSource(new VectorSource({
67
+ layer.setSource(source);
68
+ }
69
+ break;
70
+ case "wmts": {
71
+ const olLayer = new TileLayer({});
72
+ const endpoint = new WmtsEndpoint(layerModel.url);
73
+ endpoint
74
+ .isReady()
75
+ .then(async (endpoint) => {
76
+ const layerName = endpoint.getSingleLayerName() ?? layerModel.name;
77
+ const layer = endpoint.getLayerByName(layerName);
78
+ const matrixSet = layer.matrixSets[0];
79
+ const tileGrid = await endpoint.getOpenLayersTileGrid(layer.name);
80
+ if (tileGrid === null) {
81
+ console.warn("A WMTS tile grid could not be created", layerModel);
82
+ return;
83
+ }
84
+ const resourceUrl = layer.resourceLinks[0];
85
+ const dimensions = endpoint.getDefaultDimensions(layer.name);
86
+ olLayer.setSource(new WMTS({
87
+ layer: layer.name,
88
+ style: layer.defaultStyle,
89
+ matrixSet: matrixSet.identifier,
90
+ format: resourceUrl.format,
91
+ url: resourceUrl.url,
92
+ requestEncoding: resourceUrl.encoding,
93
+ tileGrid,
94
+ projection: matrixSet.crs,
95
+ dimensions,
96
+ attributions: layerModel.attributions,
97
+ }));
98
+ })
99
+ .catch((e) => {
100
+ handleEndpointError(olLayer, e);
101
+ });
102
+ return olLayer;
103
+ }
104
+ case "wfs": {
105
+ const olLayer = new VectorLayer({
106
+ style: layerModel.style ?? defaultStyle,
107
+ });
108
+ new WfsEndpoint(layerModel.url)
109
+ .isReady()
110
+ .then((endpoint) => {
111
+ const featureType = endpoint.getSingleFeatureTypeName() ?? layerModel.featureType;
112
+ olLayer.setSource(new VectorSource({
113
+ format: new GeoJSON(),
114
+ url: function (extent) {
115
+ return endpoint.getFeatureUrl(featureType, {
116
+ maxFeatures: WFS_MAX_FEATURES,
117
+ asJson: true,
118
+ outputCrs: "EPSG:3857",
119
+ extent: extent,
120
+ extentCrs: "EPSG:3857",
121
+ });
122
+ },
123
+ strategy: bboxStrategy,
124
+ attributions: layerModel.attributions,
125
+ }));
126
+ })
127
+ .catch((e) => {
128
+ handleEndpointError(olLayer, e);
129
+ });
130
+ layer = olLayer;
131
+ break;
132
+ }
133
+ case "maplibre-style": {
134
+ layer = new MapboxVectorLayer({
135
+ styleUrl: layerModel.styleUrl,
136
+ accessToken: layerModel.accessToken,
137
+ });
138
+ break;
139
+ }
140
+ case "geojson": {
141
+ if (layerModel.url !== undefined) {
142
+ layer = new VectorLayer({
143
+ source: new VectorSource({
123
144
  format: new GeoJSON(),
124
- url: function (extent) {
125
- return endpoint.getFeatureUrl(featureType, {
126
- maxFeatures: WFS_MAX_FEATURES,
127
- asJson: true,
128
- outputCrs: "EPSG:3857",
129
- extent: extent,
130
- extentCrs: "EPSG:3857",
131
- });
132
- },
133
- strategy: bboxStrategy,
145
+ url: layerModel.url,
134
146
  attributions: layerModel.attributions,
135
- }));
136
- })
137
- .catch((e) => {
138
- handleEndpointError(olLayer, e);
147
+ }),
148
+ style: layerModel.style ?? defaultStyle,
139
149
  });
140
- layer = olLayer;
141
- break;
142
150
  }
143
- case "maplibre-style": {
144
- layer = new MapboxVectorLayer({
145
- styleUrl: layerModel.styleUrl,
146
- accessToken: layerModel.accessToken,
151
+ else {
152
+ let geojson = layerModel.data;
153
+ if (typeof geojson === "string") {
154
+ try {
155
+ geojson = JSON.parse(geojson);
156
+ }
157
+ catch (e) {
158
+ console.warn("A layer could not be created", layerModel, e);
159
+ geojson = { type: "FeatureCollection", features: [] };
160
+ }
161
+ }
162
+ const features = GEOJSON.readFeatures(geojson, {
163
+ featureProjection: "EPSG:3857",
164
+ dataProjection: "EPSG:4326",
165
+ });
166
+ layer = new VectorLayer({
167
+ source: new VectorSource({
168
+ features,
169
+ attributions: layerModel.attributions,
170
+ }),
171
+ style: layerModel.style ?? defaultStyle,
147
172
  });
148
- break;
149
173
  }
150
- case "geojson": {
151
- if (layerModel.url !== undefined) {
152
- layer = new VectorLayer({
153
- source: new VectorSource({
154
- format: new GeoJSON(),
155
- url: layerModel.url,
156
- attributions: layerModel.attributions,
157
- }),
158
- style: (_b = layerModel.style) !== null && _b !== void 0 ? _b : defaultStyle,
159
- });
160
- }
161
- else {
162
- let geojson = layerModel.data;
163
- if (typeof geojson === "string") {
164
- try {
165
- geojson = JSON.parse(geojson);
166
- }
167
- catch (e) {
168
- console.warn("A layer could not be created", layerModel, e);
169
- geojson = { type: "FeatureCollection", features: [] };
170
- }
171
- }
172
- const features = GEOJSON.readFeatures(geojson, {
173
- featureProjection: "EPSG:3857",
174
- dataProjection: "EPSG:4326",
175
- });
176
- layer = new VectorLayer({
177
- source: new VectorSource({
178
- features,
174
+ break;
175
+ }
176
+ case "ogcapi": {
177
+ const ogcEndpoint = new OgcApiEndpoint(layerModel.url);
178
+ let layerUrl;
179
+ if (layerModel.useTiles) {
180
+ if (layerModel.useTiles === "vector") {
181
+ layerUrl = await ogcEndpoint.getVectorTilesetUrl(layerModel.collection, layerModel.tileMatrixSet);
182
+ layer = new VectorTileLayer({
183
+ source: new OGCVectorTile({
184
+ url: layerUrl,
185
+ format: new MVT(),
179
186
  attributions: layerModel.attributions,
180
187
  }),
181
- style: (_c = layerModel.style) !== null && _c !== void 0 ? _c : defaultStyle,
182
188
  });
183
189
  }
184
- break;
185
- }
186
- case "ogcapi": {
187
- const ogcEndpoint = new OgcApiEndpoint(layerModel.url);
188
- let layerUrl;
189
- if (layerModel.useTiles) {
190
- if (layerModel.useTiles === "vector") {
191
- layerUrl = yield ogcEndpoint.getVectorTilesetUrl(layerModel.collection, layerModel.tileMatrixSet);
192
- layer = new VectorTileLayer({
193
- source: new OGCVectorTile({
194
- url: layerUrl,
195
- format: new MVT(),
196
- attributions: layerModel.attributions,
197
- }),
198
- });
199
- }
200
- else if (layerModel.useTiles === "map") {
201
- layerUrl = yield ogcEndpoint.getMapTilesetUrl(layerModel.collection, layerModel.tileMatrixSet);
202
- layer = new TileLayer({
203
- source: new OGCMapTile({
204
- url: layerUrl,
205
- attributions: layerModel.attributions,
206
- }),
207
- });
208
- }
209
- }
210
- else {
211
- layerUrl = yield ogcEndpoint.getCollectionItemsUrl(layerModel.collection, layerModel.options);
212
- layer = new VectorLayer({
213
- source: new VectorSource({
214
- format: new GeoJSON(),
190
+ else if (layerModel.useTiles === "map") {
191
+ layerUrl = await ogcEndpoint.getMapTilesetUrl(layerModel.collection, layerModel.tileMatrixSet);
192
+ layer = new TileLayer({
193
+ source: new OGCMapTile({
215
194
  url: layerUrl,
216
195
  attributions: layerModel.attributions,
217
196
  }),
218
- style: (_d = layerModel.style) !== null && _d !== void 0 ? _d : defaultStyle,
219
197
  });
220
198
  }
221
- break;
222
199
  }
223
- default:
224
- throw new Error(`Unrecognized layer type: ${JSON.stringify(layerModel)}`);
225
- }
226
- if (!layer) {
227
- throw new Error(`Layer could not be created for type: ${layerModel.type}`);
200
+ else {
201
+ layerUrl = await ogcEndpoint.getCollectionItemsUrl(layerModel.collection, layerModel.options);
202
+ layer = new VectorLayer({
203
+ source: new VectorSource({
204
+ format: new GeoJSON(),
205
+ url: layerUrl,
206
+ attributions: layerModel.attributions,
207
+ }),
208
+ style: layerModel.style ?? defaultStyle,
209
+ });
210
+ }
211
+ break;
228
212
  }
229
- typeof layerModel.visibility !== "undefined" &&
230
- layer.setVisible(layerModel.visibility);
231
- typeof layerModel.opacity !== "undefined" &&
232
- layer.setOpacity(layerModel.opacity);
233
- typeof layerModel.attributions !== "undefined" &&
234
- ((_e = layer.getSource()) === null || _e === void 0 ? void 0 : _e.setAttributions(layerModel.attributions));
235
- layer.set("label", layerModel.label);
236
- return layer;
237
- });
213
+ default:
214
+ throw new Error(`Unrecognized layer type: ${JSON.stringify(layerModel)}`);
215
+ }
216
+ if (!layer) {
217
+ throw new Error(`Layer could not be created for type: ${layerModel.type}`);
218
+ }
219
+ typeof layerModel.visibility !== "undefined" &&
220
+ layer.setVisible(layerModel.visibility);
221
+ typeof layerModel.opacity !== "undefined" &&
222
+ layer.setOpacity(layerModel.opacity);
223
+ typeof layerModel.attributions !== "undefined" &&
224
+ layer.getSource()?.setAttributions(layerModel.attributions);
225
+ layer.set("label", layerModel.label);
226
+ return layer;
238
227
  }
239
228
  export function createView(viewModel, map) {
240
229
  if (viewModel === null) {
@@ -243,7 +232,12 @@ export function createView(viewModel, map) {
243
232
  zoom: 0,
244
233
  });
245
234
  }
246
- const view = new View(Object.assign(Object.assign(Object.assign({}, ("maxExtent" in viewModel && { extent: viewModel.maxExtent })), ("maxZoom" in viewModel && { maxZoom: viewModel.maxZoom })), { multiWorld: false, constrainResolution: true }));
235
+ const view = new View({
236
+ ...("maxExtent" in viewModel && { extent: viewModel.maxExtent }),
237
+ ...("maxZoom" in viewModel && { maxZoom: viewModel.maxZoom }),
238
+ multiWorld: false,
239
+ constrainResolution: true,
240
+ });
247
241
  if ("geometry" in viewModel) {
248
242
  const geom = GEOJSON.readGeometry(viewModel.geometry);
249
243
  view.fit(geom, {
@@ -270,27 +264,23 @@ export function createView(viewModel, map) {
270
264
  * @param context
271
265
  * @param target
272
266
  */
273
- export function createMapFromContext(context, target) {
274
- return __awaiter(this, void 0, void 0, function* () {
275
- const map = new Map({
276
- target,
277
- });
278
- return yield resetMapFromContext(map, context);
267
+ export async function createMapFromContext(context, target) {
268
+ const map = new Map({
269
+ target,
279
270
  });
271
+ return await resetMapFromContext(map, context);
280
272
  }
281
273
  /**
282
274
  * Resets an OpenLayers map from a context; existing content will be cleared
283
275
  * @param map
284
276
  * @param context
285
277
  */
286
- export function resetMapFromContext(map, context) {
287
- return __awaiter(this, void 0, void 0, function* () {
288
- map.setView(createView(context.view, map));
289
- map.getLayers().clear();
290
- for (const layerModel of context.layers) {
291
- const layer = yield createLayer(layerModel);
292
- map.addLayer(layer);
293
- }
294
- return map;
295
- });
278
+ export async function resetMapFromContext(map, context) {
279
+ map.setView(createView(context.view, map));
280
+ map.getLayers().clear();
281
+ for (const layerModel of context.layers) {
282
+ const layer = await createLayer(layerModel);
283
+ map.addLayer(layer);
284
+ }
285
+ return map;
296
286
  }
@@ -1,10 +1,10 @@
1
1
  import { EndpointError } from "@camptocamp/ogc-client";
2
2
  import { Tile } from "ol";
3
- import { Layer } from "ol/layer";
4
- import TileLayer from "ol/layer/Tile";
5
- import VectorLayer from "ol/layer/Vector";
6
- import TileSource from "ol/source/Tile";
7
- import VectorSource from "ol/source/Vector";
3
+ import { Layer } from "ol/layer.js";
4
+ import TileLayer from "ol/layer/Tile.js";
5
+ import VectorLayer from "ol/layer/Vector.js";
6
+ import TileSource from "ol/source/Tile.js";
7
+ import VectorSource from "ol/source/Vector.js";
8
8
  export declare function handleEndpointError(layer: TileLayer<TileSource> | VectorLayer<VectorSource>, error: EndpointError): void;
9
9
  export declare function handleTileError(response: Response | Error, tile: Tile, layer: Layer): void;
10
10
  export declare function tileLoadErrorCatchFunction(layer: Layer, tile: Tile, src: string): void;
@@ -1 +1 @@
1
- {"version":3,"file":"handle-errors.d.ts","sourceRoot":"","sources":["../../lib/map/handle-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAa,IAAI,EAAE,MAAM,IAAI,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,SAAS,MAAM,eAAe,CAAC;AACtC,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAC1C,OAAO,UAAU,MAAM,gBAAgB,CAAC;AACxC,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAG5C,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,SAAS,CAAC,UAAU,CAAC,GAAG,WAAW,CAAC,YAAY,CAAC,EACxD,KAAK,EAAE,aAAa,QAIrB;AAED,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,QAAQ,GAAG,KAAK,EAC1B,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,QAKb;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,MAAM,QAqBZ"}
1
+ {"version":3,"file":"handle-errors.d.ts","sourceRoot":"","sources":["../../lib/map/handle-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAa,IAAI,EAAE,MAAM,IAAI,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,WAAW,MAAM,oBAAoB,CAAC;AAC7C,OAAO,UAAU,MAAM,mBAAmB,CAAC;AAC3C,OAAO,YAAY,MAAM,qBAAqB,CAAC;AAG/C,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,SAAS,CAAC,UAAU,CAAC,GAAG,WAAW,CAAC,YAAY,CAAC,EACxD,KAAK,EAAE,aAAa,QAIrB;AAED,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,QAAQ,GAAG,KAAK,EAC1B,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,QAKb;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,MAAM,QAqBZ"}
@@ -1,5 +1,5 @@
1
- export * from "./styles";
2
- export { createMapFromContext, resetMapFromContext } from "./create-map";
3
- export { applyContextDiffToMap } from "./apply-context-diff";
4
- export { listen } from "./register-events";
1
+ export * from "./styles.js";
2
+ export { createMapFromContext, resetMapFromContext } from "./create-map.js";
3
+ export { applyContextDiffToMap } from "./apply-context-diff.js";
4
+ export { listen } from "./register-events.js";
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/map/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/map/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC"}
package/dist/map/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export * from "./styles";
2
- export { createMapFromContext, resetMapFromContext } from "./create-map";
3
- export { applyContextDiffToMap } from "./apply-context-diff";
4
- export { listen } from "./register-events";
1
+ export * from "./styles.js";
2
+ export { createMapFromContext, resetMapFromContext } from "./create-map.js";
3
+ export { applyContextDiffToMap } from "./apply-context-diff.js";
4
+ export { listen } from "./register-events.js";
@@ -1,9 +1,9 @@
1
- import Map from "ol/Map";
1
+ import Map from "ol/Map.js";
2
2
  import { MapEventsByType } from "@geospatial-sdk/core";
3
- import { Coordinate } from "ol/coordinate";
4
- import TileWMS from "ol/source/TileWMS";
5
- import ImageWMS from "ol/source/ImageWMS";
6
- import { Pixel } from "ol/pixel";
3
+ import { Coordinate } from "ol/coordinate.js";
4
+ import TileWMS from "ol/source/TileWMS.js";
5
+ import ImageWMS from "ol/source/ImageWMS.js";
6
+ import { Pixel } from "ol/pixel.js";
7
7
  import type { Feature } from "geojson";
8
8
  export declare function getFeaturesFromVectorSources(olMap: Map, pixel: Pixel): Feature[];
9
9
  export declare function getGFIUrl(source: TileWMS | ImageWMS, map: Map, coordinate: Coordinate): string | null;
@@ -1 +1 @@
1
- {"version":3,"file":"register-events.d.ts","sourceRoot":"","sources":["../../lib/map/register-events.ts"],"names":[],"mappings":"AAAA,OAAO,GAA4B,MAAM,QAAQ,CAAC;AAClD,OAAO,EAKL,eAAe,EAEhB,MAAM,sBAAsB,CAAC;AAM9B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,OAAO,MAAM,mBAAmB,CAAC;AACxC,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,KAAK,EAAE,OAAO,EAAqB,MAAM,SAAS,CAAC;AAO1D,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,GAAG,EACV,KAAK,EAAE,KAAK,GACX,OAAO,EAAE,CAOX;AAED,wBAAgB,SAAS,CACvB,MAAM,EAAE,OAAO,GAAG,QAAQ,EAC1B,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,GACrB,MAAM,GAAG,IAAI,CAWf;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,GAAG,EACV,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,OAAO,EAAE,CAAC,CA2BpB;AA8ED,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,eAAe,EACpD,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,CAAC,EACZ,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,IAAI,QA0E9C"}
1
+ {"version":3,"file":"register-events.d.ts","sourceRoot":"","sources":["../../lib/map/register-events.ts"],"names":[],"mappings":"AAAA,OAAO,GAA4B,MAAM,WAAW,CAAC;AACrD,OAAO,EAKL,eAAe,EAEhB,MAAM,sBAAsB,CAAC;AAM9B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,OAAO,MAAM,sBAAsB,CAAC;AAC3C,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAE7C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAqB,MAAM,SAAS,CAAC;AAO1D,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,GAAG,EACV,KAAK,EAAE,KAAK,GACX,OAAO,EAAE,CAOX;AAED,wBAAgB,SAAS,CACvB,MAAM,EAAE,OAAO,GAAG,QAAQ,EAC1B,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,GACrB,MAAM,GAAG,IAAI,CAWf;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,GAAG,EACV,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,OAAO,EAAE,CAAC,CA2BpB;AA8ED,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,eAAe,EACpD,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,CAAC,EACZ,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,IAAI,QA0E9C"}
@@ -1,20 +1,11 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { FeaturesClickEventType, FeaturesHoverEventType, MapClickEventType, MapExtentChangeEventType, SourceLoadErrorType, } from "@geospatial-sdk/core";
11
- import { toLonLat, transformExtent } from "ol/proj";
12
- import GeoJSON from "ol/format/GeoJSON";
13
- import TileWMS from "ol/source/TileWMS";
14
- import ImageWMS from "ol/source/ImageWMS";
15
- import Layer from "ol/layer/Layer";
2
+ import { toLonLat, transformExtent } from "ol/proj.js";
3
+ import GeoJSON from "ol/format/GeoJSON.js";
4
+ import TileWMS from "ol/source/TileWMS.js";
5
+ import ImageWMS from "ol/source/ImageWMS.js";
6
+ import Layer from "ol/layer/Layer.js";
16
7
  import throttle from "lodash.throttle";
17
- import { equals } from "ol/extent";
8
+ import { equals } from "ol/extent.js";
18
9
  const GEOJSON = new GeoJSON();
19
10
  export function getFeaturesFromVectorSources(olMap, pixel) {
20
11
  const olFeatures = olMap.getFeaturesAtPixel(pixel);
@@ -25,12 +16,14 @@ export function getFeaturesFromVectorSources(olMap, pixel) {
25
16
  return features;
26
17
  }
27
18
  export function getGFIUrl(source, map, coordinate) {
28
- var _a;
29
19
  const view = map.getView();
30
20
  const projection = view.getProjection();
31
21
  const resolution = view.getResolution();
32
- const params = Object.assign(Object.assign({}, source.getParams()), { INFO_FORMAT: "application/json" });
33
- return ((_a = source.getFeatureInfoUrl(coordinate, resolution, projection, params)) !== null && _a !== void 0 ? _a : null);
22
+ const params = {
23
+ ...source.getParams(),
24
+ INFO_FORMAT: "application/json",
25
+ };
26
+ return (source.getFeatureInfoUrl(coordinate, resolution, projection, params) ?? null);
34
27
  }
35
28
  export function getFeaturesFromWmsSources(olMap, coordinate) {
36
29
  const wmsSources = olMap
@@ -52,36 +45,34 @@ export function getFeaturesFromWmsSources(olMap, coordinate) {
52
45
  .then((collection) => collection.features))).then((features) => features.flat());
53
46
  }
54
47
  const getFeaturesFromWmsSourcesThrottled = throttle(getFeaturesFromWmsSources, 250);
55
- function readFeaturesAtPixel(map, event) {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- return [
58
- ...getFeaturesFromVectorSources(map, event.pixel),
59
- ...(yield getFeaturesFromWmsSourcesThrottled(map, event.coordinate)),
60
- ];
61
- });
48
+ async function readFeaturesAtPixel(map, event) {
49
+ return [
50
+ ...getFeaturesFromVectorSources(map, event.pixel),
51
+ ...(await getFeaturesFromWmsSourcesThrottled(map, event.coordinate)),
52
+ ];
62
53
  }
63
54
  function registerFeatureClickEvent(map) {
64
55
  if (map.get(FeaturesClickEventType))
65
56
  return;
66
- map.on("click", (event) => __awaiter(this, void 0, void 0, function* () {
67
- const features = yield readFeaturesAtPixel(map, event);
57
+ map.on("click", async (event) => {
58
+ const features = await readFeaturesAtPixel(map, event);
68
59
  map.dispatchEvent({
69
60
  type: FeaturesClickEventType,
70
61
  features,
71
62
  });
72
- }));
63
+ });
73
64
  map.set(FeaturesClickEventType, true);
74
65
  }
75
66
  function registerFeatureHoverEvent(map) {
76
67
  if (map.get(FeaturesHoverEventType))
77
68
  return;
78
- map.on("pointermove", (event) => __awaiter(this, void 0, void 0, function* () {
79
- const features = yield readFeaturesAtPixel(map, event);
69
+ map.on("pointermove", async (event) => {
70
+ const features = await readFeaturesAtPixel(map, event);
80
71
  map.dispatchEvent({
81
72
  type: FeaturesHoverEventType,
82
73
  features,
83
74
  });
84
- }));
75
+ });
85
76
  map.set(FeaturesHoverEventType, true);
86
77
  }
87
78
  function registerMapExtentChangeEvent(map) {
@@ -1,5 +1,5 @@
1
- import { Style } from "ol/style";
2
- import { StyleFunction } from "ol/style/Style";
1
+ import { Style } from "ol/style.js";
2
+ import { StyleFunction } from "ol/style/Style.js";
3
3
  export interface CreateStyleOptions {
4
4
  color: string;
5
5
  isFocused?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../lib/map/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAI/C,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,KAAK,GAAG,KAAK,EAAE,CAAC;IACtB,OAAO,EAAE,KAAK,GAAG,KAAK,EAAE,CAAC;IACzB,KAAK,EAAE,KAAK,GAAG,KAAK,EAAE,CAAC;CACxB;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,kBAAkB,GAC1B,mBAAmB,CA4CrB;AAED,wBAAgB,mBAAmB,CACjC,mBAAmB,EAAE,mBAAmB,GACvC,aAAa,CAmBf;AAMD,eAAO,MAAM,YAAY,eAIxB,CAAC;AAEF,eAAO,MAAM,qBAAqB,eAKjC,CAAC"}
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../lib/map/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIlD,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,KAAK,GAAG,KAAK,EAAE,CAAC;IACtB,OAAO,EAAE,KAAK,GAAG,KAAK,EAAE,CAAC;IACzB,KAAK,EAAE,KAAK,GAAG,KAAK,EAAE,CAAC;CACxB;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,kBAAkB,GAC1B,mBAAmB,CA4CrB;AAED,wBAAgB,mBAAmB,CACjC,mBAAmB,EAAE,mBAAmB,GACvC,aAAa,CAmBf;AAMD,eAAO,MAAM,YAAY,eAIxB,CAAC;AAEF,eAAO,MAAM,qBAAqB,eAKjC,CAAC"}
@@ -1,4 +1,4 @@
1
- import { Circle, Fill, Stroke, Style } from "ol/style";
1
+ import { Circle, Fill, Stroke, Style } from "ol/style.js";
2
2
  import chroma from "chroma-js";
3
3
  export function createGeometryStyles(options) {
4
4
  const { color, isFocused } = options;
@@ -47,8 +47,7 @@ export function createGeometryStyles(options) {
47
47
  }
48
48
  export function createStyleFunction(styleByGeometryType) {
49
49
  return (feature) => {
50
- var _a;
51
- const geometryType = (_a = feature === null || feature === void 0 ? void 0 : feature.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType();
50
+ const geometryType = feature?.getGeometry()?.getType();
52
51
  switch (geometryType) {
53
52
  case "LinearRing":
54
53
  case "LineString":
package/lib/index.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // PUBLIC API
2
- export * from "./map";
2
+ export * from "./map/index.js";
@@ -1,9 +1,9 @@
1
- import Map from "ol/Map";
1
+ import Map from "ol/Map.js";
2
2
  import { MapContextDiff } from "@geospatial-sdk/core";
3
- import { createLayer, createView } from "./create-map";
4
- import { fromLonLat, transformExtent } from "ol/proj";
5
- import GeoJSON from "ol/format/GeoJSON";
6
- import SimpleGeometry from "ol/geom/SimpleGeometry";
3
+ import { createLayer, createView } from "./create-map.js";
4
+ import { fromLonLat, transformExtent } from "ol/proj.js";
5
+ import GeoJSON from "ol/format/GeoJSON.js";
6
+ import SimpleGeometry from "ol/geom/SimpleGeometry.js";
7
7
 
8
8
  const GEOJSON = new GeoJSON();
9
9
 
@@ -158,7 +158,7 @@ describe("MapContextService", () => {
158
158
  const urls = source.getUrls() || [];
159
159
  expect(urls.length).toBe(1);
160
160
  expect(urls[0]).toBe(
161
- "https://www.geograndest.fr/geoserver/region-grand-est/ows",
161
+ "https://www.datagrandest.fr/geoserver/region-grand-est/ows",
162
162
  );
163
163
  });
164
164
  it("set WMS gutter of 20px", () => {
@@ -211,7 +211,7 @@ describe("MapContextService", () => {
211
211
  const source = layer.getSource() as VectorSource;
212
212
  const urlLoader = source.getUrl() as Function;
213
213
  expect(urlLoader([10, 20, 30, 40])).toBe(
214
- "https://www.geograndest.fr/geoserver/region-grand-est/ows?service=WFS&version=1.1.0&request=GetFeature&outputFormat=application%2Fjson&typename=ms%3Acommune_actuelle_3857&srsname=EPSG%3A3857&bbox=10%2C20%2C30%2C40%2CEPSG%3A3857&maxFeatures=10000",
214
+ "https://www.datagrandest.fr/geoserver/region-grand-est/ows?service=WFS&version=1.1.0&request=GetFeature&outputFormat=application%2Fjson&typename=ms%3Acommune_actuelle_3857&srsname=EPSG%3A3857&bbox=10%2C20%2C30%2C40%2CEPSG%3A3857&maxFeatures=10000",
215
215
  );
216
216
  });
217
217
  it("should NOT call handleEndpointError", () => {
@@ -4,26 +4,26 @@ import {
4
4
  MapContextView,
5
5
  removeSearchParams,
6
6
  } from "@geospatial-sdk/core";
7
- import Map from "ol/Map";
8
- import View from "ol/View";
9
- import Layer from "ol/layer/Layer";
10
- import TileLayer from "ol/layer/Tile";
11
- import XYZ from "ol/source/XYZ";
12
- import TileWMS from "ol/source/TileWMS";
13
- import VectorLayer from "ol/layer/Vector";
14
- import VectorSource from "ol/source/Vector";
15
- import GeoJSON from "ol/format/GeoJSON";
16
- import Feature from "ol/Feature";
17
- import Geometry from "ol/geom/Geometry";
18
- import SimpleGeometry from "ol/geom/SimpleGeometry";
19
- import { fromLonLat, transformExtent } from "ol/proj";
20
- import { bbox as bboxStrategy } from "ol/loadingstrategy";
21
- import { defaultStyle } from "./styles";
22
- import VectorTileLayer from "ol/layer/VectorTile";
23
- import OGCMapTile from "ol/source/OGCMapTile";
24
- import OGCVectorTile from "ol/source/OGCVectorTile";
25
- import WMTS from "ol/source/WMTS";
26
- import MVT from "ol/format/MVT";
7
+ import Map from "ol/Map.js";
8
+ import View from "ol/View.js";
9
+ import Layer from "ol/layer/Layer.js";
10
+ import TileLayer from "ol/layer/Tile.js";
11
+ import XYZ from "ol/source/XYZ.js";
12
+ import TileWMS from "ol/source/TileWMS.js";
13
+ import VectorLayer from "ol/layer/Vector.js";
14
+ import VectorSource from "ol/source/Vector.js";
15
+ import GeoJSON from "ol/format/GeoJSON.js";
16
+ import Feature from "ol/Feature.js";
17
+ import Geometry from "ol/geom/Geometry.js";
18
+ import SimpleGeometry from "ol/geom/SimpleGeometry.js";
19
+ import { fromLonLat, transformExtent } from "ol/proj.js";
20
+ import { bbox as bboxStrategy } from "ol/loadingstrategy.js";
21
+ import { defaultStyle } from "./styles.js";
22
+ import VectorTileLayer from "ol/layer/VectorTile.js";
23
+ import OGCMapTile from "ol/source/OGCMapTile.js";
24
+ import OGCVectorTile from "ol/source/OGCVectorTile.js";
25
+ import WMTS from "ol/source/WMTS.js";
26
+ import MVT from "ol/format/MVT.js";
27
27
  import {
28
28
  OgcApiEndpoint,
29
29
  WfsEndpoint,
@@ -34,8 +34,8 @@ import { Tile } from "ol";
34
34
  import {
35
35
  handleEndpointError,
36
36
  tileLoadErrorCatchFunction,
37
- } from "./handle-errors";
38
- import VectorTile from "ol/source/VectorTile";
37
+ } from "./handle-errors.js";
38
+ import VectorTile from "ol/source/VectorTile.js";
39
39
 
40
40
  const GEOJSON = new GeoJSON();
41
41
  const WFS_MAX_FEATURES = 10000;
@@ -1,11 +1,11 @@
1
1
  import { EndpointError } from "@camptocamp/ogc-client";
2
2
  import { SourceLoadErrorEvent } from "@geospatial-sdk/core";
3
3
  import { ImageTile, Tile } from "ol";
4
- import { Layer } from "ol/layer";
5
- import TileLayer from "ol/layer/Tile";
6
- import VectorLayer from "ol/layer/Vector";
7
- import TileSource from "ol/source/Tile";
8
- import VectorSource from "ol/source/Vector";
4
+ import { Layer } from "ol/layer.js";
5
+ import TileLayer from "ol/layer/Tile.js";
6
+ import VectorLayer from "ol/layer/Vector.js";
7
+ import TileSource from "ol/source/Tile.js";
8
+ import VectorSource from "ol/source/Vector.js";
9
9
  import TileState from "ol/TileState.js";
10
10
 
11
11
  export function handleEndpointError(
package/lib/map/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from "./styles";
2
- export { createMapFromContext, resetMapFromContext } from "./create-map";
3
- export { applyContextDiffToMap } from "./apply-context-diff";
4
- export { listen } from "./register-events";
1
+ export * from "./styles.js";
2
+ export { createMapFromContext, resetMapFromContext } from "./create-map.js";
3
+ export { applyContextDiffToMap } from "./apply-context-diff.js";
4
+ export { listen } from "./register-events.js";
@@ -1,4 +1,4 @@
1
- import Map, { MapObjectEventTypes } from "ol/Map";
1
+ import Map, { MapObjectEventTypes } from "ol/Map.js";
2
2
  import {
3
3
  FeaturesClickEventType,
4
4
  FeaturesHoverEventType,
@@ -7,20 +7,20 @@ import {
7
7
  MapEventsByType,
8
8
  SourceLoadErrorType,
9
9
  } from "@geospatial-sdk/core";
10
- import { toLonLat, transformExtent } from "ol/proj";
11
- import GeoJSON from "ol/format/GeoJSON";
12
- import OlFeature from "ol/Feature";
13
- import BaseEvent from "ol/events/Event";
10
+ import { toLonLat, transformExtent } from "ol/proj.js";
11
+ import GeoJSON from "ol/format/GeoJSON.js";
12
+ import OlFeature from "ol/Feature.js";
13
+ import BaseEvent from "ol/events/Event.js";
14
14
  import { MapBrowserEvent } from "ol";
15
- import { Coordinate } from "ol/coordinate";
16
- import TileWMS from "ol/source/TileWMS";
17
- import ImageWMS from "ol/source/ImageWMS";
18
- import Layer from "ol/layer/Layer";
19
- import { Pixel } from "ol/pixel";
15
+ import { Coordinate } from "ol/coordinate.js";
16
+ import TileWMS from "ol/source/TileWMS.js";
17
+ import ImageWMS from "ol/source/ImageWMS.js";
18
+ import Layer from "ol/layer/Layer.js";
19
+ import { Pixel } from "ol/pixel.js";
20
20
  import type { Feature, FeatureCollection } from "geojson";
21
21
  import throttle from "lodash.throttle";
22
- import { BaseLayerObjectEventTypes } from "ol/layer/Base";
23
- import { equals } from "ol/extent";
22
+ import { BaseLayerObjectEventTypes } from "ol/layer/Base.js";
23
+ import { equals } from "ol/extent.js";
24
24
 
25
25
  const GEOJSON = new GeoJSON();
26
26
 
@@ -103,7 +103,7 @@ async function readFeaturesAtPixel(
103
103
  function registerFeatureClickEvent(map: Map) {
104
104
  if (map.get(FeaturesClickEventType)) return;
105
105
 
106
- map.on("click", async (event) => {
106
+ map.on("click", async (event: any) => {
107
107
  const features = await readFeaturesAtPixel(map, event);
108
108
  map.dispatchEvent({
109
109
  type: FeaturesClickEventType,
@@ -117,7 +117,7 @@ function registerFeatureClickEvent(map: Map) {
117
117
  function registerFeatureHoverEvent(map: Map) {
118
118
  if (map.get(FeaturesHoverEventType)) return;
119
119
 
120
- map.on("pointermove", async (event) => {
120
+ map.on("pointermove", async (event: any) => {
121
121
  const features = await readFeaturesAtPixel(map, event);
122
122
  map.dispatchEvent({
123
123
  type: FeaturesHoverEventType,
@@ -170,19 +170,19 @@ export function listen<T extends keyof MapEventsByType>(
170
170
  case FeaturesClickEventType:
171
171
  registerFeatureClickEvent(map);
172
172
  // we're using a custom event type here so we need to cast to unknown first
173
- map.on(eventType as unknown as MapObjectEventTypes, (event) => {
173
+ map.on(eventType as unknown as MapObjectEventTypes, (event: any) => {
174
174
  (callback as (event: unknown) => void)(event);
175
175
  });
176
176
  break;
177
177
  case FeaturesHoverEventType:
178
178
  registerFeatureHoverEvent(map);
179
179
  // see comment above
180
- map.on(eventType as unknown as MapObjectEventTypes, (event) => {
180
+ map.on(eventType as unknown as MapObjectEventTypes, (event: any) => {
181
181
  (callback as (event: unknown) => void)(event);
182
182
  });
183
183
  break;
184
184
  case MapClickEventType:
185
- map.on("click", (event) => {
185
+ map.on("click", (event: any) => {
186
186
  const coordinate = toLonLat(
187
187
  event.coordinate,
188
188
  map.getView().getProjection(),
@@ -196,7 +196,7 @@ export function listen<T extends keyof MapEventsByType>(
196
196
  case MapExtentChangeEventType:
197
197
  registerMapExtentChangeEvent(map);
198
198
  // see comment above
199
- map.on(eventType as unknown as MapObjectEventTypes, (event) => {
199
+ map.on(eventType as unknown as MapObjectEventTypes, (event: any) => {
200
200
  (callback as (event: unknown) => void)(event);
201
201
  });
202
202
  break;
@@ -214,7 +214,7 @@ export function listen<T extends keyof MapEventsByType>(
214
214
  }
215
215
  });
216
216
  //attach event listener when layer is added
217
- map.getLayers().on("add", (event) => {
217
+ map.getLayers().on("add", (event: any) => {
218
218
  const layer = event.element as Layer;
219
219
  if (layer) {
220
220
  layer.on(
@@ -224,7 +224,7 @@ export function listen<T extends keyof MapEventsByType>(
224
224
  }
225
225
  });
226
226
  //remove event listener when layer is removed
227
- map.getLayers().on("remove", (event) => {
227
+ map.getLayers().on("remove", (event: any) => {
228
228
  const layer = event.element as Layer;
229
229
  if (layer) {
230
230
  layer.un(
package/lib/map/styles.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { Circle, Fill, Stroke, Style } from "ol/style";
2
- import { StyleFunction } from "ol/style/Style";
3
- import { FeatureLike } from "ol/Feature";
1
+ import { Circle, Fill, Stroke, Style } from "ol/style.js";
2
+ import { StyleFunction } from "ol/style/Style.js";
3
+ import { FeatureLike } from "ol/Feature.js";
4
4
  import chroma from "chroma-js";
5
5
 
6
6
  export interface CreateStyleOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geospatial-sdk/openlayers",
3
- "version": "0.0.5-dev.40+17bad88",
3
+ "version": "0.0.5-dev.42+baa75c1",
4
4
  "description": "OpenLayers-related utilities",
5
5
  "keywords": [
6
6
  "ol",
@@ -37,10 +37,10 @@
37
37
  "ol": ">6.x"
38
38
  },
39
39
  "dependencies": {
40
- "@geospatial-sdk/core": "^0.0.5-dev.40+17bad88",
40
+ "@geospatial-sdk/core": "^0.0.5-dev.42+baa75c1",
41
41
  "chroma-js": "^2.4.2",
42
42
  "lodash.throttle": "^4.1.1",
43
43
  "ol-mapbox-style": "12.4.0"
44
44
  },
45
- "gitHead": "17bad885319e693911c2219422bfe3fca4437fa2"
45
+ "gitHead": "baa75c1fed77ed160f6a2d94bfeb5358cc91d63a"
46
46
  }