-
-
Notifications
You must be signed in to change notification settings - Fork 628
Expand file tree
/
Copy pathmarker-categories.test.ts
More file actions
134 lines (122 loc) · 3.88 KB
/
Copy pathmarker-categories.test.ts
File metadata and controls
134 lines (122 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { DEFAULT_LAYER_STYLE, type LayerStyle } from "@geolibre/core";
import {
KML_ICON_URL_PROPERTY,
markerImageValue,
prepareKmlFeatureIcons,
} from "../packages/map/src/markers";
function categorizedMarker(patch: Partial<LayerStyle> = {}): LayerStyle {
return {
...DEFAULT_LAYER_STYLE,
markerEnabled: true,
markerShape: "circle",
markerColor: "#3b82f6",
markerSize: 18,
vectorStyleMode: "categorized",
vectorStyleProperty: "status",
vectorStyleStops: [
{ value: "good", color: "#339084" },
{ value: "bad", color: "#fde725" },
],
...patch,
};
}
describe("markerImageValue", () => {
it("selects a separately colored built-in marker for each category", () => {
assert.deepEqual(markerImageValue(categorizedMarker()), [
"match",
["to-string", ["get", "status"]],
"good",
"geolibre-marker-circle-339084-18",
"bad",
"geolibre-marker-circle-fde725-18",
"geolibre-marker-circle-3b82f6-18",
]);
});
it("creates distinct parameterized SVG sprites for category colors", () => {
const value = markerImageValue(
categorizedMarker({
markerShape: "custom",
markerSvg:
'<svg xmlns="http://www.w3.org/2000/svg"><path fill="param(fill)" d="M0 0h10v10z"/></svg>',
}),
);
assert.ok(Array.isArray(value));
const imageIds = [value[3], value[5], value[6]];
assert.ok(
imageIds.every((id) => typeof id === "string" && id.startsWith("geolibre-marker-svg-")),
);
assert.equal(new Set(imageIds).size, 3);
});
it("creates distinct category sprites when the SVG is supplied by URL", () => {
const value = markerImageValue(
categorizedMarker({
markerShape: "custom",
markerSvg: "https://example.com/tree.svg",
}),
);
assert.ok(Array.isArray(value));
assert.equal(new Set([value[3], value[5], value[6]]).size, 3);
});
it("uses the base marker for invalid expression color outputs", () => {
const value = markerImageValue(
categorizedMarker({
vectorStyleMode: "expression",
vectorStyleExpression: '["match",["get","status"],"good","red","#fde725"]',
}),
);
assert.ok(Array.isArray(value));
assert.equal(value[3], "geolibre-marker-circle-3b82f6-18");
assert.equal(value[4], "geolibre-marker-circle-fde725-18");
});
it("recursively converts colors in zoom-scoped rule expressions", () => {
const value = markerImageValue(
categorizedMarker({
vectorStyleMode: "expression",
vectorStyleExpression:
'["step",["zoom"],["case",["get","selected"],"#339084","#fde725"],10,["case",["get","selected"],"#fde725","#339084"]]',
}),
);
assert.deepEqual(value, [
"step",
["zoom"],
[
"case",
["get", "selected"],
"geolibre-marker-circle-339084-18",
"geolibre-marker-circle-fde725-18",
],
10,
[
"case",
["get", "selected"],
"geolibre-marker-circle-fde725-18",
"geolibre-marker-circle-339084-18",
],
]);
});
it("keeps categorized marker fallback inside a mixed KML icon expression", () => {
const markerImage = markerImageValue(categorizedMarker());
const value = prepareKmlFeatureIcons(
{
type: "FeatureCollection",
features: [
{
type: "Feature",
geometry: { type: "Point", coordinates: [0, 0] },
properties: { [KML_ICON_URL_PROPERTY]: "data:image/png;base64,AA==" },
},
{
type: "Feature",
geometry: { type: "Point", coordinates: [1, 1] },
properties: { status: "good" },
},
],
},
markerImage,
);
assert.ok(Array.isArray(value));
assert.deepEqual(value[value.length - 1], markerImage);
});
});