diff --git a/components/src/maplibre/MapStyle/SWRDataLabDark.ts b/components/src/maplibre/MapStyle/SWRDataLabDark.ts index bb7f8319..2427a45f 100644 --- a/components/src/maplibre/MapStyle/SWRDataLabDark.ts +++ b/components/src/maplibre/MapStyle/SWRDataLabDark.ts @@ -51,7 +51,6 @@ const tokens = { const { landuse } = makeLanduse(tokens); const { placeLabels, boundaryLabels } = makePlaceLabels(tokens); -const { admin } = makeAdmin(tokens); const { airports, transitBridges, transitSurface, transitTunnels } = makeTransit(tokens); const { walkingLabels, walkingTunnels, walkingSurface, walkingBridges } = makeWalking(tokens); const { roadLabels, roadBridges, roadSurface, roadTunnels } = makeRoads(tokens); @@ -68,6 +67,8 @@ const style: styleFunction = (opts) => { ...opts } as StyleOptions; + const { admin } = makeAdmin(tokens, options?.admin); + return { version: 8, name: 'swr-datalab-dark', diff --git a/components/src/maplibre/MapStyle/SWRDataLabLight.mdx b/components/src/maplibre/MapStyle/SWRDataLabLight.mdx index 78c07559..8282f853 100644 --- a/components/src/maplibre/MapStyle/SWRDataLabLight.mdx +++ b/components/src/maplibre/MapStyle/SWRDataLabLight.mdx @@ -94,9 +94,14 @@ interface StyleOptions { places?: { showLabels?: boolean } + admin?: { + show?: boolean | []AdminLevel + } } ``` +- `AdminLevel` is an integer representing an admin level; the relevant levels [for Germany](https://wiki.openstreetmap.org/wiki/Tag:boundary%3Dadministrative#Country_specific_values_of_the_key_admin_level=*) are country (`2`) and bundesland (`4`). + ## Icons export const customIcons = ['pin-14', 'pin-14-dark']; diff --git a/components/src/maplibre/MapStyle/SWRDataLabLight.stories.svelte b/components/src/maplibre/MapStyle/SWRDataLabLight.stories.svelte index 4220cc4c..90686e67 100644 --- a/components/src/maplibre/MapStyle/SWRDataLabLight.stories.svelte +++ b/components/src/maplibre/MapStyle/SWRDataLabLight.stories.svelte @@ -44,6 +44,26 @@ + + +
+
+ + + +
+
+
+
diff --git a/components/src/maplibre/MapStyle/SWRDataLabLight.ts b/components/src/maplibre/MapStyle/SWRDataLabLight.ts index 45b206df..91541c9e 100644 --- a/components/src/maplibre/MapStyle/SWRDataLabLight.ts +++ b/components/src/maplibre/MapStyle/SWRDataLabLight.ts @@ -50,7 +50,6 @@ const tokens = { const { landuse } = makeLanduse(tokens); const { placeLabels, boundaryLabels } = makePlaceLabels(tokens); -const { admin } = makeAdmin(tokens); const { airports, transitBridges, transitSurface, transitTunnels } = makeTransit(tokens); const { walkingLabels, walkingTunnels, walkingSurface, walkingBridges } = makeWalking(tokens); const { roadLabels, roadBridges, roadSurface, roadTunnels } = makeRoads(tokens); @@ -67,6 +66,8 @@ const style: styleFunction = (opts) => { ...opts } as StyleOptions; + const { admin } = makeAdmin(tokens, options?.admin); + return { version: 8, name: 'swr-datalab-light', diff --git a/components/src/maplibre/MapStyle/components/Admin.ts b/components/src/maplibre/MapStyle/components/Admin.ts index 5e0de2a2..e1ec05d1 100644 --- a/components/src/maplibre/MapStyle/components/Admin.ts +++ b/components/src/maplibre/MapStyle/components/Admin.ts @@ -1,6 +1,6 @@ import { type Layer } from '../../types'; -export default function makeAdmin(tokens): any { +export default function makeAdmin(tokens, options): any { const admin: Layer[] = [ { id: 'boundary-country:case', @@ -134,18 +134,32 @@ export default function makeAdmin(tokens): any { } } } - ].map((el) => { - return { - source: 'versatiles-osm', - 'source-layer': 'boundaries', - type: 'line', - ...el, - layout: { - 'line-cap': 'round', - 'line-join': 'round' + ] + .filter((el) => { + if (!options || options.show === true) { + return true; + } else if (options.show === false) { + return false; + } else { + return ( + (el.id.includes('country') && options.show.includes(2)) || + (el.id.includes('state') && options.show.includes(4)) + ); } - } as Layer; - }); + return false; + }) + .map((el) => { + return { + source: 'versatiles-osm', + 'source-layer': 'boundaries', + type: 'line', + ...el, + layout: { + 'line-cap': 'round', + 'line-join': 'round' + } + } as Layer; + }); return { admin }; } diff --git a/components/src/maplibre/MapStyle/defaultOptions.ts b/components/src/maplibre/MapStyle/defaultOptions.ts index 57ae17b7..77800ca5 100644 --- a/components/src/maplibre/MapStyle/defaultOptions.ts +++ b/components/src/maplibre/MapStyle/defaultOptions.ts @@ -7,6 +7,9 @@ const opts: StyleOptions = { }, roads: { showLabels: true + }, + admin: { + show: true } }; diff --git a/components/src/maplibre/MapStyle/types.ts b/components/src/maplibre/MapStyle/types.ts index 3b610049..c8251dab 100644 --- a/components/src/maplibre/MapStyle/types.ts +++ b/components/src/maplibre/MapStyle/types.ts @@ -1,9 +1,16 @@ +enum AdminLevel { + COUNTRY = 2, + BUNDESLAND = 4 +} interface StyleOptions { enableBuildingExtrusions?: boolean; enableHillshade?: boolean; places?: { showLabels?: boolean; }; + admin?: { + show?: boolean | AdminLevel[]; + }; roads?: { showLabels?: boolean; };