@geospatial-sdk/core 0.0.5-dev.44 → 0.0.5-dev.45
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/README.md +38 -5
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/model/index.d.ts +4 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +4 -0
- package/dist/model/map-context.d.ts +24 -6
- package/dist/model/map-context.d.ts.map +1 -1
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +4 -0
- package/dist/utils/map-context.d.ts.map +1 -1
- package/dist/utils/map-context.js +3 -1
- package/dist/utils/view.d.ts +22 -0
- package/dist/utils/view.d.ts.map +1 -1
- package/dist/utils/view.js +22 -0
- package/lib/index.ts +6 -1
- package/lib/model/index.ts +5 -0
- package/lib/model/map-context-diff.ts +1 -1
- package/lib/model/map-context.ts +25 -8
- package/lib/utils/index.ts +5 -0
- package/lib/utils/map-context.test.ts +31 -9
- package/lib/utils/map-context.ts +5 -1
- package/lib/utils/view.ts +22 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,11 +1,44 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@geospatial-sdk/core`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<!-- #region body -->
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This package provides the foundation for the Geospatial SDK.
|
|
6
|
+
|
|
7
|
+
It includes:
|
|
8
|
+
|
|
9
|
+
- **Map Context model**: TypeScript types and interfaces for declaratively defining maps, layers, and views
|
|
10
|
+
- **Diff algorithms**: Utilities to compute differences between Map Context objects (`computeMapContextDiff`)
|
|
11
|
+
- **Validation utilities**: Tools for working with and validating geospatial data
|
|
12
|
+
- **Shared constants**: Common definitions used across all packages
|
|
13
|
+
|
|
14
|
+
The `@geospatial-sdk/core` package is framework-agnostic and does not depend on any specific mapping library. It's required by all other packages in the SDK.
|
|
6
15
|
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install @geospatial-sdk/core
|
|
7
20
|
```
|
|
8
|
-
const core = require('core');
|
|
9
21
|
|
|
10
|
-
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { computeMapContextDiff, type MapContext } from "@geospatial-sdk/core";
|
|
26
|
+
|
|
27
|
+
const oldContext: MapContext = {
|
|
28
|
+
layers: [{ type: "xyz", url: "https://example.com/{z}/{x}/{y}.png" }],
|
|
29
|
+
view: { center: [0, 0], zoom: 2 },
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const newContext: MapContext = {
|
|
33
|
+
layers: [{ type: "xyz", url: "https://example.com/{z}/{x}/{y}.png" }],
|
|
34
|
+
view: { center: [5, 45], zoom: 5 },
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const diff = computeMapContextDiff(newContext, oldContext);
|
|
11
38
|
```
|
|
39
|
+
|
|
40
|
+
<!-- #endregion body -->
|
|
41
|
+
|
|
42
|
+
## Documentation
|
|
43
|
+
|
|
44
|
+
For more detailed API documentation, see the [documentation website](https://camptocamp.github.io/geospatial-sdk/docs/).
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/model/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/model/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
package/dist/model/index.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { FeatureCollection, Geometry } from "geojson";
|
|
2
2
|
import { VectorStyle } from "./style.js";
|
|
3
|
+
/**
|
|
4
|
+
* @private
|
|
5
|
+
* @inline
|
|
6
|
+
*/
|
|
3
7
|
export type LayerDimensions = Record<string, string>;
|
|
8
|
+
/**
|
|
9
|
+
* @private
|
|
10
|
+
* @inline
|
|
11
|
+
*/
|
|
4
12
|
export type LayerExtras = Record<string, unknown>;
|
|
5
13
|
export interface MapContextBaseLayer {
|
|
6
14
|
id?: string | number;
|
|
@@ -67,17 +75,14 @@ export interface LayerGeojsonWithData extends LayerGeojson {
|
|
|
67
75
|
data: FeatureCollection<Geometry | null> | string;
|
|
68
76
|
url?: never;
|
|
69
77
|
}
|
|
70
|
-
/**
|
|
71
|
-
* @interface
|
|
72
|
-
*/
|
|
73
78
|
export type MapContextLayerGeojson = LayerGeojsonWithUrl | LayerGeojsonWithData;
|
|
74
79
|
/**
|
|
75
|
-
*
|
|
80
|
+
* A layer that can be used in a map context.
|
|
76
81
|
*/
|
|
77
82
|
export type MapContextLayer = MapContextLayerWms | MapContextLayerWmts | MapContextLayerWfs | MapContextLayerXyz | MapContextLayerGeojson | MapContextLayerOgcApi | MapContextLayerMapLibreStyle;
|
|
78
83
|
export type Coordinate = [number, number];
|
|
79
84
|
/**
|
|
80
|
-
*
|
|
85
|
+
* Array components are respectively: minX, minY, maxX, maxY
|
|
81
86
|
*/
|
|
82
87
|
export type Extent = [number, number, number, number];
|
|
83
88
|
/**
|
|
@@ -95,15 +100,28 @@ export interface ViewByExtent {
|
|
|
95
100
|
extent: Extent;
|
|
96
101
|
}
|
|
97
102
|
/**
|
|
98
|
-
* @property geometry Expressed in
|
|
103
|
+
* @property geometry Expressed in GeoJSON
|
|
99
104
|
*/
|
|
100
105
|
export interface ViewByGeometry {
|
|
101
106
|
geometry: Geometry;
|
|
102
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* A description of a map viewport in one of three ways:
|
|
110
|
+
* * by center and zoom level,
|
|
111
|
+
* * by extent,
|
|
112
|
+
* * by geometry (in GeoJSON)
|
|
113
|
+
*
|
|
114
|
+
* Also allows specifying constraints for zoom and extent.
|
|
115
|
+
*/
|
|
103
116
|
export type MapContextView = (ViewByZoomAndCenter | ViewByExtent | ViewByGeometry) & {
|
|
104
117
|
maxZoom?: number;
|
|
105
118
|
maxExtent?: Extent;
|
|
106
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* A map context, containing layers and a view.
|
|
122
|
+
*
|
|
123
|
+
* Note: setting the `view` property to `null` indicates that the map should use a default global view.
|
|
124
|
+
*/
|
|
107
125
|
export interface MapContext {
|
|
108
126
|
layers: MapContextLayer[];
|
|
109
127
|
view: MapContextView | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-context.d.ts","sourceRoot":"","sources":["../../lib/model/map-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAErD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAElD,MAAM,WAAW,mBAAmB;IAClC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,MAAM,CAAC,EAAE,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AI,CAAC;CAC7B"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/utils/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-context.d.ts","sourceRoot":"","sources":["../../lib/utils/map-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGhE,wBAAgB,YAAY,CAC1B,KAAK,EAAE,eAAe,EACtB,aAAa,UAAQ,GACpB,MAAM,CAER;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,eAAe,GACtB,OAAO,CAKT;AAED,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,eAAe,GACtB,OAAO,
|
|
1
|
+
{"version":3,"file":"map-context.d.ts","sourceRoot":"","sources":["../../lib/utils/map-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGhE,wBAAgB,YAAY,CAC1B,KAAK,EAAE,eAAe,EACtB,aAAa,UAAQ,GACpB,MAAM,CAER;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,eAAe,GACtB,OAAO,CAKT;AAED,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,eAAe,GACtB,OAAO,CAST;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,UAAU,EACnB,UAAU,EAAE,eAAe,GAC1B,MAAM,CAER;AAED;;;;;;;GAOG;AAEH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,UAAU,EACnB,UAAU,EAAE,eAAe,EAC3B,QAAQ,CAAC,EAAE,MAAM,GAChB,UAAU,CAQZ;AAED;;;;;;GAMG;AAEH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,UAAU,EACnB,UAAU,EAAE,eAAe,GAC1B,UAAU,CAOZ;AAED;;;;;;;GAOG;AAEH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,UAAU,EACnB,UAAU,EAAE,eAAe,EAC3B,WAAW,EAAE,eAAe,GAC3B,UAAU,CAOZ;AAED;;;;;;;GAOG;AAEH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,UAAU,EACnB,UAAU,EAAE,eAAe,EAC3B,QAAQ,EAAE,MAAM,GACf,UAAU,CAGZ"}
|
|
@@ -9,7 +9,9 @@ export function isLayerSame(layerA, layerB) {
|
|
|
9
9
|
return getLayerHash(layerA) === getLayerHash(layerB);
|
|
10
10
|
}
|
|
11
11
|
export function isLayerSameAndUnchanged(layerA, layerB) {
|
|
12
|
-
if ("id" in layerA &&
|
|
12
|
+
if ("id" in layerA &&
|
|
13
|
+
"id" in layerB &&
|
|
14
|
+
("version" in layerA || "version" in layerB)) {
|
|
13
15
|
return layerA.id == layerB.id && layerA.version == layerB.version;
|
|
14
16
|
}
|
|
15
17
|
return getLayerHash(layerA, true) === getLayerHash(layerB, true);
|
package/dist/utils/view.d.ts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
1
|
import { MapContextLayer, MapContextView } from "../model/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a view from a layer by extracting its geographic extent. The returned extent is
|
|
4
|
+
* always expressed in EPSG:4326 (longitude/latitude) coordinates.
|
|
5
|
+
*
|
|
6
|
+
* @param layer - The map context layer to extract the extent from
|
|
7
|
+
* @returns A Promise resolving to a `ViewByExtent` object, or `null` if the extent cannot be determined
|
|
8
|
+
* @throws {Error} If the layer type is not supported
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const wmsLayer: MapContextLayerWms = {
|
|
13
|
+
* type: 'wms',
|
|
14
|
+
* url: 'https://example.com/wms',
|
|
15
|
+
* name: 'myLayer'
|
|
16
|
+
* };
|
|
17
|
+
*
|
|
18
|
+
* const view = await createViewFromLayer(wmsLayer);
|
|
19
|
+
* if (view) {
|
|
20
|
+
* console.log('Extent:', view.extent); // [minX, minY, maxX, maxY] in EPSG:4326
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
2
24
|
export declare function createViewFromLayer(layer: MapContextLayer): Promise<MapContextView | null>;
|
|
3
25
|
//# sourceMappingURL=view.d.ts.map
|
package/dist/utils/view.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../lib/utils/view.ts"],"names":[],"mappings":"AAQA,OAAO,EAEL,eAAe,EAIf,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAK3B,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,eAAe,GACrB,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAYhC"}
|
|
1
|
+
{"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../lib/utils/view.ts"],"names":[],"mappings":"AAQA,OAAO,EAEL,eAAe,EAIf,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAK3B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,eAAe,GACrB,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAYhC"}
|
package/dist/utils/view.js
CHANGED
|
@@ -6,6 +6,28 @@ import GeoJSON from "ol/format/GeoJSON.js";
|
|
|
6
6
|
import { extend } from "ol/extent.js";
|
|
7
7
|
import proj4 from "proj4";
|
|
8
8
|
const GEOJSON = new GeoJSON();
|
|
9
|
+
/**
|
|
10
|
+
* Creates a view from a layer by extracting its geographic extent. The returned extent is
|
|
11
|
+
* always expressed in EPSG:4326 (longitude/latitude) coordinates.
|
|
12
|
+
*
|
|
13
|
+
* @param layer - The map context layer to extract the extent from
|
|
14
|
+
* @returns A Promise resolving to a `ViewByExtent` object, or `null` if the extent cannot be determined
|
|
15
|
+
* @throws {Error} If the layer type is not supported
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const wmsLayer: MapContextLayerWms = {
|
|
20
|
+
* type: 'wms',
|
|
21
|
+
* url: 'https://example.com/wms',
|
|
22
|
+
* name: 'myLayer'
|
|
23
|
+
* };
|
|
24
|
+
*
|
|
25
|
+
* const view = await createViewFromLayer(wmsLayer);
|
|
26
|
+
* if (view) {
|
|
27
|
+
* console.log('Extent:', view.extent); // [minX, minY, maxX, maxY] in EPSG:4326
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
9
31
|
export async function createViewFromLayer(layer) {
|
|
10
32
|
if (layer.type === "wms") {
|
|
11
33
|
return await getWmsLayerExtent(layer);
|
package/lib/index.ts
CHANGED
package/lib/model/index.ts
CHANGED
|
@@ -33,5 +33,5 @@ export interface MapContextDiff {
|
|
|
33
33
|
layersReordered: MapContextLayerReordered[];
|
|
34
34
|
layersRemoved: MapContextLayerPositioned[];
|
|
35
35
|
layersAdded: MapContextLayerPositioned[];
|
|
36
|
-
viewChanges?: MapContextView | null;
|
|
36
|
+
viewChanges?: MapContextView | null; // this is both optional (meaning no view change) and nullable (meaning reset to default view)
|
|
37
37
|
}
|
package/lib/model/map-context.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { FeatureCollection, Geometry } from "geojson";
|
|
2
2
|
import { VectorStyle } from "./style.js";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @private
|
|
6
|
+
* @inline
|
|
7
|
+
*/
|
|
4
8
|
export type LayerDimensions = Record<string, string>;
|
|
5
9
|
|
|
10
|
+
/**
|
|
11
|
+
* @private
|
|
12
|
+
* @inline
|
|
13
|
+
*/
|
|
6
14
|
export type LayerExtras = Record<string, unknown>;
|
|
7
15
|
|
|
8
16
|
export interface MapContextBaseLayer {
|
|
@@ -79,14 +87,10 @@ export interface LayerGeojsonWithData extends LayerGeojson {
|
|
|
79
87
|
data: FeatureCollection<Geometry | null> | string;
|
|
80
88
|
url?: never;
|
|
81
89
|
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @interface
|
|
85
|
-
*/
|
|
86
90
|
export type MapContextLayerGeojson = LayerGeojsonWithUrl | LayerGeojsonWithData;
|
|
87
91
|
|
|
88
92
|
/**
|
|
89
|
-
*
|
|
93
|
+
* A layer that can be used in a map context.
|
|
90
94
|
*/
|
|
91
95
|
export type MapContextLayer =
|
|
92
96
|
| MapContextLayerWms
|
|
@@ -100,7 +104,7 @@ export type MapContextLayer =
|
|
|
100
104
|
export type Coordinate = [number, number];
|
|
101
105
|
|
|
102
106
|
/**
|
|
103
|
-
*
|
|
107
|
+
* Array components are respectively: minX, minY, maxX, maxY
|
|
104
108
|
*/
|
|
105
109
|
export type Extent = [number, number, number, number];
|
|
106
110
|
|
|
@@ -121,12 +125,20 @@ export interface ViewByExtent {
|
|
|
121
125
|
}
|
|
122
126
|
|
|
123
127
|
/**
|
|
124
|
-
* @property geometry Expressed in
|
|
128
|
+
* @property geometry Expressed in GeoJSON
|
|
125
129
|
*/
|
|
126
130
|
export interface ViewByGeometry {
|
|
127
131
|
geometry: Geometry;
|
|
128
132
|
}
|
|
129
133
|
|
|
134
|
+
/**
|
|
135
|
+
* A description of a map viewport in one of three ways:
|
|
136
|
+
* * by center and zoom level,
|
|
137
|
+
* * by extent,
|
|
138
|
+
* * by geometry (in GeoJSON)
|
|
139
|
+
*
|
|
140
|
+
* Also allows specifying constraints for zoom and extent.
|
|
141
|
+
*/
|
|
130
142
|
export type MapContextView = (
|
|
131
143
|
| ViewByZoomAndCenter
|
|
132
144
|
| ViewByExtent
|
|
@@ -136,7 +148,12 @@ export type MapContextView = (
|
|
|
136
148
|
maxExtent?: Extent;
|
|
137
149
|
};
|
|
138
150
|
|
|
151
|
+
/**
|
|
152
|
+
* A map context, containing layers and a view.
|
|
153
|
+
*
|
|
154
|
+
* Note: setting the `view` property to `null` indicates that the map should use a default global view.
|
|
155
|
+
*/
|
|
139
156
|
export interface MapContext {
|
|
140
157
|
layers: MapContextLayer[];
|
|
141
|
-
view: MapContextView | null;
|
|
158
|
+
view: MapContextView | null;
|
|
142
159
|
}
|
package/lib/utils/index.ts
CHANGED
|
@@ -99,8 +99,30 @@ describe("Map context utils", () => {
|
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
describe("isLayerSameAndUnchanged", () => {
|
|
102
|
-
describe("layers with id", () => {
|
|
102
|
+
describe("layers with id and version", () => {
|
|
103
103
|
it("compares non-strictly by id and version field", () => {
|
|
104
|
+
expect(
|
|
105
|
+
isLayerSameAndUnchanged(
|
|
106
|
+
{ ...SAMPLE_LAYER1, id: "ab", version: 2 },
|
|
107
|
+
{ ...SAMPLE_LAYER2, id: "ab", version: 2 },
|
|
108
|
+
),
|
|
109
|
+
).toBe(true);
|
|
110
|
+
expect(
|
|
111
|
+
isLayerSameAndUnchanged(
|
|
112
|
+
{ ...SAMPLE_LAYER1, id: "ab", version: 2 },
|
|
113
|
+
{ ...SAMPLE_LAYER1, id: "ab", version: 1 },
|
|
114
|
+
),
|
|
115
|
+
).toBe(false);
|
|
116
|
+
expect(
|
|
117
|
+
isLayerSameAndUnchanged(
|
|
118
|
+
{ ...SAMPLE_LAYER1, id: 1 },
|
|
119
|
+
{ ...SAMPLE_LAYER1, id: "01", version: 3 },
|
|
120
|
+
),
|
|
121
|
+
).toBe(false);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
describe("layers with id and both without version", () => {
|
|
125
|
+
it("compares by properties, including extras", () => {
|
|
104
126
|
expect(
|
|
105
127
|
isLayerSameAndUnchanged(
|
|
106
128
|
{ ...SAMPLE_LAYER1, id: "a" },
|
|
@@ -112,23 +134,23 @@ describe("Map context utils", () => {
|
|
|
112
134
|
{ ...SAMPLE_LAYER1, id: "a" },
|
|
113
135
|
{ ...SAMPLE_LAYER2, id: "a" },
|
|
114
136
|
),
|
|
115
|
-
).toBe(
|
|
137
|
+
).toBe(false);
|
|
116
138
|
expect(
|
|
117
139
|
isLayerSameAndUnchanged(
|
|
118
|
-
{ ...SAMPLE_LAYER1, id: "
|
|
119
|
-
{ ...
|
|
140
|
+
{ ...SAMPLE_LAYER1, id: "a" },
|
|
141
|
+
{ ...SAMPLE_LAYER1, id: "a" },
|
|
120
142
|
),
|
|
121
143
|
).toBe(true);
|
|
122
144
|
expect(
|
|
123
145
|
isLayerSameAndUnchanged(
|
|
124
|
-
{ ...
|
|
125
|
-
{ ...
|
|
146
|
+
{ ...SAMPLE_LAYER2, id: "b", extras: { hello: "world" } },
|
|
147
|
+
{ ...SAMPLE_LAYER2, id: "b", extras: { hello: "world" } },
|
|
126
148
|
),
|
|
127
|
-
).toBe(
|
|
149
|
+
).toBe(true);
|
|
128
150
|
expect(
|
|
129
151
|
isLayerSameAndUnchanged(
|
|
130
|
-
{ ...
|
|
131
|
-
{ ...
|
|
152
|
+
{ ...SAMPLE_LAYER2, id: "b", extras: { hello: "world" } },
|
|
153
|
+
{ ...SAMPLE_LAYER2, id: "b", extras: { foo: "bar" } },
|
|
132
154
|
),
|
|
133
155
|
).toBe(false);
|
|
134
156
|
});
|
package/lib/utils/map-context.ts
CHANGED
|
@@ -22,7 +22,11 @@ export function isLayerSameAndUnchanged(
|
|
|
22
22
|
layerA: MapContextLayer,
|
|
23
23
|
layerB: MapContextLayer,
|
|
24
24
|
): boolean {
|
|
25
|
-
if (
|
|
25
|
+
if (
|
|
26
|
+
"id" in layerA &&
|
|
27
|
+
"id" in layerB &&
|
|
28
|
+
("version" in layerA || "version" in layerB)
|
|
29
|
+
) {
|
|
26
30
|
return layerA.id == layerB.id && layerA.version == layerB.version;
|
|
27
31
|
}
|
|
28
32
|
return getLayerHash(layerA, true) === getLayerHash(layerB, true);
|
package/lib/utils/view.ts
CHANGED
|
@@ -19,6 +19,28 @@ import { FeatureCollection, Geometry } from "geojson";
|
|
|
19
19
|
|
|
20
20
|
const GEOJSON = new GeoJSON();
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Creates a view from a layer by extracting its geographic extent. The returned extent is
|
|
24
|
+
* always expressed in EPSG:4326 (longitude/latitude) coordinates.
|
|
25
|
+
*
|
|
26
|
+
* @param layer - The map context layer to extract the extent from
|
|
27
|
+
* @returns A Promise resolving to a `ViewByExtent` object, or `null` if the extent cannot be determined
|
|
28
|
+
* @throws {Error} If the layer type is not supported
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const wmsLayer: MapContextLayerWms = {
|
|
33
|
+
* type: 'wms',
|
|
34
|
+
* url: 'https://example.com/wms',
|
|
35
|
+
* name: 'myLayer'
|
|
36
|
+
* };
|
|
37
|
+
*
|
|
38
|
+
* const view = await createViewFromLayer(wmsLayer);
|
|
39
|
+
* if (view) {
|
|
40
|
+
* console.log('Extent:', view.extent); // [minX, minY, maxX, maxY] in EPSG:4326
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
22
44
|
export async function createViewFromLayer(
|
|
23
45
|
layer: MapContextLayer,
|
|
24
46
|
): Promise<MapContextView | null> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geospatial-sdk/core",
|
|
3
|
-
"version": "0.0.5-dev.
|
|
3
|
+
"version": "0.0.5-dev.45+a90fe28",
|
|
4
4
|
"description": "Core functions and models for the SDK",
|
|
5
5
|
"author": "Olivia <olivia.guyot@camptocamp.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"test": "vitest",
|
|
23
23
|
"build": "tsc"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "a90fe28ac749e1d35a976bdcfd02cb47357e8955",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"proj4": "^2.9.2"
|
|
28
28
|
},
|