@geospatial-sdk/core 0.0.5-alpha.0
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/LICENSE +28 -0
- package/README.md +11 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/model/index.d.ts +3 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +2 -0
- package/dist/model/map-context-diff.d.ts +35 -0
- package/dist/model/map-context-diff.d.ts.map +1 -0
- package/dist/model/map-context-diff.js +1 -0
- package/dist/model/map-context.d.ts +82 -0
- package/dist/model/map-context.d.ts.map +1 -0
- package/dist/model/map-context.js +1 -0
- package/dist/utils/freeze.d.ts +2 -0
- package/dist/utils/freeze.d.ts.map +1 -0
- package/dist/utils/freeze.js +15 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/map-context-diff.d.ts +22 -0
- package/dist/utils/map-context-diff.d.ts.map +1 -0
- package/dist/utils/map-context-diff.js +79 -0
- 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/url.d.ts +7 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/dist/utils/url.js +17 -0
- package/lib/index.ts +3 -0
- package/lib/model/index.ts +2 -0
- package/lib/model/map-context-diff.ts +37 -0
- package/lib/model/map-context.ts +100 -0
- package/lib/utils/freeze.test.ts +52 -0
- package/lib/utils/freeze.ts +14 -0
- package/lib/utils/index.ts +4 -0
- package/lib/utils/map-context-diff.test.ts +275 -0
- package/lib/utils/map-context-diff.ts +102 -0
- package/lib/utils/map-context.test.ts +303 -0
- package/lib/utils/map-context.ts +51 -0
- package/lib/utils/url.test.ts +14 -0
- package/lib/utils/url.ts +20 -0
- package/package.json +26 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { MapContext, MapContextLayer } from "../model";
|
|
2
|
+
|
|
3
|
+
export function getLayerHash(
|
|
4
|
+
layer: MapContextLayer,
|
|
5
|
+
includeExtras = false,
|
|
6
|
+
): string {
|
|
7
|
+
function getHash(input: unknown): string {
|
|
8
|
+
if (input instanceof Object) {
|
|
9
|
+
const obj: Record<string, string> = {};
|
|
10
|
+
const keys = Object.keys(input).sort();
|
|
11
|
+
for (const key of keys) {
|
|
12
|
+
if (!includeExtras && key === "extras") continue;
|
|
13
|
+
obj[key] = getHash(input[key as keyof typeof input]);
|
|
14
|
+
}
|
|
15
|
+
const hash = JSON.stringify(obj)
|
|
16
|
+
.split("")
|
|
17
|
+
.reduce((prev, curr) => (prev << 5) - prev + curr.charCodeAt(0), 0);
|
|
18
|
+
return (hash >>> 0).toString();
|
|
19
|
+
} else {
|
|
20
|
+
return JSON.stringify(input);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return getHash(layer);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isLayerSame(
|
|
27
|
+
layerA: MapContextLayer,
|
|
28
|
+
layerB: MapContextLayer,
|
|
29
|
+
): boolean {
|
|
30
|
+
if ("id" in layerA && "id" in layerB) {
|
|
31
|
+
return layerA.id == layerB.id;
|
|
32
|
+
}
|
|
33
|
+
return getLayerHash(layerA) === getLayerHash(layerB);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function isLayerSameAndUnchanged(
|
|
37
|
+
layerA: MapContextLayer,
|
|
38
|
+
layerB: MapContextLayer,
|
|
39
|
+
): boolean {
|
|
40
|
+
if ("id" in layerA && "id" in layerB) {
|
|
41
|
+
return layerA.id == layerB.id && layerA.version == layerB.version;
|
|
42
|
+
}
|
|
43
|
+
return getLayerHash(layerA, true) === getLayerHash(layerB, true);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function getLayerPosition(
|
|
47
|
+
context: MapContext,
|
|
48
|
+
layerModel: MapContextLayer,
|
|
49
|
+
): number {
|
|
50
|
+
return context.layers.findIndex((l) => isLayerSame(layerModel, l));
|
|
51
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { removeSearchParams } from "./url";
|
|
2
|
+
|
|
3
|
+
describe("URL utils", () => {
|
|
4
|
+
describe("removeSearchParams", () => {
|
|
5
|
+
it("removes given search params in a case insensitive way", () => {
|
|
6
|
+
expect(
|
|
7
|
+
removeSearchParams(
|
|
8
|
+
"http://my.org/abc/?arg0=1234&arg1=aaa&Arg1=111&ARG2=&aRG3=fff&arg4=5678",
|
|
9
|
+
["ARG1", "arg2", "arg3"],
|
|
10
|
+
),
|
|
11
|
+
).toEqual("http://my.org/abc/?arg0=1234&arg4=5678");
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
});
|
package/lib/utils/url.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes the given search params from the URL completely; this is case-insensitive
|
|
3
|
+
* @param url
|
|
4
|
+
* @param searchParams
|
|
5
|
+
*/
|
|
6
|
+
export function removeSearchParams(
|
|
7
|
+
url: string,
|
|
8
|
+
searchParams: string[],
|
|
9
|
+
): string {
|
|
10
|
+
const toDelete = [];
|
|
11
|
+
const urlObj = new URL(url, window.location.toString());
|
|
12
|
+
const keysLower = searchParams.map((p) => p.toLowerCase());
|
|
13
|
+
for (const param of urlObj.searchParams.keys()) {
|
|
14
|
+
if (keysLower.indexOf(param.toLowerCase()) > -1) {
|
|
15
|
+
toDelete.push(param);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
toDelete.map((param) => urlObj.searchParams.delete(param));
|
|
19
|
+
return urlObj.toString();
|
|
20
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@geospatial-sdk/core",
|
|
3
|
+
"version": "0.0.5-alpha.0+030ea1b",
|
|
4
|
+
"description": "Core functions and models for the SDK",
|
|
5
|
+
"author": "Olivia <olivia.guyot@camptocamp.com>",
|
|
6
|
+
"homepage": "",
|
|
7
|
+
"license": "BSD-3-Clause",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"typings": "dist/index.d.ts",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"directories": {
|
|
15
|
+
"lib": "lib"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"lib",
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"test": "vitest",
|
|
23
|
+
"build": "tsc"
|
|
24
|
+
},
|
|
25
|
+
"gitHead": "030ea1b7054f5febd8bcddd9b6be8d06793ecebd"
|
|
26
|
+
}
|