Add Background layer to map.

This is a limited implementation of layer backgrounds. The API
supports an arbitrary number of arbitrarily named background
layers, but for the time being we only recognise one background
layer named `Background` and of GeoJSON type.

Certain properties, such a colour/color, opacity, etc., are
recognised and applied as feature styles. If not, a default
style is used.
This commit is contained in:
D. Berge
2023-09-11 10:17:10 +02:00
parent 36d5862375
commit 0a9bde5f10

View File

@@ -267,6 +267,59 @@ const layers = {
opacity: 0.5
}
}
}),
"Background": L.geoJSON(null,{
style (feature) {
const style = {
stroke: undefined,
color: "grey",
weight: 2,
opacity: 0.5,
lineCap: undefined,
lineJoin: undefined,
dashArray: undefined,
dashOffset: undefined,
fill: undefined,
fillColor: "lightgrey",
fillOpacity: 0.5,
fillRule: undefined
};
for (let key in style) {
switch (key) {
case "color":
style[key] = feature.properties?.colour ?? feature.properties?.color ?? style[key];
break;
case "fillColor":
style[key] = feature.properties?.fillColour ?? feature.properties?.fillColor ?? style[key];
break;
default:
style[key] = feature.properties?.[key] ?? style[key];
}
if (typeof style[key] === "undefined") {
delete style[key];
}
}
return style;
return Object.fromEntries(Object.entries(style).map( ([key, defaultValue]) => {
function value () {
switch (key) {
case "color":
return feature.properties?.colour ?? feature.properties?.color ?? defaultValue;
case "fillColor":
return feature.properties?.fillColour ?? feature.properties?.fillColor ?? defaultValue;
default:
return feature.properties?.[key] ?? defaultValue;
}
}
return [key, value()];
}));
}
})
};
@@ -372,6 +425,12 @@ export default {
? `/project/${this.$route.params.project}/gis/final/line`
: `/project/${this.$route.params.project}/gis/final/point?${query.toString()}`;
}
},
{
layer: layers["Background"],
url: (query = "") => {
return `/project/${this.$route.params.project}/gis/layer/Background`;
}
}
],
labels: {},