@geospatial-sdk/core 0.0.5-dev.46 → 0.0.5-dev.48
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/model/map-context-diff.d.ts +9 -1
- package/dist/model/map-context-diff.d.ts.map +1 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/map-context-diff.d.ts.map +1 -1
- package/dist/utils/map-context-diff.js +2 -2
- package/dist/utils/map-context-layer.d.ts +13 -0
- package/dist/utils/map-context-layer.d.ts.map +1 -0
- package/dist/utils/map-context-layer.js +44 -0
- package/dist/utils/map-context.d.ts +27 -18
- package/dist/utils/map-context.d.ts.map +1 -1
- package/dist/utils/map-context.js +38 -33
- package/lib/model/map-context-diff.ts +10 -1
- package/lib/utils/index.ts +2 -0
- package/lib/utils/map-context-diff.test.ts +3 -0
- package/lib/utils/map-context-diff.ts +4 -3
- package/lib/utils/map-context-layer.test.ts +357 -0
- package/lib/utils/map-context-layer.ts +66 -0
- package/lib/utils/map-context.test.ts +76 -305
- package/lib/utils/map-context.ts +44 -47
- package/package.json +2 -2
|
@@ -15,6 +15,14 @@ export interface MapContextLayerReordered {
|
|
|
15
15
|
newPosition: number;
|
|
16
16
|
previousPosition: number;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Describes a layer that was changed: both states before and after change are included
|
|
20
|
+
*/
|
|
21
|
+
export interface MapContextLayerChanged {
|
|
22
|
+
layer: MapContextLayer;
|
|
23
|
+
previousLayer: MapContextLayer;
|
|
24
|
+
position: number;
|
|
25
|
+
}
|
|
18
26
|
/**
|
|
19
27
|
* Describes a delta between two contexts, in order to be
|
|
20
28
|
* applied to an existing map.
|
|
@@ -26,7 +34,7 @@ export interface MapContextLayerReordered {
|
|
|
26
34
|
* 4. change layers
|
|
27
35
|
*/
|
|
28
36
|
export interface MapContextDiff {
|
|
29
|
-
layersChanged:
|
|
37
|
+
layersChanged: MapContextLayerChanged[];
|
|
30
38
|
layersReordered: MapContextLayerReordered[];
|
|
31
39
|
layersRemoved: MapContextLayerPositioned[];
|
|
32
40
|
layersAdded: MapContextLayerPositioned[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-context-diff.d.ts","sourceRoot":"","sources":["../../lib/model/map-context-diff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEnE;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,eAAe,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"map-context-diff.d.ts","sourceRoot":"","sources":["../../lib/model/map-context-diff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEnE;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,eAAe,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,eAAe,CAAC;IACvB,aAAa,EAAE,eAAe,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,sBAAsB,EAAE,CAAC;IACxC,eAAe,EAAE,wBAAwB,EAAE,CAAC;IAC5C,aAAa,EAAE,yBAAyB,EAAE,CAAC;IAC3C,WAAW,EAAE,yBAAyB,EAAE,CAAC;IACzC,WAAW,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;CACrC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./url.js";
|
|
|
6
6
|
export * from "./freeze.js";
|
|
7
7
|
export * from "./hash.js";
|
|
8
8
|
export { computeMapContextDiff } from "./map-context-diff.js";
|
|
9
|
-
export { getLayerPosition, addLayerToContext, removeLayerFromContext, replaceLayerInContext, changeLayerPositionInContext, } from "./map-context.js";
|
|
9
|
+
export { getLayerPosition, addLayerToContext, removeLayerFromContext, replaceLayerInContext, changeLayerPositionInContext, updateLayerInContext, } from "./map-context.js";
|
|
10
|
+
export { updateLayer } from "./map-context-layer.js";
|
|
10
11
|
export { createViewFromLayer } from "./view.js";
|
|
11
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,EAC5B,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -6,5 +6,6 @@ export * from "./url.js";
|
|
|
6
6
|
export * from "./freeze.js";
|
|
7
7
|
export * from "./hash.js";
|
|
8
8
|
export { computeMapContextDiff } from "./map-context-diff.js";
|
|
9
|
-
export { getLayerPosition, addLayerToContext, removeLayerFromContext, replaceLayerInContext, changeLayerPositionInContext, } from "./map-context.js";
|
|
9
|
+
export { getLayerPosition, addLayerToContext, removeLayerFromContext, replaceLayerInContext, changeLayerPositionInContext, updateLayerInContext, } from "./map-context.js";
|
|
10
|
+
export { updateLayer } from "./map-context-layer.js";
|
|
10
11
|
export { createViewFromLayer } from "./view.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-context-diff.d.ts","sourceRoot":"","sources":["../../lib/utils/map-context-diff.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,cAAc,
|
|
1
|
+
{"version":3,"file":"map-context-diff.d.ts","sourceRoot":"","sources":["../../lib/utils/map-context-diff.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,cAAc,EAKf,MAAM,mBAAmB,CAAC;AAG3B;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,UAAU,EACvB,eAAe,EAAE,UAAU,GAC1B,cAAc,CA0EhB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isLayerSame, isLayerSameAndUnchanged } from "./map-context.js";
|
|
1
|
+
import { isLayerSame, isLayerSameAndUnchanged } from "./map-context-layer.js";
|
|
2
2
|
/**
|
|
3
3
|
* The following logic is produced by identifying layers in both context
|
|
4
4
|
* and determining whether they have been added, removed, changed or reordered.
|
|
@@ -50,7 +50,7 @@ export function computeMapContextDiff(nextContext, previousContext) {
|
|
|
50
50
|
else {
|
|
51
51
|
const prevLayer = previousContext.layers[prevPosition];
|
|
52
52
|
if (!isLayerSameAndUnchanged(layer, prevLayer)) {
|
|
53
|
-
layersChanged.push({ layer, position: i });
|
|
53
|
+
layersChanged.push({ layer, previousLayer: prevLayer, position: i });
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MapContextLayer } from "../model/index.js";
|
|
2
|
+
export declare function getLayerHash(layer: MapContextLayer, includeExtras?: boolean): string;
|
|
3
|
+
export declare function isLayerSame(layerA: MapContextLayer, layerB: MapContextLayer): boolean;
|
|
4
|
+
export declare function isLayerSameAndUnchanged(layerA: MapContextLayer, layerB: MapContextLayer): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Applies the `updates` partial to the given layer. The layer will also be
|
|
7
|
+
* adjusted depending on the presence of the `id` and `version` fields.
|
|
8
|
+
* Note: any property set to `undefined` in `updates` will be removed from the resulting layer.
|
|
9
|
+
* @param layer
|
|
10
|
+
* @param updates
|
|
11
|
+
*/
|
|
12
|
+
export declare function updateLayer(layer: MapContextLayer, updates: Partial<MapContextLayer>): MapContextLayer;
|
|
13
|
+
//# sourceMappingURL=map-context-layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-context-layer.d.ts","sourceRoot":"","sources":["../../lib/utils/map-context-layer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,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;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,eAAe,EACtB,OAAO,EAAE,OAAO,CAAC,eAAe,CAAC,GAChC,eAAe,CAqBjB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { getHash } from "./hash.js";
|
|
2
|
+
export function getLayerHash(layer, includeExtras = false) {
|
|
3
|
+
return getHash(layer, includeExtras ? [] : ["extras"]);
|
|
4
|
+
}
|
|
5
|
+
export function isLayerSame(layerA, layerB) {
|
|
6
|
+
if ("id" in layerA && "id" in layerB) {
|
|
7
|
+
return layerA.id == layerB.id;
|
|
8
|
+
}
|
|
9
|
+
return getLayerHash(layerA) === getLayerHash(layerB);
|
|
10
|
+
}
|
|
11
|
+
export function isLayerSameAndUnchanged(layerA, layerB) {
|
|
12
|
+
if ("id" in layerA &&
|
|
13
|
+
"id" in layerB &&
|
|
14
|
+
("version" in layerA || "version" in layerB)) {
|
|
15
|
+
return layerA.id == layerB.id && layerA.version == layerB.version;
|
|
16
|
+
}
|
|
17
|
+
return getLayerHash(layerA, true) === getLayerHash(layerB, true);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Applies the `updates` partial to the given layer. The layer will also be
|
|
21
|
+
* adjusted depending on the presence of the `id` and `version` fields.
|
|
22
|
+
* Note: any property set to `undefined` in `updates` will be removed from the resulting layer.
|
|
23
|
+
* @param layer
|
|
24
|
+
* @param updates
|
|
25
|
+
*/
|
|
26
|
+
export function updateLayer(layer, updates) {
|
|
27
|
+
const updatedLayer = {
|
|
28
|
+
...layer,
|
|
29
|
+
...updates,
|
|
30
|
+
};
|
|
31
|
+
const versionExplicitlyUpdated = "version" in updates && updates.version !== undefined;
|
|
32
|
+
if ("id" in updatedLayer &&
|
|
33
|
+
"version" in updatedLayer &&
|
|
34
|
+
typeof updatedLayer.version === "number" &&
|
|
35
|
+
!versionExplicitlyUpdated) {
|
|
36
|
+
updatedLayer.version = updatedLayer.version + 1;
|
|
37
|
+
}
|
|
38
|
+
for (const key in updatedLayer) {
|
|
39
|
+
if (updatedLayer[key] === undefined) {
|
|
40
|
+
delete updatedLayer[key];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return updatedLayer;
|
|
44
|
+
}
|
|
@@ -1,41 +1,50 @@
|
|
|
1
1
|
import { MapContext, MapContextLayer } from "../model/index.js";
|
|
2
|
-
export declare function getLayerHash(layer: MapContextLayer, includeExtras?: boolean): string;
|
|
3
|
-
export declare function isLayerSame(layerA: MapContextLayer, layerB: MapContextLayer): boolean;
|
|
4
|
-
export declare function isLayerSameAndUnchanged(layerA: MapContextLayer, layerB: MapContextLayer): boolean;
|
|
5
2
|
export declare function getLayerPosition(context: MapContext, layerModel: MapContextLayer): number;
|
|
6
3
|
/**
|
|
7
4
|
* Adds a layer to the context at a specific position or at the end if no position is specified.
|
|
8
5
|
*
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
12
|
-
* @returns
|
|
6
|
+
* @param context The current map context.
|
|
7
|
+
* @param layerModel The layer to be added.
|
|
8
|
+
* @param [position] The position at which to add the layer. If not specified, the layer is added at the end.
|
|
9
|
+
* @returns The new map context with the added layer.
|
|
13
10
|
*/
|
|
14
11
|
export declare function addLayerToContext(context: MapContext, layerModel: MapContextLayer, position?: number): MapContext;
|
|
15
12
|
/**
|
|
16
13
|
* Removes a layer from the context.
|
|
17
14
|
*
|
|
18
|
-
* @param
|
|
19
|
-
* @param
|
|
20
|
-
* @returns
|
|
15
|
+
* @param context The current map context.
|
|
16
|
+
* @param layerModel The layer to be removed.
|
|
17
|
+
* @returns The new map context without the removed layer.
|
|
21
18
|
*/
|
|
22
19
|
export declare function removeLayerFromContext(context: MapContext, layerModel: MapContextLayer): MapContext;
|
|
23
20
|
/**
|
|
24
21
|
* Replaces a layer in the context with a new layer.
|
|
25
22
|
*
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
29
|
-
* @returns
|
|
23
|
+
* @param context The current map context.
|
|
24
|
+
* @param layerModel The layer to be replaced.
|
|
25
|
+
* @param replacement The new layer that will replace the old one.
|
|
26
|
+
* @returns The new map context with the replaced layer.
|
|
30
27
|
*/
|
|
31
28
|
export declare function replaceLayerInContext(context: MapContext, layerModel: MapContextLayer, replacement: MapContextLayer): MapContext;
|
|
29
|
+
/**
|
|
30
|
+
* Updates an existing layer in the context by applying partial changes.
|
|
31
|
+
*
|
|
32
|
+
* Note: setting a property to `undefined` in the partial layer updates will remove that
|
|
33
|
+
* property from the existing layer.
|
|
34
|
+
*
|
|
35
|
+
* @param context The current map context.
|
|
36
|
+
* @param layerModel The layer to be updated.
|
|
37
|
+
* @param layerUpdates A partial layer object containing the properties to update on the existing layer.
|
|
38
|
+
* @returns The new map context with the updated layer.
|
|
39
|
+
*/
|
|
40
|
+
export declare function updateLayerInContext(context: MapContext, layerModel: MapContextLayer, layerUpdates: Partial<MapContextLayer>): MapContext;
|
|
32
41
|
/**
|
|
33
42
|
* Changes the position of a layer in the context.
|
|
34
43
|
*
|
|
35
|
-
* @param
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
38
|
-
* @returns
|
|
44
|
+
* @param context The current map context.
|
|
45
|
+
* @param layerModel The layer whose position is to be changed.
|
|
46
|
+
* @param position The new position for the layer.
|
|
47
|
+
* @returns The new map context with the layer moved to the new position.
|
|
39
48
|
*/
|
|
40
49
|
export declare function changeLayerPositionInContext(context: MapContext, layerModel: MapContextLayer, position: number): MapContext;
|
|
41
50
|
//# sourceMappingURL=map-context.d.ts.map
|
|
@@ -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,
|
|
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,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;;;;;;;;;;GAUG;AAEH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,UAAU,EACnB,UAAU,EAAE,eAAe,EAC3B,YAAY,EAAE,OAAO,CAAC,eAAe,CAAC,GACrC,UAAU,CAUZ;AAED;;;;;;;GAOG;AAEH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,UAAU,EACnB,UAAU,EAAE,eAAe,EAC3B,QAAQ,EAAE,MAAM,GACf,UAAU,CAGZ"}
|
|
@@ -1,31 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export function getLayerHash(layer, includeExtras = false) {
|
|
3
|
-
return getHash(layer, includeExtras ? [] : ["extras"]);
|
|
4
|
-
}
|
|
5
|
-
export function isLayerSame(layerA, layerB) {
|
|
6
|
-
if ("id" in layerA && "id" in layerB) {
|
|
7
|
-
return layerA.id == layerB.id;
|
|
8
|
-
}
|
|
9
|
-
return getLayerHash(layerA) === getLayerHash(layerB);
|
|
10
|
-
}
|
|
11
|
-
export function isLayerSameAndUnchanged(layerA, layerB) {
|
|
12
|
-
if ("id" in layerA &&
|
|
13
|
-
"id" in layerB &&
|
|
14
|
-
("version" in layerA || "version" in layerB)) {
|
|
15
|
-
return layerA.id == layerB.id && layerA.version == layerB.version;
|
|
16
|
-
}
|
|
17
|
-
return getLayerHash(layerA, true) === getLayerHash(layerB, true);
|
|
18
|
-
}
|
|
1
|
+
import { isLayerSame, updateLayer } from "./map-context-layer.js";
|
|
19
2
|
export function getLayerPosition(context, layerModel) {
|
|
20
3
|
return context.layers.findIndex((l) => isLayerSame(layerModel, l));
|
|
21
4
|
}
|
|
22
5
|
/**
|
|
23
6
|
* Adds a layer to the context at a specific position or at the end if no position is specified.
|
|
24
7
|
*
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
28
|
-
* @returns
|
|
8
|
+
* @param context The current map context.
|
|
9
|
+
* @param layerModel The layer to be added.
|
|
10
|
+
* @param [position] The position at which to add the layer. If not specified, the layer is added at the end.
|
|
11
|
+
* @returns The new map context with the added layer.
|
|
29
12
|
*/
|
|
30
13
|
export function addLayerToContext(context, layerModel, position) {
|
|
31
14
|
const newContext = { ...context, layers: [...context.layers] };
|
|
@@ -40,9 +23,9 @@ export function addLayerToContext(context, layerModel, position) {
|
|
|
40
23
|
/**
|
|
41
24
|
* Removes a layer from the context.
|
|
42
25
|
*
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
45
|
-
* @returns
|
|
26
|
+
* @param context The current map context.
|
|
27
|
+
* @param layerModel The layer to be removed.
|
|
28
|
+
* @returns The new map context without the removed layer.
|
|
46
29
|
*/
|
|
47
30
|
export function removeLayerFromContext(context, layerModel) {
|
|
48
31
|
const newContext = { ...context, layers: [...context.layers] };
|
|
@@ -55,10 +38,10 @@ export function removeLayerFromContext(context, layerModel) {
|
|
|
55
38
|
/**
|
|
56
39
|
* Replaces a layer in the context with a new layer.
|
|
57
40
|
*
|
|
58
|
-
* @param
|
|
59
|
-
* @param
|
|
60
|
-
* @param
|
|
61
|
-
* @returns
|
|
41
|
+
* @param context The current map context.
|
|
42
|
+
* @param layerModel The layer to be replaced.
|
|
43
|
+
* @param replacement The new layer that will replace the old one.
|
|
44
|
+
* @returns The new map context with the replaced layer.
|
|
62
45
|
*/
|
|
63
46
|
export function replaceLayerInContext(context, layerModel, replacement) {
|
|
64
47
|
const newContext = { ...context, layers: [...context.layers] };
|
|
@@ -68,13 +51,35 @@ export function replaceLayerInContext(context, layerModel, replacement) {
|
|
|
68
51
|
}
|
|
69
52
|
return newContext;
|
|
70
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Updates an existing layer in the context by applying partial changes.
|
|
56
|
+
*
|
|
57
|
+
* Note: setting a property to `undefined` in the partial layer updates will remove that
|
|
58
|
+
* property from the existing layer.
|
|
59
|
+
*
|
|
60
|
+
* @param context The current map context.
|
|
61
|
+
* @param layerModel The layer to be updated.
|
|
62
|
+
* @param layerUpdates A partial layer object containing the properties to update on the existing layer.
|
|
63
|
+
* @returns The new map context with the updated layer.
|
|
64
|
+
*/
|
|
65
|
+
export function updateLayerInContext(context, layerModel, layerUpdates) {
|
|
66
|
+
const position = getLayerPosition(context, layerModel);
|
|
67
|
+
if (position >= 0) {
|
|
68
|
+
const existing = context.layers[position];
|
|
69
|
+
const updated = updateLayer(existing, layerUpdates);
|
|
70
|
+
return replaceLayerInContext(context, layerModel, updated);
|
|
71
|
+
}
|
|
72
|
+
// we're building a new context so that the reference is changed anyway; this is done to be
|
|
73
|
+
// consistent with other utilities that always change the context reference even if the layer wasn't found
|
|
74
|
+
return { ...context };
|
|
75
|
+
}
|
|
71
76
|
/**
|
|
72
77
|
* Changes the position of a layer in the context.
|
|
73
78
|
*
|
|
74
|
-
* @param
|
|
75
|
-
* @param
|
|
76
|
-
* @param
|
|
77
|
-
* @returns
|
|
79
|
+
* @param context The current map context.
|
|
80
|
+
* @param layerModel The layer whose position is to be changed.
|
|
81
|
+
* @param position The new position for the layer.
|
|
82
|
+
* @returns The new map context with the layer moved to the new position.
|
|
78
83
|
*/
|
|
79
84
|
export function changeLayerPositionInContext(context, layerModel, position) {
|
|
80
85
|
const newContext = removeLayerFromContext(context, layerModel);
|
|
@@ -18,6 +18,15 @@ export interface MapContextLayerReordered {
|
|
|
18
18
|
previousPosition: number;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Describes a layer that was changed: both states before and after change are included
|
|
23
|
+
*/
|
|
24
|
+
export interface MapContextLayerChanged {
|
|
25
|
+
layer: MapContextLayer;
|
|
26
|
+
previousLayer: MapContextLayer;
|
|
27
|
+
position: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
21
30
|
/**
|
|
22
31
|
* Describes a delta between two contexts, in order to be
|
|
23
32
|
* applied to an existing map.
|
|
@@ -29,7 +38,7 @@ export interface MapContextLayerReordered {
|
|
|
29
38
|
* 4. change layers
|
|
30
39
|
*/
|
|
31
40
|
export interface MapContextDiff {
|
|
32
|
-
layersChanged:
|
|
41
|
+
layersChanged: MapContextLayerChanged[];
|
|
33
42
|
layersReordered: MapContextLayerReordered[];
|
|
34
43
|
layersRemoved: MapContextLayerPositioned[];
|
|
35
44
|
layersAdded: MapContextLayerPositioned[];
|
package/lib/utils/index.ts
CHANGED
|
@@ -121,10 +121,12 @@ describe("Context diff utils", () => {
|
|
|
121
121
|
layersChanged: [
|
|
122
122
|
{
|
|
123
123
|
layer: contextNew.layers[0],
|
|
124
|
+
previousLayer: contextOld.layers[0],
|
|
124
125
|
position: 0,
|
|
125
126
|
},
|
|
126
127
|
{
|
|
127
128
|
layer: contextNew.layers[1],
|
|
129
|
+
previousLayer: contextOld.layers[1],
|
|
128
130
|
position: 1,
|
|
129
131
|
},
|
|
130
132
|
],
|
|
@@ -356,6 +358,7 @@ describe("Context diff utils", () => {
|
|
|
356
358
|
layersChanged: [
|
|
357
359
|
{
|
|
358
360
|
layer: changedLayer,
|
|
361
|
+
previousLayer: SAMPLE_LAYER3,
|
|
359
362
|
position: 1,
|
|
360
363
|
},
|
|
361
364
|
],
|
|
@@ -2,10 +2,11 @@ import {
|
|
|
2
2
|
MapContext,
|
|
3
3
|
MapContextDiff,
|
|
4
4
|
MapContextLayer,
|
|
5
|
+
MapContextLayerChanged,
|
|
5
6
|
MapContextLayerPositioned,
|
|
6
7
|
MapContextLayerReordered,
|
|
7
8
|
} from "../model/index.js";
|
|
8
|
-
import { isLayerSame, isLayerSameAndUnchanged } from "./map-context.js";
|
|
9
|
+
import { isLayerSame, isLayerSameAndUnchanged } from "./map-context-layer.js";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* The following logic is produced by identifying layers in both context
|
|
@@ -42,7 +43,7 @@ export function computeMapContextDiff(
|
|
|
42
43
|
return -1;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
const layersChanged:
|
|
46
|
+
const layersChanged: MapContextLayerChanged[] = [];
|
|
46
47
|
const layersReordered: MapContextLayerReordered[] = [];
|
|
47
48
|
const layersRemoved: MapContextLayerPositioned[] = [];
|
|
48
49
|
const layersAdded: MapContextLayerPositioned[] = [];
|
|
@@ -66,7 +67,7 @@ export function computeMapContextDiff(
|
|
|
66
67
|
} else {
|
|
67
68
|
const prevLayer = previousContext.layers[prevPosition];
|
|
68
69
|
if (!isLayerSameAndUnchanged(layer, prevLayer)) {
|
|
69
|
-
layersChanged.push({ layer, position: i });
|
|
70
|
+
layersChanged.push({ layer, previousLayer: prevLayer, position: i });
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
}
|