@geospatial-sdk/core 0.0.5-dev.72 → 0.0.5-dev.74
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.
|
@@ -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,EAKf,MAAM,mBAAmB,CAAC;AAG3B;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,UAAU,EACvB,eAAe,EAAE,UAAU,GAC1B,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,CA8EhB"}
|
|
@@ -54,17 +54,22 @@ export function computeMapContextDiff(nextContext, previousContext) {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
// look for moved layers
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
for (let i = 0; i <
|
|
61
|
-
const layer =
|
|
62
|
-
|
|
57
|
+
// look for moved layers (ignore removed and added ones)
|
|
58
|
+
const movedLayersInPrevious = previousContext.layers.filter((l) => !layersRemoved.find(({ layer }) => l === layer));
|
|
59
|
+
const movedLayersInNext = nextContext.layers.filter((l) => !layersAdded.find(({ layer }) => l === layer));
|
|
60
|
+
for (let i = 0; i < movedLayersInNext.length; i++) {
|
|
61
|
+
const layer = movedLayersInNext[i];
|
|
62
|
+
let prevPosition = getLayerPosition(layer, movedLayersInPrevious);
|
|
63
63
|
if (i !== prevPosition) {
|
|
64
|
+
// shift prevPosition of a move layer when others layers were added before them
|
|
65
|
+
for (const { position: addedPos } of layersAdded) {
|
|
66
|
+
if (addedPos <= prevPosition)
|
|
67
|
+
prevPosition++;
|
|
68
|
+
}
|
|
64
69
|
layersReordered.push({
|
|
65
70
|
layer,
|
|
66
71
|
newPosition: getLayerPosition(layer, nextContext.layers),
|
|
67
|
-
previousPosition:
|
|
72
|
+
previousPosition: prevPosition,
|
|
68
73
|
});
|
|
69
74
|
}
|
|
70
75
|
}
|
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
SAMPLE_LAYER3,
|
|
8
8
|
SAMPLE_LAYER4,
|
|
9
9
|
SAMPLE_LAYER5,
|
|
10
|
+
SAMPLE_LAYER6,
|
|
11
|
+
SAMPLE_LAYER7,
|
|
10
12
|
} from "../../fixtures/map-context.fixtures.js";
|
|
11
13
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
12
14
|
|
|
@@ -390,5 +392,114 @@ describe("Context diff utils", () => {
|
|
|
390
392
|
});
|
|
391
393
|
});
|
|
392
394
|
});
|
|
395
|
+
|
|
396
|
+
describe("combined changes (2)", () => {
|
|
397
|
+
beforeEach(() => {
|
|
398
|
+
contextOld = {
|
|
399
|
+
...SAMPLE_CONTEXT,
|
|
400
|
+
layers: [
|
|
401
|
+
SAMPLE_LAYER1,
|
|
402
|
+
SAMPLE_LAYER5,
|
|
403
|
+
SAMPLE_LAYER3,
|
|
404
|
+
SAMPLE_LAYER4,
|
|
405
|
+
SAMPLE_LAYER6,
|
|
406
|
+
],
|
|
407
|
+
};
|
|
408
|
+
contextNew = {
|
|
409
|
+
...SAMPLE_CONTEXT,
|
|
410
|
+
layers: [SAMPLE_LAYER3, SAMPLE_LAYER1],
|
|
411
|
+
};
|
|
412
|
+
});
|
|
413
|
+
it("outputs the correct diff", async () => {
|
|
414
|
+
diff = computeMapContextDiff(contextNew, contextOld);
|
|
415
|
+
expect(diff).toEqual({
|
|
416
|
+
layersAdded: [],
|
|
417
|
+
layersChanged: [],
|
|
418
|
+
layersRemoved: [
|
|
419
|
+
{
|
|
420
|
+
layer: SAMPLE_LAYER5,
|
|
421
|
+
position: 1,
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
layer: SAMPLE_LAYER4,
|
|
425
|
+
position: 3,
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
layer: SAMPLE_LAYER6,
|
|
429
|
+
position: 4,
|
|
430
|
+
},
|
|
431
|
+
],
|
|
432
|
+
layersReordered: [
|
|
433
|
+
{
|
|
434
|
+
layer: SAMPLE_LAYER3,
|
|
435
|
+
newPosition: 0,
|
|
436
|
+
previousPosition: 1,
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
layer: SAMPLE_LAYER1,
|
|
440
|
+
newPosition: 1,
|
|
441
|
+
previousPosition: 0,
|
|
442
|
+
},
|
|
443
|
+
],
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
describe("combined changes (3)", () => {
|
|
449
|
+
beforeEach(() => {
|
|
450
|
+
contextOld = {
|
|
451
|
+
...SAMPLE_CONTEXT,
|
|
452
|
+
layers: [SAMPLE_LAYER5, SAMPLE_LAYER1, SAMPLE_LAYER2],
|
|
453
|
+
};
|
|
454
|
+
contextNew = {
|
|
455
|
+
...SAMPLE_CONTEXT,
|
|
456
|
+
layers: [
|
|
457
|
+
SAMPLE_LAYER2,
|
|
458
|
+
SAMPLE_LAYER3,
|
|
459
|
+
SAMPLE_LAYER6,
|
|
460
|
+
SAMPLE_LAYER1,
|
|
461
|
+
SAMPLE_LAYER7,
|
|
462
|
+
],
|
|
463
|
+
};
|
|
464
|
+
});
|
|
465
|
+
it("outputs the correct diff", async () => {
|
|
466
|
+
diff = computeMapContextDiff(contextNew, contextOld);
|
|
467
|
+
expect(diff).toEqual({
|
|
468
|
+
layersAdded: [
|
|
469
|
+
{
|
|
470
|
+
layer: SAMPLE_LAYER3,
|
|
471
|
+
position: 1,
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
layer: SAMPLE_LAYER6,
|
|
475
|
+
position: 2,
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
layer: SAMPLE_LAYER7,
|
|
479
|
+
position: 4,
|
|
480
|
+
},
|
|
481
|
+
],
|
|
482
|
+
layersChanged: [],
|
|
483
|
+
layersRemoved: [
|
|
484
|
+
{
|
|
485
|
+
layer: SAMPLE_LAYER5,
|
|
486
|
+
position: 0,
|
|
487
|
+
},
|
|
488
|
+
],
|
|
489
|
+
layersReordered: [
|
|
490
|
+
{
|
|
491
|
+
layer: SAMPLE_LAYER2,
|
|
492
|
+
previousPosition: 3,
|
|
493
|
+
newPosition: 0,
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
layer: SAMPLE_LAYER1,
|
|
497
|
+
previousPosition: 0,
|
|
498
|
+
newPosition: 3,
|
|
499
|
+
},
|
|
500
|
+
],
|
|
501
|
+
});
|
|
502
|
+
});
|
|
503
|
+
});
|
|
393
504
|
});
|
|
394
505
|
});
|
|
@@ -72,21 +72,25 @@ export function computeMapContextDiff(
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
// look for moved layers
|
|
76
|
-
const
|
|
75
|
+
// look for moved layers (ignore removed and added ones)
|
|
76
|
+
const movedLayersInPrevious = previousContext.layers.filter(
|
|
77
77
|
(l) => !layersRemoved.find(({ layer }) => l === layer),
|
|
78
78
|
);
|
|
79
|
-
const
|
|
79
|
+
const movedLayersInNext = nextContext.layers.filter(
|
|
80
80
|
(l) => !layersAdded.find(({ layer }) => l === layer),
|
|
81
81
|
);
|
|
82
|
-
for (let i = 0; i <
|
|
83
|
-
const layer =
|
|
84
|
-
|
|
82
|
+
for (let i = 0; i < movedLayersInNext.length; i++) {
|
|
83
|
+
const layer = movedLayersInNext[i];
|
|
84
|
+
let prevPosition = getLayerPosition(layer, movedLayersInPrevious);
|
|
85
85
|
if (i !== prevPosition) {
|
|
86
|
+
// shift prevPosition of a move layer when others layers were added before them
|
|
87
|
+
for (const { position: addedPos } of layersAdded) {
|
|
88
|
+
if (addedPos <= prevPosition) prevPosition++;
|
|
89
|
+
}
|
|
86
90
|
layersReordered.push({
|
|
87
91
|
layer,
|
|
88
92
|
newPosition: getLayerPosition(layer, nextContext.layers),
|
|
89
|
-
previousPosition:
|
|
93
|
+
previousPosition: prevPosition,
|
|
90
94
|
});
|
|
91
95
|
}
|
|
92
96
|
}
|
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.74+ccdb7a2",
|
|
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": "ccdb7a252c6a6ff483904fe06bad70f08d023d61",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"chroma-js": "^2.4.2",
|
|
28
28
|
"proj4": "^2.9.2"
|