switch contour lines based on units

This commit is contained in:
vcoppe
2026-05-25 16:50:28 +02:00
parent c758bda1a9
commit 2fdb58bc7d
2 changed files with 142 additions and 65 deletions
+10 -1
View File
@@ -10,7 +10,8 @@ import {
import { getLayers } from '$lib/components/map/layer-control/utils';
import { i18n } from '$lib/i18n.svelte';
const { currentBasemap, currentOverlays, customLayers, opacities, terrainSource } = settings;
const { currentBasemap, currentOverlays, customLayers, opacities, terrainSource, distanceUnits } =
settings;
const emptySource: maplibregl.GeoJSONSourceSpecification = {
type: 'geojson',
@@ -57,6 +58,9 @@ export class StyleManager {
opacities.subscribe(() => this.updateOverlays());
terrainSource.subscribe(() => this.updateTerrain());
customLayers.subscribe(() => this.updateBasemap());
distanceUnits.subscribe(() => {
if (get(currentBasemap) === 'topo') this.updateBasemap();
});
}
updateBasemap() {
@@ -217,7 +221,12 @@ export class StyleManager {
merge(style: maplibregl.StyleSpecification, other: maplibregl.StyleSpecification) {
style.sources = { ...style.sources, ...other.sources };
const units = get(distanceUnits);
for (let layer of other.layers ?? []) {
if ('source' in layer) {
if (layer.source == 'contours_m' && units === 'imperial') continue;
if (layer.source == 'contours_ft' && units !== 'imperial') continue;
}
if (layer.type === 'symbol' && layer.layout && layer.layout['text-field']) {
const textField = layer.layout['text-field'];
if (