mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:57:08 +00:00
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:
@@ -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: {},
|
||||
|
||||
Reference in New Issue
Block a user