2024-09-20 18:22:49 +02:00
|
|
|
import type { LayerSpecification, StyleSpecification } from 'maplibre-gl';
|
2022-02-08 12:49:51 +01:00
|
|
|
|
2024-09-20 18:22:49 +02:00
|
|
|
import {
|
|
|
|
style as baseStyle,
|
|
|
|
buildOptionalLayers,
|
|
|
|
getLayerName,
|
|
|
|
NBS
|
|
|
|
} from './base';
|
|
|
|
import ignLayers from './layers/ign.json';
|
|
|
|
import orthoLayers from './layers/ortho.json';
|
|
|
|
import vectorLayers from './layers/vector.json';
|
2020-10-15 17:22:08 +02:00
|
|
|
|
2021-07-01 18:50:35 +02:00
|
|
|
export { getLayerName, NBS };
|
2021-06-30 10:28:02 +02:00
|
|
|
|
2022-02-08 12:49:51 +01:00
|
|
|
export type LayersMap = Record<
|
|
|
|
string,
|
|
|
|
{
|
|
|
|
configurable: boolean;
|
|
|
|
enabled: boolean;
|
|
|
|
opacity: number;
|
|
|
|
name: string;
|
|
|
|
}
|
|
|
|
>;
|
|
|
|
|
|
|
|
export function getMapStyle(
|
|
|
|
id: string,
|
|
|
|
layers: string[],
|
|
|
|
opacity: Record<string, number>
|
2024-09-20 18:22:49 +02:00
|
|
|
): StyleSpecification & { id: string } {
|
2021-05-06 18:51:19 +02:00
|
|
|
const style = { ...baseStyle, id };
|
2020-10-15 17:22:08 +02:00
|
|
|
|
2021-05-06 18:51:19 +02:00
|
|
|
switch (id) {
|
2020-10-15 17:22:08 +02:00
|
|
|
case 'ortho':
|
2024-09-20 18:22:49 +02:00
|
|
|
style.layers = orthoLayers as LayerSpecification[];
|
2021-05-06 18:51:19 +02:00
|
|
|
style.name = 'Photographies aériennes';
|
2020-10-15 17:22:08 +02:00
|
|
|
break;
|
|
|
|
case 'vector':
|
2024-09-20 18:22:49 +02:00
|
|
|
style.layers = vectorLayers as LayerSpecification[];
|
2021-05-06 18:51:19 +02:00
|
|
|
style.name = 'Carte OSM';
|
2020-10-15 17:22:08 +02:00
|
|
|
break;
|
|
|
|
case 'ign':
|
2024-09-20 18:22:49 +02:00
|
|
|
style.layers = ignLayers as LayerSpecification[];
|
2021-05-06 18:51:19 +02:00
|
|
|
style.name = 'Carte IGN';
|
2020-10-15 17:22:08 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-02-08 12:49:51 +01:00
|
|
|
style.layers = style.layers?.concat(buildOptionalLayers(layers, opacity));
|
2020-10-15 17:22:08 +02:00
|
|
|
|
2021-05-06 18:51:19 +02:00
|
|
|
return style;
|
2020-10-15 17:22:08 +02:00
|
|
|
}
|