feat: add some query params to change behavior

This commit is contained in:
uku 2024-10-21 15:34:58 +02:00
parent 811328dda7
commit 9d471f92a3
Signed by: uku
SSH key fingerprint: SHA256:4P0aN6M8ajKukNi6aPOaX0LacanGYtlfjmN+m/sHY/o

View file

@ -4,6 +4,7 @@
import 'leaflet/dist/leaflet.css';
import lignes from './lignes';
import { page } from '$app/stores';
const bbox = lignes.bbox || [0, 0, 0, 0];
const centerLat = (bbox[1] + bbox[3]) / 2;
@ -14,23 +15,28 @@
const map = L.map('map').setView([centerLat, centerLon], 13);
L.tileLayer(`https://basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png`, {
const params = $page.url.searchParams;
const mapSuffix = params.has('labels') ? 'all' : 'nolabels';
L.tileLayer(`https://basemaps.cartocdn.com/light_${mapSuffix}/{z}/{x}/{y}{r}.png`, {
attribution:
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors &copy; <a href="https://carto.com/attributions">CARTO</a>',
maxZoom: 20
}).addTo(map);
lignes.features.forEach((feature) => {
const options: GeoJSONOptions = {};
if (params.has('lines')) {
lignes.features.forEach((feature) => {
const options: GeoJSONOptions = {};
if (feature.properties && feature.properties.couleur) {
options.style = {
color: 'rgb(' + feature.properties.couleur.replaceAll(' ', ',') + ')'
};
}
if (feature.properties && feature.properties.couleur) {
options.style = {
color: 'rgb(' + feature.properties.couleur.replaceAll(' ', ',') + ')'
};
}
L.geoJSON(feature, options).addTo(map);
});
L.geoJSON(feature, options).addTo(map);
});
}
});
</script>