@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.
Files changed (65) hide show
  1. package/dist/fixtures/geojson.fixtures.d.ts +4 -0
  2. package/dist/fixtures/geojson.fixtures.d.ts.map +1 -0
  3. package/dist/fixtures/geojson.fixtures.js +55121 -0
  4. package/dist/fixtures/map-context.fixtures.d.ts +16 -0
  5. package/dist/fixtures/map-context.fixtures.d.ts.map +1 -0
  6. package/dist/fixtures/map-context.fixtures.js +73 -0
  7. package/dist/lib/index.d.ts +3 -0
  8. package/dist/lib/index.d.ts.map +1 -0
  9. package/dist/lib/index.js +3 -0
  10. package/dist/lib/model/index.d.ts +3 -0
  11. package/dist/lib/model/index.d.ts.map +1 -0
  12. package/dist/lib/model/index.js +2 -0
  13. package/dist/lib/model/map-context-diff.d.ts +35 -0
  14. package/dist/lib/model/map-context-diff.d.ts.map +1 -0
  15. package/dist/lib/model/map-context-diff.js +1 -0
  16. package/dist/lib/model/map-context.d.ts +78 -0
  17. package/dist/lib/model/map-context.d.ts.map +1 -0
  18. package/dist/lib/model/map-context.js +1 -0
  19. package/dist/lib/utils/freeze.d.ts +2 -0
  20. package/dist/lib/utils/freeze.d.ts.map +1 -0
  21. package/dist/lib/utils/freeze.js +15 -0
  22. package/dist/lib/utils/freeze.test.d.ts +2 -0
  23. package/dist/lib/utils/freeze.test.d.ts.map +1 -0
  24. package/dist/lib/utils/freeze.test.js +51 -0
  25. package/dist/lib/utils/index.d.ts +5 -0
  26. package/dist/lib/utils/index.d.ts.map +1 -0
  27. package/dist/lib/utils/index.js +4 -0
  28. package/dist/lib/utils/map-context-diff.d.ts +22 -0
  29. package/dist/lib/utils/map-context-diff.d.ts.map +1 -0
  30. package/dist/lib/utils/map-context-diff.js +79 -0
  31. package/dist/lib/utils/map-context-diff.test.d.ts +2 -0
  32. package/dist/lib/utils/map-context-diff.test.d.ts.map +1 -0
  33. package/dist/lib/utils/map-context-diff.test.js +217 -0
  34. package/dist/lib/utils/map-context.d.ts +6 -0
  35. package/dist/lib/utils/map-context.d.ts.map +1 -0
  36. package/dist/lib/utils/map-context.js +36 -0
  37. package/dist/lib/utils/map-context.test.d.ts +2 -0
  38. package/dist/lib/utils/map-context.test.d.ts.map +1 -0
  39. package/dist/lib/utils/map-context.test.js +131 -0
  40. package/dist/lib/utils/url.d.ts +7 -0
  41. package/dist/lib/utils/url.d.ts.map +1 -0
  42. package/dist/lib/utils/url.js +17 -0
  43. package/dist/lib/utils/url.test.d.ts +2 -0
  44. package/dist/lib/utils/url.test.d.ts.map +1 -0
  45. package/dist/lib/utils/url.test.js +8 -0
  46. package/dist/utils/index.d.ts +1 -0
  47. package/dist/utils/index.d.ts.map +1 -1
  48. package/dist/utils/index.js +1 -0
  49. package/dist/utils/map-context-diff.d.ts +1 -4
  50. package/dist/utils/map-context-diff.d.ts.map +1 -1
  51. package/dist/utils/map-context-diff.js +1 -33
  52. package/dist/utils/map-context-diff.test.js +1 -120
  53. package/dist/utils/map-context.d.ts +6 -0
  54. package/dist/utils/map-context.d.ts.map +1 -0
  55. package/dist/utils/map-context.js +36 -0
  56. package/dist/utils/map-context.test.d.ts +2 -0
  57. package/dist/utils/map-context.test.d.ts.map +1 -0
  58. package/dist/utils/map-context.test.js +150 -0
  59. package/lib/model/map-context-diff.ts +4 -4
  60. package/lib/utils/index.ts +1 -0
  61. package/lib/utils/map-context-diff.test.ts +8 -310
  62. package/lib/utils/map-context-diff.ts +1 -43
  63. package/lib/utils/map-context.test.ts +294 -0
  64. package/lib/utils/map-context.ts +51 -0
  65. package/package.json +2 -2
