demarches-normaliennes/app/javascript/components/MapStyles/index.js

56 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-07-29 15:27:08 +02:00
import baseStyle from './base-style';
import cadastre from './cadastre';
import orthoStyle from './ortho-style';
import vectorStyle from './vector-style';
function rasterStyle(source) {
return {
id: source,
source,
2020-07-29 15:27:08 +02:00
type: 'raster',
paint: { 'raster-resampling': 'linear' }
};
}
export function getMapStyle(style, hasCadastres, hasMNHN) {
2020-07-29 15:27:08 +02:00
const mapStyle = { ...baseStyle };
switch (style) {
case 'ortho':
mapStyle.layers = orthoStyle;
mapStyle.id = 'ortho';
mapStyle.name = 'Photographies aériennes';
break;
case 'vector':
mapStyle.layers = vectorStyle;
mapStyle.id = 'vector';
mapStyle.name = 'Carte OSM';
break;
case 'ign':
mapStyle.layers = [rasterStyle('plan-ign')];
2020-07-29 15:27:08 +02:00
mapStyle.id = 'ign';
mapStyle.name = 'Carte IGN';
break;
}
if (hasCadastres) {
2020-07-29 15:27:08 +02:00
mapStyle.layers = mapStyle.layers.concat(cadastre);
mapStyle.id += '-cadastre';
}
2020-07-29 15:27:08 +02:00
if (hasMNHN) {
mapStyle.layers = mapStyle.layers.concat([
rasterStyle('protectedareas-gp'),
rasterStyle('protectedareas-pn'),
rasterStyle('protectedareas-pnr'),
rasterStyle('protectedareas-sic'),
rasterStyle('protectedareas-zps')
]);
mapStyle.id += '-mnhn';
}
2020-07-29 15:27:08 +02:00
return mapStyle;
}
2020-07-29 15:27:08 +02:00
export { SwitchMapStyle } from './SwitchMapStyle';