@geospatial-sdk/core 0.0.5-alpha.1 → 0.0.5-alpha.2
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/fixtures/geojson.fixtures.d.ts +4 -0
- package/dist/fixtures/geojson.fixtures.d.ts.map +1 -0
- package/dist/fixtures/geojson.fixtures.js +55121 -0
- package/dist/fixtures/map-context.fixtures.d.ts +16 -0
- package/dist/fixtures/map-context.fixtures.d.ts.map +1 -0
- package/dist/fixtures/map-context.fixtures.js +73 -0
- package/dist/lib/index.d.ts +3 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +3 -0
- package/dist/lib/model/index.d.ts +3 -0
- package/dist/lib/model/index.d.ts.map +1 -0
- package/dist/lib/model/index.js +2 -0
- package/dist/lib/model/map-context-diff.d.ts +35 -0
- package/dist/lib/model/map-context-diff.d.ts.map +1 -0
- package/dist/lib/model/map-context-diff.js +1 -0
- package/dist/lib/model/map-context.d.ts +78 -0
- package/dist/lib/model/map-context.d.ts.map +1 -0
- package/dist/lib/model/map-context.js +1 -0
- package/dist/lib/utils/freeze.d.ts +2 -0
- package/dist/lib/utils/freeze.d.ts.map +1 -0
- package/dist/lib/utils/freeze.js +15 -0
- package/dist/lib/utils/freeze.test.d.ts +2 -0
- package/dist/lib/utils/freeze.test.d.ts.map +1 -0
- package/dist/lib/utils/freeze.test.js +51 -0
- package/dist/lib/utils/index.d.ts +5 -0
- package/dist/lib/utils/index.d.ts.map +1 -0
- package/dist/lib/utils/index.js +4 -0
- package/dist/lib/utils/map-context-diff.d.ts +22 -0
- package/dist/lib/utils/map-context-diff.d.ts.map +1 -0
- package/dist/lib/utils/map-context-diff.js +79 -0
- package/dist/lib/utils/map-context-diff.test.d.ts +2 -0
- package/dist/lib/utils/map-context-diff.test.d.ts.map +1 -0
- package/dist/lib/utils/map-context-diff.test.js +217 -0
- package/dist/lib/utils/map-context.d.ts +6 -0
- package/dist/lib/utils/map-context.d.ts.map +1 -0
- package/dist/lib/utils/map-context.js +36 -0
- package/dist/lib/utils/map-context.test.d.ts +2 -0
- package/dist/lib/utils/map-context.test.d.ts.map +1 -0
- package/dist/lib/utils/map-context.test.js +131 -0
- package/dist/lib/utils/url.d.ts +7 -0
- package/dist/lib/utils/url.d.ts.map +1 -0
- package/dist/lib/utils/url.js +17 -0
- package/dist/lib/utils/url.test.d.ts +2 -0
- package/dist/lib/utils/url.test.d.ts.map +1 -0
- package/dist/lib/utils/url.test.js +8 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/map-context-diff.d.ts +1 -4
- package/dist/utils/map-context-diff.d.ts.map +1 -1
- package/dist/utils/map-context-diff.js +1 -33
- package/dist/utils/map-context-diff.test.js +1 -120
- package/dist/utils/map-context.d.ts +6 -0
- package/dist/utils/map-context.d.ts.map +1 -0
- package/dist/utils/map-context.js +36 -0
- package/dist/utils/map-context.test.d.ts +2 -0
- package/dist/utils/map-context.test.d.ts.map +1 -0
- package/dist/utils/map-context.test.js +150 -0
- package/lib/model/map-context-diff.ts +4 -4
- package/lib/utils/index.ts +1 -0
- package/lib/utils/map-context-diff.test.ts +8 -310
- package/lib/utils/map-context-diff.ts +1 -43
- package/lib/utils/map-context.test.ts +294 -0
- package/lib/utils/map-context.ts +51 -0
- package/package.json +2 -2
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Extent, MapContext, MapContextLayerGeojson, MapContextLayerWfs, MapContextLayerWms, MapContextLayerXyz, MapContextView } from "../lib/model";
|
|
2
|
+
export declare const MAP_CTX_LAYER_XYZ_FIXTURE: MapContextLayerXyz;
|
|
3
|
+
export declare const MAP_CTX_LAYER_WMS_FIXTURE: MapContextLayerWms;
|
|
4
|
+
export declare const MAP_CTX_LAYER_WFS_FIXTURE: MapContextLayerWfs;
|
|
5
|
+
export declare const MAP_CTX_LAYER_GEOJSON_FIXTURE: MapContextLayerGeojson;
|
|
6
|
+
export declare const MAP_CTX_LAYER_GEOJSON_REMOTE_FIXTURE: MapContextLayerGeojson;
|
|
7
|
+
export declare const MAP_CTX_VIEW_FIXTURE: MapContextView;
|
|
8
|
+
export declare const MAP_CTX_FIXTURE: MapContext;
|
|
9
|
+
export declare const MAP_CTX_EXTENT_FIXTURE: Extent;
|
|
10
|
+
export declare const SAMPLE_CONTEXT: MapContext;
|
|
11
|
+
export declare const SAMPLE_LAYER1: MapContextLayerWms;
|
|
12
|
+
export declare const SAMPLE_LAYER2: MapContextLayerXyz;
|
|
13
|
+
export declare const SAMPLE_LAYER3: MapContextLayerGeojson;
|
|
14
|
+
export declare const SAMPLE_LAYER4: MapContextLayerWfs;
|
|
15
|
+
export declare const SAMPLE_LAYER5: MapContextLayerXyz;
|
|
16
|
+
//# sourceMappingURL=map-context.fixtures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-context.fixtures.d.ts","sourceRoot":"","sources":["../../fixtures/map-context.fixtures.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EACN,UAAU,EAEV,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACf,MAAM,cAAc,CAAC;AAGtB,eAAO,MAAM,yBAAyB,EAAE,kBAGtC,CAAC;AACH,eAAO,MAAM,yBAAyB,EAAE,kBAItC,CAAC;AACH,eAAO,MAAM,yBAAyB,EAAE,kBAItC,CAAC;AACH,eAAO,MAAM,6BAA6B,EAAE,sBAK3C,CAAC;AACF,eAAO,MAAM,oCAAoC,EAAE,sBAI/C,CAAC;AAEL,eAAO,MAAM,oBAAoB,EAAE,cAGjC,CAAC;AAEH,eAAO,MAAM,eAAe,EAAE,UAO5B,CAAC;AAEH,eAAO,MAAM,sBAAsB,EAAE,MAEpC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,UAO3B,CAAC;AAEH,eAAO,MAAM,aAAa,EAAE,kBAK1B,CAAC;AACH,eAAO,MAAM,aAAa,EAAE,kBAI1B,CAAC;AACH,eAAO,MAAM,aAAa,EAAE,sBAI1B,CAAC;AACH,eAAO,MAAM,aAAa,EAAE,kBAK1B,CAAC;AACH,eAAO,MAAM,aAAa,EAAE,kBAG1B,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { FEATURE_COLLECTION_POLYGON_FIXTURE_4326 } from "./geojson.fixtures";
|
|
2
|
+
import { deepFreeze } from "../lib/utils";
|
|
3
|
+
export const MAP_CTX_LAYER_XYZ_FIXTURE = deepFreeze({
|
|
4
|
+
type: "xyz",
|
|
5
|
+
url: "https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png",
|
|
6
|
+
});
|
|
7
|
+
export const MAP_CTX_LAYER_WMS_FIXTURE = deepFreeze({
|
|
8
|
+
type: "wms",
|
|
9
|
+
url: "https://www.geograndest.fr/geoserver/region-grand-est/ows?REQUEST=GetCapabilities&SERVICE=WMS",
|
|
10
|
+
name: "commune_actuelle_3857",
|
|
11
|
+
});
|
|
12
|
+
export const MAP_CTX_LAYER_WFS_FIXTURE = deepFreeze({
|
|
13
|
+
type: "wfs",
|
|
14
|
+
url: "https://www.geograndest.fr/geoserver/region-grand-est/ows?REQUEST=GetCapabilities&SERVICE=WFS&VERSION=1.1.0",
|
|
15
|
+
featureType: "ms:commune_actuelle_3857",
|
|
16
|
+
});
|
|
17
|
+
export const MAP_CTX_LAYER_GEOJSON_FIXTURE = deepFreeze({
|
|
18
|
+
type: "geojson",
|
|
19
|
+
data: FEATURE_COLLECTION_POLYGON_FIXTURE_4326,
|
|
20
|
+
});
|
|
21
|
+
export const MAP_CTX_LAYER_GEOJSON_REMOTE_FIXTURE = deepFreeze({
|
|
22
|
+
type: "geojson",
|
|
23
|
+
url: "https://my.host.com/data/regions.json",
|
|
24
|
+
});
|
|
25
|
+
export const MAP_CTX_VIEW_FIXTURE = deepFreeze({
|
|
26
|
+
center: [7.75, 48.6],
|
|
27
|
+
zoom: 9,
|
|
28
|
+
});
|
|
29
|
+
export const MAP_CTX_FIXTURE = deepFreeze({
|
|
30
|
+
layers: [
|
|
31
|
+
MAP_CTX_LAYER_XYZ_FIXTURE,
|
|
32
|
+
MAP_CTX_LAYER_WMS_FIXTURE,
|
|
33
|
+
MAP_CTX_LAYER_GEOJSON_FIXTURE,
|
|
34
|
+
],
|
|
35
|
+
view: MAP_CTX_VIEW_FIXTURE,
|
|
36
|
+
});
|
|
37
|
+
export const MAP_CTX_EXTENT_FIXTURE = [
|
|
38
|
+
171083.69713494915, 6246047.945419401, 476970.39956295764, 6631079.362882684,
|
|
39
|
+
];
|
|
40
|
+
export const SAMPLE_CONTEXT = deepFreeze({
|
|
41
|
+
view: {
|
|
42
|
+
center: [10, 20],
|
|
43
|
+
zoom: 3,
|
|
44
|
+
extent: [40, 50, 60, 70],
|
|
45
|
+
},
|
|
46
|
+
layers: [],
|
|
47
|
+
});
|
|
48
|
+
export const SAMPLE_LAYER1 = deepFreeze({
|
|
49
|
+
type: "wms",
|
|
50
|
+
url: "http://abc.org/wms",
|
|
51
|
+
name: "myLayer",
|
|
52
|
+
extras: { myField: "abc" },
|
|
53
|
+
});
|
|
54
|
+
export const SAMPLE_LAYER2 = deepFreeze({
|
|
55
|
+
type: "xyz",
|
|
56
|
+
url: "http://abc.org/tiles",
|
|
57
|
+
extras: { myField2: "123" },
|
|
58
|
+
});
|
|
59
|
+
export const SAMPLE_LAYER3 = deepFreeze({
|
|
60
|
+
type: "geojson",
|
|
61
|
+
data: '{ "type": "Feature", "properties": {}}',
|
|
62
|
+
extras: { myField3: "000" },
|
|
63
|
+
});
|
|
64
|
+
export const SAMPLE_LAYER4 = deepFreeze({
|
|
65
|
+
type: "wfs",
|
|
66
|
+
url: "http://abc.org/wfs",
|
|
67
|
+
featureType: "myFeatureType",
|
|
68
|
+
extras: { myField4: "aaa" },
|
|
69
|
+
});
|
|
70
|
+
export const SAMPLE_LAYER5 = deepFreeze({
|
|
71
|
+
type: "xyz",
|
|
72
|
+
url: "http://my.tiles/server",
|
|
73
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { MapContextLayer, MapContextView } from "./map-context";
|
|
2
|
+
/**
|
|
3
|
+
* Associates a position to a layer; the position is the index of
|
|
4
|
+
* the layer in the layers array
|
|
5
|
+
*/
|
|
6
|
+
export interface MapContextLayerPositioned {
|
|
7
|
+
layer: MapContextLayer;
|
|
8
|
+
position: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Describes a layer being moved to a different position
|
|
12
|
+
*/
|
|
13
|
+
export interface MapContextLayerReordered {
|
|
14
|
+
layer: MapContextLayer;
|
|
15
|
+
newPosition: number;
|
|
16
|
+
previousPosition: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Describes a delta between two contexts, in order to be
|
|
20
|
+
* applied to an existing map.
|
|
21
|
+
*
|
|
22
|
+
* For positions to be correct the order of operations should be:
|
|
23
|
+
* 1. remove layers
|
|
24
|
+
* 2. add layers
|
|
25
|
+
* 3. move layers
|
|
26
|
+
* 4. change layers
|
|
27
|
+
*/
|
|
28
|
+
export interface MapContextDiff {
|
|
29
|
+
layersChanged: MapContextLayerPositioned[];
|
|
30
|
+
layersReordered: MapContextLayerReordered[];
|
|
31
|
+
layersRemoved: MapContextLayerPositioned[];
|
|
32
|
+
layersAdded: MapContextLayerPositioned[];
|
|
33
|
+
viewChanges: MapContextView;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=map-context-diff.d.ts.map
|
|
@@ -0,0 +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,eAAe,CAAC;AAEhE;;;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,yBAAyB,EAAE,CAAC;IAC3C,eAAe,EAAE,wBAAwB,EAAE,CAAC;IAC5C,aAAa,EAAE,yBAAyB,EAAE,CAAC;IAC3C,WAAW,EAAE,yBAAyB,EAAE,CAAC;IACzC,WAAW,EAAE,cAAc,CAAC;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { FeatureCollection, Geometry } from "geojson";
|
|
2
|
+
export type LayerDimensions = Record<string, string>;
|
|
3
|
+
export type LayerExtras = Record<string, unknown>;
|
|
4
|
+
export interface MapContextBaseLayer {
|
|
5
|
+
id?: string | number;
|
|
6
|
+
version?: number;
|
|
7
|
+
/**
|
|
8
|
+
* This property can be used to store anything application-specific on layers; as its content may occasionally
|
|
9
|
+
* be serialized to JSON for change detection purposes, it is not recommended to store Functions or other
|
|
10
|
+
* non-serializable entities
|
|
11
|
+
*/
|
|
12
|
+
extras?: LayerExtras;
|
|
13
|
+
}
|
|
14
|
+
export interface MapContextLayerWms extends MapContextBaseLayer {
|
|
15
|
+
type: "wms";
|
|
16
|
+
url: string;
|
|
17
|
+
name: string;
|
|
18
|
+
dimensions?: LayerDimensions;
|
|
19
|
+
style?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface MapContextLayerWmts extends MapContextBaseLayer {
|
|
22
|
+
type: "wmts";
|
|
23
|
+
url: string;
|
|
24
|
+
name: string;
|
|
25
|
+
dimensions?: LayerDimensions;
|
|
26
|
+
style?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface MapContextLayerWfs extends MapContextBaseLayer {
|
|
29
|
+
type: "wfs";
|
|
30
|
+
url: string;
|
|
31
|
+
featureType: string;
|
|
32
|
+
}
|
|
33
|
+
export interface MapContextLayerXyz extends MapContextBaseLayer {
|
|
34
|
+
type: "xyz";
|
|
35
|
+
url: string;
|
|
36
|
+
}
|
|
37
|
+
interface LayerGeojson extends MapContextBaseLayer {
|
|
38
|
+
type: "geojson";
|
|
39
|
+
}
|
|
40
|
+
interface LayerGeojsonWithUrl extends LayerGeojson {
|
|
41
|
+
url: string;
|
|
42
|
+
data?: never;
|
|
43
|
+
}
|
|
44
|
+
interface LayerGeojsonWithData extends LayerGeojson {
|
|
45
|
+
data: FeatureCollection<Geometry | null> | string;
|
|
46
|
+
url?: never;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @interface
|
|
50
|
+
*/
|
|
51
|
+
export type MapContextLayerGeojson = LayerGeojsonWithUrl | LayerGeojsonWithData;
|
|
52
|
+
/**
|
|
53
|
+
* @interface
|
|
54
|
+
*/
|
|
55
|
+
export type MapContextLayer = MapContextLayerWms | MapContextLayerWmts | MapContextLayerWfs | MapContextLayerXyz | MapContextLayerGeojson;
|
|
56
|
+
export type Coordinate = [number, number];
|
|
57
|
+
/**
|
|
58
|
+
* Min X, min Y, max X, max Y
|
|
59
|
+
*/
|
|
60
|
+
export type Extent = [number, number, number, number];
|
|
61
|
+
/**
|
|
62
|
+
* @property center Expressed in longitude/latitude
|
|
63
|
+
* @property extent Expressed in longitude/latitude
|
|
64
|
+
* @property maxExtent Expressed in longitude/latitude
|
|
65
|
+
*/
|
|
66
|
+
export interface MapContextView {
|
|
67
|
+
center?: Coordinate;
|
|
68
|
+
zoom?: number;
|
|
69
|
+
extent?: Extent;
|
|
70
|
+
maxZoom?: number;
|
|
71
|
+
maxExtent?: Extent;
|
|
72
|
+
}
|
|
73
|
+
export interface MapContext {
|
|
74
|
+
layers: MapContextLayer[];
|
|
75
|
+
view: MapContextView;
|
|
76
|
+
}
|
|
77
|
+
export {};
|
|
78
|
+
//# sourceMappingURL=map-context.d.ts.map
|
|
@@ -0,0 +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;AAEtD,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,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,kBAAmB,SAAQ,mBAAmB;IAC7D,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAoB,SAAQ,mBAAmB;IAC9D,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,kBAAmB,SAAQ,mBAAmB;IAC7D,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,kBAAmB,SAAQ,mBAAmB;IAC7D,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAED,UAAU,YAAa,SAAQ,mBAAmB;IAChD,IAAI,EAAE,SAAS,CAAC;CACjB;AACD,UAAU,mBAAoB,SAAQ,YAAY;IAChD,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,KAAK,CAAC;CACd;AACD,UAAU,oBAAqB,SAAQ,YAAY;IACjD,IAAI,EAAE,iBAAiB,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC;IAClD,GAAG,CAAC,EAAE,KAAK,CAAC;CACb;AAED;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,mBAAmB,GAAG,oBAAoB,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,eAAe,GACvB,kBAAkB,GAClB,mBAAmB,GACnB,kBAAkB,GAClB,kBAAkB,GAClB,sBAAsB,CAAC;AAE3B,MAAM,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE1C;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEtD;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,IAAI,EAAE,cAAc,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"freeze.d.ts","sourceRoot":"","sources":["../../../lib/utils/freeze.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAavC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function deepFreeze(obj) {
|
|
2
|
+
if (Array.isArray(obj)) {
|
|
3
|
+
for (const elt of obj) {
|
|
4
|
+
deepFreeze(elt);
|
|
5
|
+
}
|
|
6
|
+
return obj;
|
|
7
|
+
}
|
|
8
|
+
else if (obj instanceof Object) {
|
|
9
|
+
for (const prop in obj) {
|
|
10
|
+
deepFreeze(obj[prop]);
|
|
11
|
+
}
|
|
12
|
+
return Object.freeze(obj);
|
|
13
|
+
}
|
|
14
|
+
return obj;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"freeze.test.d.ts","sourceRoot":"","sources":["../../../lib/utils/freeze.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { deepFreeze } from "./freeze";
|
|
2
|
+
describe("freeze util", () => {
|
|
3
|
+
describe("deepFreeze", () => {
|
|
4
|
+
let obj;
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
obj = deepFreeze({
|
|
7
|
+
ab: "cde",
|
|
8
|
+
fg: {
|
|
9
|
+
h: true,
|
|
10
|
+
ij: 12,
|
|
11
|
+
},
|
|
12
|
+
k: [
|
|
13
|
+
{
|
|
14
|
+
l: 456,
|
|
15
|
+
mn: ["opqr"],
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
it("prevents mutation of root properties", () => {
|
|
21
|
+
expect(() => {
|
|
22
|
+
obj.ab = "AA";
|
|
23
|
+
}).toThrow();
|
|
24
|
+
});
|
|
25
|
+
it("prevents mutation of nested properties", () => {
|
|
26
|
+
expect(() => {
|
|
27
|
+
obj.fg.h = "AA";
|
|
28
|
+
}).toThrow();
|
|
29
|
+
});
|
|
30
|
+
it("prevents mutation of objects inside nested arrays", () => {
|
|
31
|
+
expect(() => {
|
|
32
|
+
obj.k[0].l = "AA";
|
|
33
|
+
}).toThrow();
|
|
34
|
+
});
|
|
35
|
+
describe("starting with array", () => {
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
obj = deepFreeze([
|
|
38
|
+
{
|
|
39
|
+
l: 456,
|
|
40
|
+
mn: ["opqr"],
|
|
41
|
+
},
|
|
42
|
+
]);
|
|
43
|
+
});
|
|
44
|
+
it("prevents mutation of nested objects", () => {
|
|
45
|
+
expect(() => {
|
|
46
|
+
obj[0].l = "AA";
|
|
47
|
+
}).toThrow();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { MapContext, MapContextDiff } from "../model";
|
|
2
|
+
/**
|
|
3
|
+
* The following logic is produced by identifying layers in both context
|
|
4
|
+
* and determining whether they have been added, removed, changed or reordered.
|
|
5
|
+
*
|
|
6
|
+
* Identifying layers to determine if they have been added/removed/reordered is done like so:
|
|
7
|
+
* 1. For layers with an `id` property, use non-strict equality on it (e.g. '2' and 2 are equivalent);
|
|
8
|
+
* 2. For layers without `id`, compute a hash of their base properties _excluding the `extras` property_
|
|
9
|
+
*
|
|
10
|
+
* Determining whether layers have changed is done like so:
|
|
11
|
+
* 1. For layers with an `id` property, the value of the `version` field is compared;
|
|
12
|
+
* if values are different (using non-strict equality), then the layer is considered to have changed; otherwise
|
|
13
|
+
* it is considered to have remained the same
|
|
14
|
+
* 2. For layers without `id`, a full hash is computed _including the `extras` property_;
|
|
15
|
+
* this means that a layer which only had changes in its `extras` object will not be considered added/removed,
|
|
16
|
+
* but only changed
|
|
17
|
+
*
|
|
18
|
+
* @param nextContext
|
|
19
|
+
* @param previousContext
|
|
20
|
+
*/
|
|
21
|
+
export declare function computeMapContextDiff(nextContext: MapContext, previousContext: MapContext): MapContextDiff;
|
|
22
|
+
//# sourceMappingURL=map-context-diff.d.ts.map
|
|
@@ -0,0 +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,EAKf,MAAM,UAAU,CAAC;AAGlB;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,UAAU,EACvB,eAAe,EAAE,UAAU,GAC1B,cAAc,CAqEhB"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { isLayerSame, isLayerSameAndUnchanged } from "./map-context";
|
|
2
|
+
/**
|
|
3
|
+
* The following logic is produced by identifying layers in both context
|
|
4
|
+
* and determining whether they have been added, removed, changed or reordered.
|
|
5
|
+
*
|
|
6
|
+
* Identifying layers to determine if they have been added/removed/reordered is done like so:
|
|
7
|
+
* 1. For layers with an `id` property, use non-strict equality on it (e.g. '2' and 2 are equivalent);
|
|
8
|
+
* 2. For layers without `id`, compute a hash of their base properties _excluding the `extras` property_
|
|
9
|
+
*
|
|
10
|
+
* Determining whether layers have changed is done like so:
|
|
11
|
+
* 1. For layers with an `id` property, the value of the `version` field is compared;
|
|
12
|
+
* if values are different (using non-strict equality), then the layer is considered to have changed; otherwise
|
|
13
|
+
* it is considered to have remained the same
|
|
14
|
+
* 2. For layers without `id`, a full hash is computed _including the `extras` property_;
|
|
15
|
+
* this means that a layer which only had changes in its `extras` object will not be considered added/removed,
|
|
16
|
+
* but only changed
|
|
17
|
+
*
|
|
18
|
+
* @param nextContext
|
|
19
|
+
* @param previousContext
|
|
20
|
+
*/
|
|
21
|
+
export function computeMapContextDiff(nextContext, previousContext) {
|
|
22
|
+
function getLayerPosition(layer, layers) {
|
|
23
|
+
for (let i = 0; i < layers.length; i++) {
|
|
24
|
+
if (isLayerSame(layers[i], layer)) {
|
|
25
|
+
return i;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return -1;
|
|
29
|
+
}
|
|
30
|
+
const layersChanged = [];
|
|
31
|
+
const layersReordered = [];
|
|
32
|
+
const layersRemoved = [];
|
|
33
|
+
const layersAdded = [];
|
|
34
|
+
const viewChanges = {};
|
|
35
|
+
// loop on prev context layers (for removed layers)
|
|
36
|
+
for (let i = 0; i < previousContext.layers.length; i++) {
|
|
37
|
+
const layer = previousContext.layers[i];
|
|
38
|
+
const nextPosition = getLayerPosition(layer, nextContext.layers);
|
|
39
|
+
const prevPosition = getLayerPosition(layer, previousContext.layers);
|
|
40
|
+
if (nextPosition === -1) {
|
|
41
|
+
layersRemoved.push({ layer, position: prevPosition });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// loop on next context layers (for added & updated)
|
|
45
|
+
for (let i = 0; i < nextContext.layers.length; i++) {
|
|
46
|
+
const layer = nextContext.layers[i];
|
|
47
|
+
const prevPosition = getLayerPosition(layer, previousContext.layers);
|
|
48
|
+
if (prevPosition === -1) {
|
|
49
|
+
layersAdded.push({ layer, position: i });
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const prevLayer = previousContext.layers[prevPosition];
|
|
53
|
+
if (!isLayerSameAndUnchanged(layer, prevLayer)) {
|
|
54
|
+
layersChanged.push({ layer, position: i });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// look for moved layers
|
|
59
|
+
const prevLayersFiltered = previousContext.layers.filter((l) => !layersRemoved.find(({ layer }) => l === layer));
|
|
60
|
+
const nextLayersFiltered = nextContext.layers.filter((l) => !layersAdded.find(({ layer }) => l === layer));
|
|
61
|
+
for (let i = 0; i < nextLayersFiltered.length; i++) {
|
|
62
|
+
const layer = nextLayersFiltered[i];
|
|
63
|
+
const prevPosition = getLayerPosition(layer, prevLayersFiltered);
|
|
64
|
+
if (i !== prevPosition) {
|
|
65
|
+
layersReordered.push({
|
|
66
|
+
layer,
|
|
67
|
+
newPosition: getLayerPosition(layer, nextContext.layers),
|
|
68
|
+
previousPosition: getLayerPosition(layer, previousContext.layers),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
layersAdded,
|
|
74
|
+
layersChanged,
|
|
75
|
+
layersRemoved,
|
|
76
|
+
layersReordered,
|
|
77
|
+
viewChanges,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-context-diff.test.d.ts","sourceRoot":"","sources":["../../../lib/utils/map-context-diff.test.ts"],"names":[],"mappings":""}
|