@@ -1,16 +1,5 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
1
  import { deepFreeze } from "./freeze";
13
- import { computeMapContextDiff, getLayerHash, isLayerSame, isLayerSameAndUnchanged, } from "./map-context-diff";
2
+ import { computeMapContextDiff } from "./map-context-diff";
14
3
  const SAMPLE_CONTEXT = deepFreeze({
15
4
  view: {
16
5
  center: [10, 20],
@@ -46,68 +35,6 @@ const SAMPLE_LAYER5 = deepFreeze({
46
35
  url: "http://my.tiles/server",
47
36
  });
48
37
  describe("Context diff utils", () => {
49
- describe("isLayerSame", () => {
50
- describe("layers with id", () => {
51
- it("compares non-strictly by id", () => {
52
- expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "a" }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "b" }))).toBe(false);
53
- expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "ab" }), Object.assign(Object.assign({}, SAMPLE_LAYER2), { id: "ab" }))).toBe(true);
54
- expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: 1 }), Object.assign(Object.assign({}, SAMPLE_LAYER2), { id: "01" }))).toBe(true);
55
- expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: 1 }), Object.assign(Object.assign({}, SAMPLE_LAYER2), { id: 1 }))).toBe(true);
56
- expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: 1 }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: 2 }))).toBe(false);
57
- });
58
- });
59
- describe("layers without id", () => {
60
- it("compares by properties", () => {
61
- expect(isLayerSame(SAMPLE_LAYER1, SAMPLE_LAYER1)).toBe(true);
62
- expect(isLayerSame(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { name: "abc" }))).toBe(false);
63
- expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { url: "http://abc.org", name: SAMPLE_LAYER1.name }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { url: "http://abc.org" }))).toBe(true);
64
- expect(isLayerSame(SAMPLE_LAYER1, SAMPLE_LAYER2)).toBe(false);
65
- });
66
- it("ignores extras prop", () => {
67
- expect(isLayerSame(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: { otherProp: "abc" } }))).toBe(true);
68
- expect(isLayerSame(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: undefined }))).toBe(true);
69
- const { extras } = SAMPLE_LAYER1, layer = __rest(SAMPLE_LAYER1, ["extras"]);
70
- expect(isLayerSame(SAMPLE_LAYER1, layer)).toBe(true);
71
- });
72
- });
73
- describe("layers with and without id", () => {
74
- it("compares by properties", () => {
75
- expect(isLayerSame(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "123" }))).toBe(false);
76
- expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "123" }), Object.assign(Object.assign({ id: "123" }, SAMPLE_LAYER1), { name: SAMPLE_LAYER1.name }))).toBe(true);
77
- });
78
- });
79
- });
80
- describe("isLayerSameAndUnchanged", () => {
81
- describe("layers with id", () => {
82
- it("compares non-strictly by id and version field", () => {
83
- expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "a" }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "b" }))).toBe(false);
84
- expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "a" }), Object.assign(Object.assign({}, SAMPLE_LAYER2), { id: "a" }))).toBe(true);
85
- expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "ab", version: 2 }), Object.assign(Object.assign({}, SAMPLE_LAYER2), { id: "ab", version: 2 }))).toBe(true);
86
- expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "ab", version: 2 }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "ab", version: 1 }))).toBe(false);
87
- expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: 1 }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "01", version: 3 }))).toBe(false);
88
- });
89
- });
90
- describe("layers without id", () => {
91
- it("compares by properties, including extras", () => {
92
- expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, SAMPLE_LAYER1)).toBe(true);
93
- expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { name: "abc" }))).toBe(false);
94
- expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { url: "http://abc.org", name: SAMPLE_LAYER1.name }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { url: "http://abc.org" }))).toBe(true);
95
- expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, SAMPLE_LAYER2)).toBe(false);
96
- });
97
- it("takes into account extras prop", () => {
98
- expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: { otherProp: "abc" } }))).toBe(false);
99
- expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: undefined }))).toBe(false);
100
- const { extras } = SAMPLE_LAYER1, layer = __rest(SAMPLE_LAYER1, ["extras"]);
101
- expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, layer)).toBe(false);
102
- });
103
- });
104
- describe("layers with and without id", () => {
105
- it("compares by properties", () => {
106
- expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "123" }))).toBe(false);
107
- expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "123" }), Object.assign(Object.assign({ id: "123" }, SAMPLE_LAYER1), { name: SAMPLE_LAYER1.name }))).toBe(true);
108
- });
109
- });
110
- });
111
38
  describe("computeMapContextDiff", () => {
112
39
  let contextOld;
113
40
  let contextNew;
@@ -321,50 +248,4 @@ describe("Context diff utils", () => {
321
248
  });
322
249
  });
