@geospatial-sdk/legend 0.0.5-dev.58 → 0.0.5-dev.60
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":"from-layer.d.ts","sourceRoot":"","sources":["../../lib/create-legend/from-layer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAIhB,MAAM,sBAAsB,CAAC;AAG9B;;GAEG;AACH,UAAU,aAAa;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;
|
|
1
|
+
{"version":3,"file":"from-layer.d.ts","sourceRoot":"","sources":["../../lib/create-legend/from-layer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAIhB,MAAM,sBAAsB,CAAC;AAG9B;;GAEG;AACH,UAAU,aAAa;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AA+ED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,eAAe,EACtB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAiE7B"}
|
|
@@ -16,6 +16,7 @@ function createWmsLegendUrl(layer, options = {}) {
|
|
|
16
16
|
"LAYER",
|
|
17
17
|
"LAYERTITLE",
|
|
18
18
|
"SLD_VERSION",
|
|
19
|
+
"STYLE",
|
|
19
20
|
"WIDTH",
|
|
20
21
|
"HEIGHT",
|
|
21
22
|
]));
|
|
@@ -25,6 +26,9 @@ function createWmsLegendUrl(layer, options = {}) {
|
|
|
25
26
|
legendUrl.searchParams.set("LAYER", layer.name);
|
|
26
27
|
legendUrl.searchParams.set("LAYERTITLE", false.toString()); // Disable layer title for QGIS Server
|
|
27
28
|
legendUrl.searchParams.set("SLD_VERSION", "1.1.0"); // Default SLD version
|
|
29
|
+
if (layer.style !== undefined) {
|
|
30
|
+
legendUrl.searchParams.set("STYLE", layer.style);
|
|
31
|
+
}
|
|
28
32
|
if (widthPxHint) {
|
|
29
33
|
legendUrl.searchParams.set("WIDTH", widthPxHint.toString());
|
|
30
34
|
}
|
|
@@ -42,10 +46,18 @@ function createWmsLegendUrl(layer, options = {}) {
|
|
|
42
46
|
async function createWmtsLegendUrl(layer) {
|
|
43
47
|
const endpoint = await new WmtsEndpoint(layer.url).isReady();
|
|
44
48
|
const layerByName = endpoint.getLayerByName(layer.name);
|
|
45
|
-
if (layerByName.styles &&
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
if (layerByName.styles && layerByName.styles.length > 0) {
|
|
50
|
+
// If a specific style is requested, find its legend URL
|
|
51
|
+
if (layer.style !== undefined) {
|
|
52
|
+
const matchingStyle = layerByName.styles.find((s) => s.name === layer.style);
|
|
53
|
+
if (matchingStyle?.legendUrl) {
|
|
54
|
+
return matchingStyle.legendUrl;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Fall back to the first style's legend URL
|
|
58
|
+
if (layerByName.styles[0].legendUrl) {
|
|
59
|
+
return layerByName.styles[0].legendUrl;
|
|
60
|
+
}
|
|
49
61
|
}
|
|
50
62
|
return null;
|
|
51
63
|
}
|
|
@@ -56,6 +56,17 @@ describe("createLegendFromLayer", () => {
|
|
|
56
56
|
expect(img?.src).toContain("HEIGHT=100");
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
+
it("includes STYLE parameter in WMS legend URL when layer has a style", async () => {
|
|
60
|
+
const result = await createLegendFromLayer({
|
|
61
|
+
...baseWmsLayer,
|
|
62
|
+
style: "my_custom_style",
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const img = (result as HTMLElement).querySelector("img");
|
|
66
|
+
|
|
67
|
+
expect(img?.src).toContain("STYLE=my_custom_style");
|
|
68
|
+
});
|
|
69
|
+
|
|
59
70
|
it("creates a legend for a valid WMTS layer with legend URL", async () => {
|
|
60
71
|
const mockLegendUrl = "https://example.com/legend.png";
|
|
61
72
|
const mockIsReady = {
|
|
@@ -98,6 +109,32 @@ describe("createLegendFromLayer", () => {
|
|
|
98
109
|
);
|
|
99
110
|
});
|
|
100
111
|
|
|
112
|
+
it("uses matching style legend URL for WMTS layer when layer.style is set", async () => {
|
|
113
|
+
const mockIsReady = {
|
|
114
|
+
getLayerByName: () => ({
|
|
115
|
+
styles: [
|
|
116
|
+
{
|
|
117
|
+
name: "default",
|
|
118
|
+
legendUrl: "https://example.com/default-legend.png",
|
|
119
|
+
},
|
|
120
|
+
{ name: "night", legendUrl: "https://example.com/night-legend.png" },
|
|
121
|
+
],
|
|
122
|
+
}),
|
|
123
|
+
} as unknown as WmtsEndpoint;
|
|
124
|
+
|
|
125
|
+
vi.spyOn(WmtsEndpoint.prototype, "isReady").mockImplementation(function () {
|
|
126
|
+
return Promise.resolve(mockIsReady);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const result = await createLegendFromLayer({
|
|
130
|
+
...baseWmtsLayer,
|
|
131
|
+
style: "night",
|
|
132
|
+
});
|
|
133
|
+
const img = (result as HTMLElement).querySelector("img");
|
|
134
|
+
|
|
135
|
+
expect(img?.src).toBe("https://example.com/night-legend.png");
|
|
136
|
+
});
|
|
137
|
+
|
|
101
138
|
it("returns null for invalid layer type", async () => {
|
|
102
139
|
const invalidLayer = { ...baseWmsLayer, type: "invalid" as any };
|
|
103
140
|
|
|
@@ -36,6 +36,7 @@ function createWmsLegendUrl(
|
|
|
36
36
|
"LAYER",
|
|
37
37
|
"LAYERTITLE",
|
|
38
38
|
"SLD_VERSION",
|
|
39
|
+
"STYLE",
|
|
39
40
|
"WIDTH",
|
|
40
41
|
"HEIGHT",
|
|
41
42
|
]),
|
|
@@ -46,7 +47,9 @@ function createWmsLegendUrl(
|
|
|
46
47
|
legendUrl.searchParams.set("LAYER", layer.name);
|
|
47
48
|
legendUrl.searchParams.set("LAYERTITLE", false.toString()); // Disable layer title for QGIS Server
|
|
48
49
|
legendUrl.searchParams.set("SLD_VERSION", "1.1.0"); // Default SLD version
|
|
49
|
-
|
|
50
|
+
if (layer.style !== undefined) {
|
|
51
|
+
legendUrl.searchParams.set("STYLE", layer.style);
|
|
52
|
+
}
|
|
50
53
|
if (widthPxHint) {
|
|
51
54
|
legendUrl.searchParams.set("WIDTH", widthPxHint.toString());
|
|
52
55
|
}
|
|
@@ -70,12 +73,20 @@ async function createWmtsLegendUrl(
|
|
|
70
73
|
|
|
71
74
|
const layerByName = endpoint.getLayerByName(layer.name);
|
|
72
75
|
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
if (layerByName.styles && layerByName.styles.length > 0) {
|
|
77
|
+
// If a specific style is requested, find its legend URL
|
|
78
|
+
if (layer.style !== undefined) {
|
|
79
|
+
const matchingStyle = layerByName.styles.find(
|
|
80
|
+
(s: { name?: string }) => s.name === layer.style,
|
|
81
|
+
);
|
|
82
|
+
if (matchingStyle?.legendUrl) {
|
|
83
|
+
return matchingStyle.legendUrl;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Fall back to the first style's legend URL
|
|
87
|
+
if (layerByName.styles[0].legendUrl) {
|
|
88
|
+
return layerByName.styles[0].legendUrl;
|
|
89
|
+
}
|
|
79
90
|
}
|
|
80
91
|
|
|
81
92
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geospatial-sdk/legend",
|
|
3
|
-
"version": "0.0.5-dev.
|
|
3
|
+
"version": "0.0.5-dev.60+f826933",
|
|
4
4
|
"description": "Get legend graphic from the map-context",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"legend"
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"build": "tsc"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@geospatial-sdk/core": "^0.0.5-dev.
|
|
33
|
+
"@geospatial-sdk/core": "^0.0.5-dev.60+f826933"
|
|
34
34
|
},
|
|
35
35
|
"bugs": {
|
|
36
36
|
"url": "https://github.com/camptocamp/geospatial-sdk/issues"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "f8269338a04fb473cb6a467a12d2cddad89e6b98"
|
|
39
39
|
}
|