From 39f5642951b5607b5de0af918ed7e90f0735fde6 Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Wed, 20 Nov 2024 08:40:48 -0600 Subject: [PATCH 01/13] query source features --- app/src/app/utils/helpers.ts | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/app/src/app/utils/helpers.ts b/app/src/app/utils/helpers.ts index 3f4b44dd..f5e01689 100644 --- a/app/src/app/utils/helpers.ts +++ b/app/src/app/utils/helpers.ts @@ -133,16 +133,30 @@ export const getFeaturesIntersectingCounties = ( if (!countyFeatures?.length) return; const fips = countyFeatures[0].properties.STATEFP + countyFeatures[0].properties.COUNTYFP; - - const features = map.queryRenderedFeatures(undefined, { - layers, - }); - - return filterFeatures( - features, - true, - [(feature) => Boolean(feature?.id && feature.id.toString().match(/\d{5}/)?.[0] === fips)] - ); + const {mapDocument, shatterIds} = useMapStore.getState(); + + const sourceFeatures = map.querySourceFeatures(BLOCK_SOURCE_ID, { + sourceLayer: mapDocument?.parent_layer, + }).map(feature => ({ + ...feature, + source: BLOCK_SOURCE_ID, + sourceLayer: mapDocument?.parent_layer + })) + + const childFeatures = shatterIds.children.size + ? (Array.from(shatterIds.children).map(id => ({ + id, + source: BLOCK_SOURCE_ID, + sourceLayer: mapDocument?.child_layer + })) as any) + : []; + + return filterFeatures([ + ...sourceFeatures, + ...childFeatures + ], true, [ + feature => Boolean(feature?.id && feature.id.toString().match(/\d{5}/)?.[0] === fips), + ]); }; /** From 06901ae928384fb21c94fbe303f0656827a931db Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Wed, 20 Nov 2024 09:37:45 -0600 Subject: [PATCH 02/13] trying out cache Ids --- app/src/app/components/Map.tsx | 21 +++++++++++++++++++++ app/src/app/store/idCache.ts | 25 +++++++++++++++++++++++++ app/src/app/utils/helpers.ts | 21 ++++++++------------- 3 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 app/src/app/store/idCache.ts diff --git a/app/src/app/components/Map.tsx b/app/src/app/components/Map.tsx index 908a7066..19158742 100644 --- a/app/src/app/components/Map.tsx +++ b/app/src/app/components/Map.tsx @@ -8,6 +8,7 @@ import {MAP_OPTIONS} from '../constants/configuration'; import {mapEvents} from '../utils/events/mapEvents'; import {INTERACTIVE_LAYERS} from '../constants/layers'; import {useMapStore} from '../store/mapStore'; +import { parentIdCache } from '../store/idCache'; export const MapComponent: React.FC = () => { const map: MutableRefObject = useRef(null); @@ -45,6 +46,25 @@ export const MapComponent: React.FC = () => { zoom: MAP_OPTIONS.zoom, maxZoom: MAP_OPTIONS.maxZoom, }); + + map.current.on('data', (event) => { + const {tiles_s3_path, parent_layer} = useMapStore.getState().mapDocument || {} + if (!tiles_s3_path || event.dataType !== 'source' || !event?.source?.url?.includes(tiles_s3_path)) return + + const tileData = event?.tile?.latestFeatureIndex + if (!tileData) return + + const index = `${tileData.x}-${tileData.y}-${tileData.z}` + if (parentIdCache.hasCached(index)) return + + + const vtLayers = tileData.loadVTLayers() + const parentLayerData = vtLayers[parent_layer] + const numFeatures = parentLayerData?.length + const featureDataArray = parentLayerData?._values + parentIdCache.add(index, featureDataArray.slice(-numFeatures,)) + }); + fitMapToBounds(); map.current.scrollZoom.setWheelZoomRate(1 / 300); map.current.scrollZoom.setZoomRate(1 / 300); @@ -86,3 +106,4 @@ export const MapComponent: React.FC = () => { /> ); }; + diff --git a/app/src/app/store/idCache.ts b/app/src/app/store/idCache.ts new file mode 100644 index 00000000..d8b004f8 --- /dev/null +++ b/app/src/app/store/idCache.ts @@ -0,0 +1,25 @@ + +class IdCache { + cachedTileIndices: Set = new Set() + parentIds: Set = new Set() + + hasCached(index: string){ + return this.cachedTileIndices.has(index) + } + + add(index: string, ids: string[]){ + this.cachedTileIndices.add(index) + ids.forEach(id => this.parentIds.add(id)) + } + + clear(){ + this.parentIds.clear() + this.cachedTileIndices.clear() + } + + getFilteredIds(id: string){ + return Array.from(this.parentIds).filter(f => f.startsWith(id)) + } +} + +export const parentIdCache = new IdCache() diff --git a/app/src/app/utils/helpers.ts b/app/src/app/utils/helpers.ts index f5e01689..e3fdf36d 100644 --- a/app/src/app/utils/helpers.ts +++ b/app/src/app/utils/helpers.ts @@ -15,6 +15,7 @@ import { } from '@/app/constants/layers'; import {MapStore, useMapStore} from '../store/mapStore'; import {NullableZone} from '../constants/types'; +import {parentIdCache} from '../store/idCache'; /** * PaintEventHandler @@ -134,27 +135,21 @@ export const getFeaturesIntersectingCounties = ( if (!countyFeatures?.length) return; const fips = countyFeatures[0].properties.STATEFP + countyFeatures[0].properties.COUNTYFP; const {mapDocument, shatterIds} = useMapStore.getState(); - - const sourceFeatures = map.querySourceFeatures(BLOCK_SOURCE_ID, { - sourceLayer: mapDocument?.parent_layer, - }).map(feature => ({ - ...feature, + const cachedParentFeatures = parentIdCache.getFilteredIds(`vtd:${fips}`).map(id => ({ + id, source: BLOCK_SOURCE_ID, - sourceLayer: mapDocument?.parent_layer - })) - + sourceLayer: mapDocument?.parent_layer, + })); + const childFeatures = shatterIds.children.size ? (Array.from(shatterIds.children).map(id => ({ id, source: BLOCK_SOURCE_ID, - sourceLayer: mapDocument?.child_layer + sourceLayer: mapDocument?.child_layer, })) as any) : []; - return filterFeatures([ - ...sourceFeatures, - ...childFeatures - ], true, [ + return filterFeatures([...cachedParentFeatures, ...childFeatures], true, [ feature => Boolean(feature?.id && feature.id.toString().match(/\d{5}/)?.[0] === fips), ]); }; From 62ab7a7dc920c28efddede8d3868726e1490778a Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Wed, 20 Nov 2024 09:42:46 -0600 Subject: [PATCH 03/13] Clear cache on document change --- app/src/app/store/mapStore.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/app/store/mapStore.ts b/app/src/app/store/mapStore.ts index d1864251..8d6335b4 100644 --- a/app/src/app/store/mapStore.ts +++ b/app/src/app/store/mapStore.ts @@ -36,6 +36,7 @@ import {BLOCK_SOURCE_ID} from '../constants/layers'; import {DistrictrMapOptions} from './types'; import {onlyUnique} from '../utils/arrays'; import {queryClient} from '../utils/api/queryClient'; +import { parentIdCache } from './idCache'; const combineSetValues = (setRecord: Record>, keys?: string[]) => { const combinedSet = new Set(); // Create a new set to hold combined values @@ -383,6 +384,7 @@ export const useMapStore = create( if (currentMapDocument?.document_id === mapDocument.document_id) { return; } + parentIdCache.clear() setFreshMap(true); resetZoneAssignments(); upsertUserMap({mapDocument}); From 310b000812542bd6fd37fd5fe2d743a5fc85effc Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Wed, 20 Nov 2024 09:48:40 -0600 Subject: [PATCH 04/13] clean up types and safety --- app/src/app/components/Map.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/app/components/Map.tsx b/app/src/app/components/Map.tsx index 19158742..3a013768 100644 --- a/app/src/app/components/Map.tsx +++ b/app/src/app/components/Map.tsx @@ -47,11 +47,11 @@ export const MapComponent: React.FC = () => { maxZoom: MAP_OPTIONS.maxZoom, }); - map.current.on('data', (event) => { + map.current.on('data', (event: any) => { const {tiles_s3_path, parent_layer} = useMapStore.getState().mapDocument || {} - if (!tiles_s3_path || event.dataType !== 'source' || !event?.source?.url?.includes(tiles_s3_path)) return + if (!tiles_s3_path || !parent_layer || event.dataType !== 'source' || !event?.source?.url?.includes(tiles_s3_path)) return - const tileData = event?.tile?.latestFeatureIndex + const tileData = event?.tile?.latestFeatureIndex; if (!tileData) return const index = `${tileData.x}-${tileData.y}-${tileData.z}` @@ -64,7 +64,7 @@ export const MapComponent: React.FC = () => { const featureDataArray = parentLayerData?._values parentIdCache.add(index, featureDataArray.slice(-numFeatures,)) }); - + fitMapToBounds(); map.current.scrollZoom.setWheelZoomRate(1 / 300); map.current.scrollZoom.setZoomRate(1 / 300); From de13cfc9c1d7e91dba748714ebd428a1e85812c9 Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Wed, 20 Nov 2024 10:08:47 -0600 Subject: [PATCH 05/13] prefix if VTDs --- app/src/app/utils/helpers.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/app/utils/helpers.ts b/app/src/app/utils/helpers.ts index e3fdf36d..a997a649 100644 --- a/app/src/app/utils/helpers.ts +++ b/app/src/app/utils/helpers.ts @@ -135,7 +135,8 @@ export const getFeaturesIntersectingCounties = ( if (!countyFeatures?.length) return; const fips = countyFeatures[0].properties.STATEFP + countyFeatures[0].properties.COUNTYFP; const {mapDocument, shatterIds} = useMapStore.getState(); - const cachedParentFeatures = parentIdCache.getFilteredIds(`vtd:${fips}`).map(id => ({ + const filterPrefix = mapDocument?.parent_layer.includes("vtd") ? "vtd:" : "" + const cachedParentFeatures = parentIdCache.getFilteredIds(`${filterPrefix}${fips}`).map(id => ({ id, source: BLOCK_SOURCE_ID, sourceLayer: mapDocument?.parent_layer, From 0d812b403a85179150483541f1951f0d69dc54c2 Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Wed, 20 Nov 2024 10:21:22 -0600 Subject: [PATCH 06/13] move paint by county to store --- .../app/components/sidebar/PaintByCounty.tsx | 17 ++++++++++------- app/src/app/store/types.ts | 1 + 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/app/components/sidebar/PaintByCounty.tsx b/app/src/app/components/sidebar/PaintByCounty.tsx index 88e72afa..78c72c93 100644 --- a/app/src/app/components/sidebar/PaintByCounty.tsx +++ b/app/src/app/components/sidebar/PaintByCounty.tsx @@ -8,12 +8,15 @@ export default function PaintByCounty() { const mapRef = useMapStore(state => state.getMapRef()); const addVisibleLayerIds = useMapStore(state => state.addVisibleLayerIds); const setPaintFunction = useMapStore(state => state.setPaintFunction); - const [checked, setChecked] = useState(false); + const paintByCounty = useMapStore(state => state.mapOptions.paintByCounty) + const setMapOptions = useMapStore(state => state.setMapOptions) - useEffect(() => { + const handleToggle = () => { if (!mapRef) return; - - if (checked) { + setMapOptions({ + paintByCounty: !paintByCounty + }) + if (!paintByCounty) { COUNTY_LAYER_IDS.forEach(layerId => { mapRef.setLayoutProperty(layerId, 'visibility', 'visible'); }); @@ -22,16 +25,16 @@ export default function PaintByCounty() { } else { setPaintFunction(getFeaturesInBbox); } - }, [checked, mapRef, addVisibleLayerIds]); + } return ( setChecked(prevIsChecked => !prevIsChecked)} + onClick={handleToggle} /> Paint by County diff --git a/app/src/app/store/types.ts b/app/src/app/store/types.ts index 47ad70c5..08706d72 100644 --- a/app/src/app/store/types.ts +++ b/app/src/app/store/types.ts @@ -5,4 +5,5 @@ export type DistrictrMapOptions = { higlightUnassigned?: boolean; lockPaintedAreas: boolean | Array; mode: 'default' | 'break'; + paintByCounty?: boolean }; From a620c89a0ad102fdec912e3206e0a0f533007ffc Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Wed, 20 Nov 2024 10:25:33 -0600 Subject: [PATCH 07/13] set paint function correctly --- app/src/app/store/mapRenderSubs.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/app/store/mapRenderSubs.ts b/app/src/app/store/mapRenderSubs.ts index 2a1a98b5..858ad5d5 100644 --- a/app/src/app/store/mapRenderSubs.ts +++ b/app/src/app/store/mapRenderSubs.ts @@ -15,6 +15,8 @@ import { import { ColorZoneAssignmentsState, colorZoneAssignments, + getFeaturesInBbox, + getFeaturesIntersectingCounties, shallowCompareArray, } from '../utils/helpers'; import {useMapStore as _useMapStore, MapStore} from '@store/mapStore'; @@ -222,16 +224,21 @@ export const getRenderSubscriptions = (useMapStore: typeof _useMapStore) => { activeTool => { const mapRef = useMapStore.getState().getMapRef(); if (!mapRef) return; + const mapOptions = useMapStore.getState().mapOptions + const defaultPaintFunction = mapOptions.paintByCounty ? getFeaturesIntersectingCounties : getFeaturesInBbox let cursor; switch (activeTool) { case 'pan': cursor = ''; + useMapStore.getState().setPaintFunction(defaultPaintFunction); break; case 'brush': cursor = 'pointer'; + useMapStore.getState().setPaintFunction(defaultPaintFunction); break; case 'eraser': cursor = 'pointer'; + useMapStore.getState().setPaintFunction(defaultPaintFunction); break; case 'shatter': cursor = 'crosshair'; From 1c65a833beb007199a70c4adad027f88125c0e8b Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Wed, 20 Nov 2024 14:40:11 -0600 Subject: [PATCH 08/13] regex instead of string methods --- app/src/app/store/idCache.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/app/store/idCache.ts b/app/src/app/store/idCache.ts index d8b004f8..e039ae11 100644 --- a/app/src/app/store/idCache.ts +++ b/app/src/app/store/idCache.ts @@ -1,4 +1,3 @@ - class IdCache { cachedTileIndices: Set = new Set() parentIds: Set = new Set() @@ -18,7 +17,8 @@ class IdCache { } getFilteredIds(id: string){ - return Array.from(this.parentIds).filter(f => f.startsWith(id)) + const regex = new RegExp(`^${id}`); + return Array.from(this.parentIds).filter(f => regex.test(f)); } } From f0b0df6ed6aaf00f7a10188fbd6b9d9ff0d26ea6 Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Wed, 20 Nov 2024 14:40:22 -0600 Subject: [PATCH 09/13] refactor to map events --- app/src/app/components/Map.tsx | 18 --------------- app/src/app/utils/events/mapEvents.ts | 32 ++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/app/src/app/components/Map.tsx b/app/src/app/components/Map.tsx index 3a013768..21128979 100644 --- a/app/src/app/components/Map.tsx +++ b/app/src/app/components/Map.tsx @@ -47,24 +47,6 @@ export const MapComponent: React.FC = () => { maxZoom: MAP_OPTIONS.maxZoom, }); - map.current.on('data', (event: any) => { - const {tiles_s3_path, parent_layer} = useMapStore.getState().mapDocument || {} - if (!tiles_s3_path || !parent_layer || event.dataType !== 'source' || !event?.source?.url?.includes(tiles_s3_path)) return - - const tileData = event?.tile?.latestFeatureIndex; - if (!tileData) return - - const index = `${tileData.x}-${tileData.y}-${tileData.z}` - if (parentIdCache.hasCached(index)) return - - - const vtLayers = tileData.loadVTLayers() - const parentLayerData = vtLayers[parent_layer] - const numFeatures = parentLayerData?.length - const featureDataArray = parentLayerData?._values - parentIdCache.add(index, featureDataArray.slice(-numFeatures,)) - }); - fitMapToBounds(); map.current.scrollZoom.setWheelZoomRate(1 / 300); map.current.scrollZoom.setZoomRate(1 / 300); diff --git a/app/src/app/utils/events/mapEvents.ts b/app/src/app/utils/events/mapEvents.ts index 93b3f319..e4bc3a35 100644 --- a/app/src/app/utils/events/mapEvents.ts +++ b/app/src/app/utils/events/mapEvents.ts @@ -2,7 +2,7 @@ Port over from map events declared at: https://github.com/uchicago-dsi/districtr-components/blob/2e8f9e5657b9f0fd2419b6f3258efd74ae310f32/src/Districtr/Districtr.tsx#L230 */ 'use client'; -import type {Map as MapLibreMap, MapLayerMouseEvent, MapLayerTouchEvent} from 'maplibre-gl'; +import type {Map as MapLibreMap, MapLayerMouseEvent, MapLayerTouchEvent, MapDataEvent, MapSourceDataEvent} from 'maplibre-gl'; import {useMapStore} from '@/app/store/mapStore'; import { BLOCK_HOVER_LAYER_ID, @@ -11,6 +11,7 @@ import { } from '@/app/constants/layers'; import {ResetMapSelectState} from '@utils/events/handlers'; import {ActiveTool} from '@/app/constants/types'; +import { parentIdCache } from '@/app/store/idCache'; /* MapEvent handling; these functions are called by the event listeners in the MapComponent @@ -227,6 +228,34 @@ export const handleMapContextMenu = ( }); }; +export const handleIdCache = ( + _e: MapLayerMouseEvent | MapLayerTouchEvent, + map: MapLibreMap | null +) => { + const e = _e as unknown as MapSourceDataEvent + const {tiles_s3_path, parent_layer} = useMapStore.getState().mapDocument || {} + + if ( + !tiles_s3_path || + !parent_layer || + e.dataType !== 'source' || + !("url" in e.source) || + !e.source.url?.includes(tiles_s3_path) + ) return + + const tileData = e.tile.latestFeatureIndex; + if (!tileData) return + + const index = `${tileData.x}-${tileData.y}-${tileData.z}` + if (parentIdCache.hasCached(index)) return + const vtLayers = tileData.loadVTLayers() + + const parentLayerData = vtLayers[parent_layer] + const numFeatures = parentLayerData.length + const featureDataArray = parentLayerData._values + parentIdCache.add(index, featureDataArray.slice(-numFeatures,)) +} + export const mapEvents = [ {action: 'click', handler: handleMapClick}, {action: 'mouseup', handler: handleMapMouseUp}, @@ -246,4 +275,5 @@ export const mapEvents = [ {action: 'moveend', handler: handleMapMoveEnd}, {action: 'zoomend', handler: handleMapZoomEnd}, {action: 'contextmenu', handler: handleMapContextMenu}, + {action: 'data', handler: handleIdCache} ]; From 632a4b71605e0b3872ecc32a50ebc9135408eb04 Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Thu, 21 Nov 2024 07:44:47 -0600 Subject: [PATCH 10/13] Filter counties on STATEFP --- app/src/app/constants/layers.ts | 1 + app/src/app/store/mapRenderSubs.ts | 14 ++++++++++++++ app/src/app/store/types.ts | 3 ++- app/src/app/utils/events/mapEvents.ts | 6 +++++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/src/app/constants/layers.ts b/app/src/app/constants/layers.ts index 27acb445..8c4cd675 100644 --- a/app/src/app/constants/layers.ts +++ b/app/src/app/constants/layers.ts @@ -23,6 +23,7 @@ export const INTERACTIVE_LAYERS = [BLOCK_HOVER_LAYER_ID, BLOCK_HOVER_LAYER_ID_CH export const LINE_LAYERS = [BLOCK_LAYER_ID, BLOCK_LAYER_ID_CHILD] as const export const PARENT_LAYERS = [BLOCK_LAYER_ID, BLOCK_HOVER_LAYER_ID]; +export const COUNTY_LAYERS = ['counties_fill', 'counties_boundary','counties_label'] export const CHILD_LAYERS = [ BLOCK_LAYER_ID_CHILD, diff --git a/app/src/app/store/mapRenderSubs.ts b/app/src/app/store/mapRenderSubs.ts index 858ad5d5..e4a661cd 100644 --- a/app/src/app/store/mapRenderSubs.ts +++ b/app/src/app/store/mapRenderSubs.ts @@ -11,6 +11,7 @@ import { BLOCK_LAYER_ID_HIGHLIGHT, getHighlightLayerSpecification, BLOCK_LAYER_ID_HIGHLIGHT_CHILD, + COUNTY_LAYERS, } from '../constants/layers'; import { ColorZoneAssignmentsState, @@ -310,6 +311,18 @@ export const getRenderSubscriptions = (useMapStore: typeof _useMapStore) => { } } ); + + const filterCountiesSub = useMapStore.subscribe<[string|undefined, MapStore['getMapRef']]>(state => [state.mapOptions.currentStateFp, state.getMapRef], + ([stateFp, getMapRef]) => { + const mapRef = getMapRef() + if (!mapRef) return + const filterExpression = (stateFp ? ["==", "STATEFP", stateFp] : true) as any + COUNTY_LAYERS.forEach(layer => { + mapRef.setFilter(layer, ["any", filterExpression]) + }) + } + ) + return [ addLayerSubMapDocument, _shatterMapSideEffectRender, @@ -318,5 +331,6 @@ export const getRenderSubscriptions = (useMapStore: typeof _useMapStore) => { _updateMapCursor, _applyFocusFeatureState, highlightUnassignedSub, + filterCountiesSub ]; }; diff --git a/app/src/app/store/types.ts b/app/src/app/store/types.ts index 08706d72..1f38e3bd 100644 --- a/app/src/app/store/types.ts +++ b/app/src/app/store/types.ts @@ -5,5 +5,6 @@ export type DistrictrMapOptions = { higlightUnassigned?: boolean; lockPaintedAreas: boolean | Array; mode: 'default' | 'break'; - paintByCounty?: boolean + paintByCounty?: boolean; + currentStateFp?: string }; diff --git a/app/src/app/utils/events/mapEvents.ts b/app/src/app/utils/events/mapEvents.ts index e4bc3a35..5b0e3b74 100644 --- a/app/src/app/utils/events/mapEvents.ts +++ b/app/src/app/utils/events/mapEvents.ts @@ -253,7 +253,11 @@ export const handleIdCache = ( const parentLayerData = vtLayers[parent_layer] const numFeatures = parentLayerData.length const featureDataArray = parentLayerData._values - parentIdCache.add(index, featureDataArray.slice(-numFeatures,)) + const idArray = featureDataArray.slice(-numFeatures,) + parentIdCache.add(index, idArray) + useMapStore.getState().setMapOptions({ + currentStateFp: idArray[0].replace('vtd:','').slice(0,2) + }) } export const mapEvents = [ From dccba540361d78692c549f0af7409ca65ee6e269 Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Thu, 21 Nov 2024 08:40:12 -0600 Subject: [PATCH 11/13] Type safety for county layer --- app/src/app/store/mapRenderSubs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/app/store/mapRenderSubs.ts b/app/src/app/store/mapRenderSubs.ts index e4a661cd..0dd0e1ab 100644 --- a/app/src/app/store/mapRenderSubs.ts +++ b/app/src/app/store/mapRenderSubs.ts @@ -58,7 +58,7 @@ export const getRenderSubscriptions = (useMapStore: typeof _useMapStore) => { // Hide broken parents on parent layer // Show broken children on child layer layersToFilter.forEach(layerId => - mapRef.setFilter(layerId, getLayerFilter(layerId, shatterIds)) + mapRef.getLayer(layerId) && mapRef.setFilter(layerId, getLayerFilter(layerId, shatterIds)) ); // remove zone from parents shatterIds.parents.forEach(id => { From 4a8d91014670ed253fa7dbb848a8df5b05650ebf Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Thu, 21 Nov 2024 08:44:01 -0600 Subject: [PATCH 12/13] layer safety pt 2 --- app/src/app/store/mapRenderSubs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/app/store/mapRenderSubs.ts b/app/src/app/store/mapRenderSubs.ts index 0dd0e1ab..b2848cc6 100644 --- a/app/src/app/store/mapRenderSubs.ts +++ b/app/src/app/store/mapRenderSubs.ts @@ -318,7 +318,7 @@ export const getRenderSubscriptions = (useMapStore: typeof _useMapStore) => { if (!mapRef) return const filterExpression = (stateFp ? ["==", "STATEFP", stateFp] : true) as any COUNTY_LAYERS.forEach(layer => { - mapRef.setFilter(layer, ["any", filterExpression]) + mapRef.getLayer(layer) && mapRef.setFilter(layer, ["any", filterExpression]) }) } ) From df97c391b07237c5f5a15c12601fcba095f24f43 Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Thu, 21 Nov 2024 10:32:24 -0600 Subject: [PATCH 13/13] typo --- app/src/app/constants/layers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/app/constants/layers.ts b/app/src/app/constants/layers.ts index 8c4cd675..8c0da06f 100644 --- a/app/src/app/constants/layers.ts +++ b/app/src/app/constants/layers.ts @@ -23,7 +23,7 @@ export const INTERACTIVE_LAYERS = [BLOCK_HOVER_LAYER_ID, BLOCK_HOVER_LAYER_ID_CH export const LINE_LAYERS = [BLOCK_LAYER_ID, BLOCK_LAYER_ID_CHILD] as const export const PARENT_LAYERS = [BLOCK_LAYER_ID, BLOCK_HOVER_LAYER_ID]; -export const COUNTY_LAYERS = ['counties_fill', 'counties_boundary','counties_label'] +export const COUNTY_LAYERS = ['counties_fill', 'counties_boundary','counties_labels'] export const CHILD_LAYERS = [ BLOCK_LAYER_ID_CHILD,