323
250
  });
324
- describe("getLayerHash", () => {
325
- it("works with serializable entities", () => {
326
- expect(getLayerHash(Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: {
327
- array: [11, 22, null, undefined],
328
- object: {},
329
- undef: undefined,
330
- } }))).toBeTypeOf("string");
331
- });
332
- it("ignores extra property by default", () => {
333
- expect(getLayerHash(Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: {
334
- array: [11, 22, null, undefined],
335
- object: {},
336
- } }))).toEqual(getLayerHash(Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: { hello: "world" } })));
337
- });
338
- it("works with non-serializable entities (but they are ignored)", () => {
339
- const hash = getLayerHash(Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: {
340
- func: () => 123,
341
- canvas: document.createElement("canvas"),
342
- } }), true);
343
- expect(hash).toBeTypeOf("string");
344
- expect(hash).toEqual(getLayerHash(Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: {
345
- func: () => 456,
346
- canvas: document.createElement("div"),
347
- } }), true));
348
- expect(hash).not.toEqual(getLayerHash(Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: {} }), true));
349
- });
350
- it("does not take into account properties order", () => {
351
- expect(getLayerHash({
352
- type: "wms",
353
- url: "http://abc.org/wms",
354
- name: "myLayer",
355
- extras: {
356
- array: [1, 2, 3],
357
- object: {},
358
- },
359
- }, true)).toEqual(getLayerHash({
360
- extras: {
361
- array: [1, 2, 3],
362
- object: {},
363
- },
364
- url: "http://abc.org/wms",
365
- type: "wms",
366
- name: "myLayer",
367
- }, true));
368
- });
369
- });
370
251
  });
