demarches-normaliennes/app/javascript/components/shared/maplibre/styles/index.ts

46 lines
998 B
TypeScript
Raw Normal View History

import type { Style } from 'maplibre-gl';
2021-07-01 18:50:35 +02:00
import baseStyle, { buildOptionalLayers, getLayerName, NBS } from './base';
import orthoStyle from './layers/ortho';
import vectorStyle from './layers/vector';
import ignLayers from './layers/ign';
2020-10-15 17:22:08 +02:00
2021-07-01 18:50:35 +02:00
export { getLayerName, NBS };
export type LayersMap = Record<
string,
{
configurable: boolean;
enabled: boolean;
opacity: number;
name: string;
}
>;
export function getMapStyle(
id: string,
layers: string[],
opacity: Record<string, number>
): Style & { id: string } {
const style = { ...baseStyle, id };
2020-10-15 17:22:08 +02:00
switch (id) {
2020-10-15 17:22:08 +02:00
case 'ortho':
style.layers = orthoStyle;
style.name = 'Photographies aériennes';
2020-10-15 17:22:08 +02:00
break;
case 'vector':
style.layers = vectorStyle;
style.name = 'Carte OSM';
2020-10-15 17:22:08 +02:00
break;
case 'ign':
style.layers = ignLayers;
style.name = 'Carte IGN';
2020-10-15 17:22:08 +02:00
break;
}
style.layers = style.layers?.concat(buildOptionalLayers(layers, opacity));
2020-10-15 17:22:08 +02:00
return style;
2020-10-15 17:22:08 +02:00
}