diff --git a/components/src/maplibre/VectorLayer/VectorLayer.stories.svelte b/components/src/maplibre/VectorLayer/VectorLayer.stories.svelte index 64d2fab0..bd4989f5 100644 --- a/components/src/maplibre/VectorLayer/VectorLayer.stories.svelte +++ b/components/src/maplibre/VectorLayer/VectorLayer.stories.svelte @@ -10,12 +10,21 @@ import type { GeoJSON } from 'geojson'; import { SWRDataLabLight } from '../MapStyle'; + import type { FilterSpecification } from 'maplibre-gl'; + import { tokens } from '../../DesignTokens'; const { Story } = defineMeta({ title: 'Maplibre/Layer/VectorLayer', component: VectorLayer }); + const filters: FilterSpecification[] = [ + ['<', 'coverage_2025', 1], + ['>', 'coverage_2025', 1] + ]; + + let selectedFilter: any = $state(0); + let hovered: any = $state(); const handleMouseMove = (e) => { hovered = e.features?.[0]; @@ -104,6 +113,14 @@ +
+ + +
@@ -131,4 +148,8 @@ width: 100%; height: 600px; } + .controls { + margin-bottom: 1em; + font-family: monospace; + } diff --git a/components/src/maplibre/VectorLayer/VectorLayer.svelte b/components/src/maplibre/VectorLayer/VectorLayer.svelte index 40ba2873..e375ac38 100644 --- a/components/src/maplibre/VectorLayer/VectorLayer.svelte +++ b/components/src/maplibre/VectorLayer/VectorLayer.svelte @@ -10,7 +10,8 @@ type SymbolLayoutProps, type LinePaintProps, type MapGeoJSONFeature, - type MapLayerMouseEvent + type MapLayerMouseEvent, + type FilterSpecification } from 'maplibre-gl'; import { getMapContext } from '../context.svelte.js'; @@ -24,7 +25,7 @@ /** * Maplibre [filter expression](https://maplibre.org/maplibre-style-spec/layers/#filter) */ - filter?: any[]; + filter?: FilterSpecification; type: 'line' | 'fill' | 'circle' | 'symbol'; placeBelow?: string; visible?: boolean; @@ -91,6 +92,13 @@ } }); + // Make filter reactive + $effect(() => { + if (styleLoaded && filter) { + map?.setFilter(id, filter); + } + }); + $effect(() => resetLayerEventListener(map, 'click', id, onclick)); $effect(() => resetLayerEventListener(map, 'mousemove', id, onmousemove)); $effect(() => resetLayerEventListener(map, 'mouseleave', id, onmouseleave));