@@ -0,0 +1,6 @@
1
+ import { MapContext, MapContextLayer } from "../model";
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
+ export declare function getLayerPosition(context: MapContext, layerModel: MapContextLayer): number;
6
+ //# sourceMappingURL=map-context.d.ts.map
@@ -0,0 +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,UAAU,CAAC;AAEvD,wBAAgB,YAAY,CAC1B,KAAK,EAAE,eAAe,EACtB,aAAa,UAAQ,GACpB,MAAM,CAkBR;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,CAKT;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,UAAU,EACnB,UAAU,EAAE,eAAe,GAC1B,MAAM,CAER"}
@@ -0,0 +1,36 @@
1
+ export function getLayerHash(layer, includeExtras = false) {
2
+ function getHash(input) {
3
+ if (input instanceof Object) {
4
+ const obj = {};
5
+ const keys = Object.keys(input).sort();
6
+ for (const key of keys) {
7
+ if (!includeExtras && key === "extras")
8
+ continue;
9
+ obj[key] = getHash(input[key]);
10
+ }
11
+ const hash = JSON.stringify(obj)
12
+ .split("")
13
+ .reduce((prev, curr) => (prev << 5) - prev + curr.charCodeAt(0), 0);
14
+ return (hash >>> 0).toString();
15
+ }
16
+ else {
17
+ return JSON.stringify(input);
18
+ }
19
+ }
20
+ return getHash(layer);
21
+ }
22
+ export function isLayerSame(layerA, layerB) {
23
+ if ("id" in layerA && "id" in layerB) {
24
+ return layerA.id == layerB.id;
25
+ }
26
+ return getLayerHash(layerA) === getLayerHash(layerB);
27
+ }
28
+ export function isLayerSameAndUnchanged(layerA, layerB) {
29
+ if ("id" in layerA && "id" in layerB) {
30
+ return layerA.id == layerB.id && layerA.version == layerB.version;
31
+ }
32
+ return getLayerHash(layerA, true) === getLayerHash(layerB, true);
33
+ }
34
+ export function getLayerPosition(context, layerModel) {
35
+ return context.layers.findIndex((l) => isLayerSame(layerModel, l));
36
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=map-context.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-context.test.d.ts","sourceRoot":"","sources":["../../lib/utils/map-context.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,150 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { describe } from "vitest";
13
+ import { getLayerHash, getLayerPosition, isLayerSame, isLayerSameAndUnchanged, } from "./map-context";
14
+ import { deepFreeze } from "./freeze";
15
+ const SAMPLE_LAYER1 = deepFreeze({
16
+ type: "wms",
17
+ url: "http://abc.org/wms",
18
+ name: "myLayer",
19
+ extras: { myField: "abc" },
20
+ });
21
+ const SAMPLE_LAYER2 = deepFreeze({
22
+ type: "xyz",
23
+ url: "http://abc.org/tiles",
24
+ extras: { myField2: "123" },
25
+ });
26
+ const SAMPLE_CONTEXT = deepFreeze({
27
+ view: {
28
+ center: [10, 20],
29
+ zoom: 3,
30
+ extent: [40, 50, 60, 70],
31
+ },
32
+ layers: [],
33
+ });
34
+ describe("Map context utils", () => {
35
+ describe("isLayerSame", () => {
36
+ describe("layers with id", () => {
37
+ it("compares non-strictly by id", () => {
38
+ expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "a" }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "b" }))).toBe(false);
39
+ expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "ab" }), Object.assign(Object.assign({}, SAMPLE_LAYER2), { id: "ab" }))).toBe(true);
40
+ expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: 1 }), Object.assign(Object.assign({}, SAMPLE_LAYER2), { id: "01" }))).toBe(true);
41
+ expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: 1 }), Object.assign(Object.assign({}, SAMPLE_LAYER2), { id: 1 }))).toBe(true);
42
+ expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: 1 }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: 2 }))).toBe(false);
43
+ });
44
+ });
45
+ describe("layers without id", () => {
46
+ it("compares by properties", () => {
47
+ expect(isLayerSame(SAMPLE_LAYER1, SAMPLE_LAYER1)).toBe(true);
48
+ expect(isLayerSame(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { name: "abc" }))).toBe(false);
49
+ expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { url: "http://abc.org", name: SAMPLE_LAYER1.name }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { url: "http://abc.org" }))).toBe(true);
50
+ expect(isLayerSame(SAMPLE_LAYER1, SAMPLE_LAYER2)).toBe(false);
51
+ });
52
+ it("ignores extras prop", () => {
53
+ expect(isLayerSame(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: { otherProp: "abc" } }))).toBe(true);
54
+ expect(isLayerSame(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: undefined }))).toBe(true);
55
+ const { extras } = SAMPLE_LAYER1, layer = __rest(SAMPLE_LAYER1, ["extras"]);
56
+ expect(isLayerSame(SAMPLE_LAYER1, layer)).toBe(true);
57
+ });
58
+ });
59
+ describe("layers with and without id", () => {
60
+ it("compares by properties", () => {
61
+ expect(isLayerSame(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "123" }))).toBe(false);
62
+ expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "123" }), Object.assign(Object.assign({ id: "123" }, SAMPLE_LAYER1), { name: SAMPLE_LAYER1.name }))).toBe(true);
63
+ });
64
+ });
65
+ });
66
+ describe("isLayerSameAndUnchanged", () => {
67
+ describe("layers with id", () => {
68
+ it("compares non-strictly by id and version field", () => {
69
+ expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "a" }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "b" }))).toBe(false);
70
+ expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "a" }), Object.assign(Object.assign({}, SAMPLE_LAYER2), { id: "a" }))).toBe(true);
71
+ expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "ab", version: 2 }), Object.assign(Object.assign({}, SAMPLE_LAYER2), { id: "ab", version: 2 }))).toBe(true);
72
+ expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "ab", version: 2 }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "ab", version: 1 }))).toBe(false);
73
+ expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: 1 }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "01", version: 3 }))).toBe(false);
74
+ });
75
+ });
76
+ describe("layers without id", () => {
77
+ it("compares by properties, including extras", () => {
78
+ expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, SAMPLE_LAYER1)).toBe(true);
79
+ expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { name: "abc" }))).toBe(false);
80
+ expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { url: "http://abc.org", name: SAMPLE_LAYER1.name }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { url: "http://abc.org" }))).toBe(true);
81
+ expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, SAMPLE_LAYER2)).toBe(false);
82
+ });
83
+ it("takes into account extras prop", () => {
84
+ expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: { otherProp: "abc" } }))).toBe(false);
85
+ expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: undefined }))).toBe(false);
86
+ const { extras } = SAMPLE_LAYER1, layer = __rest(SAMPLE_LAYER1, ["extras"]);
87
+ expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, layer)).toBe(false);
88
+ });
89
+ });
90
+ describe("layers with and without id", () => {
91
+ it("compares by properties", () => {
92
+ expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "123" }))).toBe(false);
93
+ expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "123" }), Object.assign(Object.assign({ id: "123" }, SAMPLE_LAYER1), { name: SAMPLE_LAYER1.name }))).toBe(true);
94
+ });
95
+ });
96
+ });
97
+ describe("getLayerHash", () => {
98
+ it("works with serializable entities", () => {
99
+ expect(getLayerHash(Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: {
100
+ array: [11, 22, null, undefined],
101
+ object: {},
102
+ undef: undefined,
103
+ } }))).toBeTypeOf("string");
104
+ });
105
+ it("ignores extra property by default", () => {
106
+ expect(getLayerHash(Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: {
107
+ array: [11, 22, null, undefined],
108
+ object: {},
109
+ } }))).toEqual(getLayerHash(Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: { hello: "world" } })));
110
+ });
111
+ it("works with non-serializable entities (but they are ignored)", () => {
112
+ const hash = getLayerHash(Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: {
113
+ func: () => 123,
114
+ canvas: document.createElement("canvas"),
115
+ } }), true);
116
+ expect(hash).toBeTypeOf("string");
117
+ expect(hash).toEqual(getLayerHash(Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: {
118
+ func: () => 456,
119
+ canvas: document.createElement("div"),
120
+ } }), true));
121
+ expect(hash).not.toEqual(getLayerHash(Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: {} }), true));
122
+ });
123
+ it("does not take into account properties order", () => {
124
+ expect(getLayerHash({
125
+ type: "wms",
126
+ url: "http://abc.org/wms",
127
+ name: "myLayer",
128
+ extras: {
129
+ array: [1, 2, 3],
130
+ object: {},
131
+ },
132
+ }, true)).toEqual(getLayerHash({
133
+ extras: {
134
+ array: [1, 2, 3],
135
+ object: {},
136
+ },
137
+ url: "http://abc.org/wms",
138
+ type: "wms",
139
+ name: "myLayer",
140
+ }, true));
141
+ });
142
+ });
143
+ describe("getLayerPosition", () => {
144
+ it("returns the index of the layer in the context", () => {
145
+ const context = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [SAMPLE_LAYER1, SAMPLE_LAYER2] });
146
+ expect(getLayerPosition(context, SAMPLE_LAYER1)).toBe(0);
147
+ expect(getLayerPosition(context, SAMPLE_LAYER2)).toBe(1);
148
+ });
149
+ });
150
+ });
@@ -23,10 +23,10 @@ export interface MapContextLayerReordered {
23
23
  * applied to an existing map.
24
24
  *
25
25
  * For positions to be correct the order of operations should be:
26
- * 1. change layers
27
- * 2. remove layers
28
- * 3. add layers
29
- * 4. move layers
26
+ * 1. remove layers
27
+ * 2. add layers
28
+ * 3. move layers
29
+ * 4. change layers
30
30
  */
31
31
  export interface MapContextDiff {
32
32
  layersChanged: MapContextLayerPositioned[];
@@ -1,3 +1,4 @@
1
1
  export * from "./url";
2
2
  export * from "./freeze";
3
3
  export { computeMapContextDiff } from "./map-context-diff";
4
+ export { getLayerPosition } from "./map-context";