From 0abd0bf5b2d37a0d7b732b56bdc1c951936af847 Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Thu, 14 Nov 2024 13:27:33 -0600 Subject: [PATCH 1/5] properly remove source --- app/src/app/constants/layers.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/app/constants/layers.ts b/app/src/app/constants/layers.ts index ca992f8f..4f4cefb8 100644 --- a/app/src/app/constants/layers.ts +++ b/app/src/app/constants/layers.ts @@ -279,6 +279,12 @@ export function removeBlockLayers(map: Map | null) { ].forEach(layer => { map.getLayer(layer) && map.removeLayer(layer); }); + + [ + BLOCK_SOURCE_ID, + ].forEach(source => { + map.getSource(source) && map.removeSource(source); + }); } export {addBlockLayers}; From 0a1c3df7326c7cb24693564ea4f0ce61d6c40ca1 Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Thu, 14 Nov 2024 13:29:06 -0600 Subject: [PATCH 2/5] Update layers.ts --- app/src/app/constants/layers.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/app/constants/layers.ts b/app/src/app/constants/layers.ts index 4f4cefb8..45e5983c 100644 --- a/app/src/app/constants/layers.ts +++ b/app/src/app/constants/layers.ts @@ -275,7 +275,6 @@ export function removeBlockLayers(map: Map | null) { BLOCK_LAYER_ID_CHILD, BLOCK_HOVER_LAYER_ID_CHILD, BLOCK_LAYER_ID_HIGHLIGHT_CHILD, - BLOCK_SOURCE_ID, ].forEach(layer => { map.getLayer(layer) && map.removeLayer(layer); }); From 8ae5ab1cb0b9360209300c0d95fbf8e8d01a058e Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Thu, 14 Nov 2024 13:32:03 -0600 Subject: [PATCH 3/5] Prettier --- app/src/app/constants/layers.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/src/app/constants/layers.ts b/app/src/app/constants/layers.ts index 45e5983c..b8081c9d 100644 --- a/app/src/app/constants/layers.ts +++ b/app/src/app/constants/layers.ts @@ -23,7 +23,11 @@ export const INTERACTIVE_LAYERS = [BLOCK_HOVER_LAYER_ID, BLOCK_HOVER_LAYER_ID_CH export const PARENT_LAYERS = [BLOCK_LAYER_ID, BLOCK_HOVER_LAYER_ID]; -export const CHILD_LAYERS = [BLOCK_LAYER_ID_CHILD, BLOCK_HOVER_LAYER_ID_CHILD, BLOCK_LAYER_ID_HIGHLIGHT_CHILD]; +export const CHILD_LAYERS = [ + BLOCK_LAYER_ID_CHILD, + BLOCK_HOVER_LAYER_ID_CHILD, + BLOCK_LAYER_ID_HIGHLIGHT_CHILD, +]; export const DEFAULT_PAINT_STYLE: ExpressionSpecification = [ 'case', @@ -66,11 +70,11 @@ export function getLayerFill( captiveIds?: Set, shatterIds?: Set ): DataDrivenPropertyValueSpecification { - const innerFillSpec = [ + const innerFillSpec = ([ 'case', // is broken parent ['boolean', ['feature-state', 'broken'], false], - 0, + 0, // geography is locked ['boolean', ['feature-state', 'locked'], false], 0.35, @@ -108,7 +112,7 @@ export function getLayerFill( ['boolean', ['feature-state', 'hover'], false], 0.6, 0.2, - ] as unknown as DataDrivenPropertyValueSpecification; + ] as unknown) as DataDrivenPropertyValueSpecification; if (captiveIds?.size) { return [ 'case', @@ -162,12 +166,13 @@ export function getHighlightLayerSpecification( 'any', ['boolean', ['feature-state', 'focused'], false], ['boolean', ['feature-state', 'highlighted'], false], - ['all', + [ + 'all', // @ts-ignore correct logic, wrong types ['==', ['feature-state', 'zone'], null], ['boolean', !!highlightUnassigned], ['!', ['boolean', ['feature-state', 'broken'], false]], - ] + ], ], 3.5, 0, // Default width if none of the conditions are met @@ -278,10 +283,8 @@ export function removeBlockLayers(map: Map | null) { ].forEach(layer => { map.getLayer(layer) && map.removeLayer(layer); }); - - [ - BLOCK_SOURCE_ID, - ].forEach(source => { + + [BLOCK_SOURCE_ID].forEach(source => { map.getSource(source) && map.removeSource(source); }); } From b5b1444858993451c930fcd03c73049926da8207 Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Thu, 14 Nov 2024 13:41:50 -0600 Subject: [PATCH 4/5] Refactor bounds to state mutation --- app/src/app/constants/layers.ts | 6 ------ app/src/app/store/mapStore.ts | 21 +++++++++++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/src/app/constants/layers.ts b/app/src/app/constants/layers.ts index b8081c9d..93461404 100644 --- a/app/src/app/constants/layers.ts +++ b/app/src/app/constants/layers.ts @@ -260,12 +260,6 @@ const addBlockLayers = (map: Map | null, mapDocument: DocumentObject) => { } map?.addLayer(getHighlightLayerSpecification(mapDocument.parent_layer, BLOCK_LAYER_ID_HIGHLIGHT)); useMapStore.getState().setMapRenderingState('loaded'); - - // update map bounds based on document extent - useMapStore.getState().setMapOptions({ - bounds: mapDocument.extent as [number, number, number, number], - container: useMapStore.getState().mapOptions.container, - }); }; export function removeBlockLayers(map: Map | null) { diff --git a/app/src/app/store/mapStore.ts b/app/src/app/store/mapStore.ts index 9c48b8c5..a40f0c7b 100644 --- a/app/src/app/store/mapStore.ts +++ b/app/src/app/store/mapStore.ts @@ -358,17 +358,26 @@ export const useMapStore = create( setMapViews: mapViews => set({mapViews}), mapDocument: null, setMapDocument: mapDocument => { - const currentMapDocument = get().mapDocument; + const { + mapDocument: currentMapDocument, + setFreshMap, + resetZoneAssignments, + upsertUserMap, + mapOptions + } = get(); if (currentMapDocument?.document_id === mapDocument.document_id) { return; } - get().setFreshMap(true); - get().resetZoneAssignments(); - get().upsertUserMap({ - mapDocument, - }); + resetZoneAssignments() + setFreshMap(true) + upsertUserMap({mapDocument}) + set({ mapDocument: mapDocument, + mapOptions: { + ...mapOptions, + bounds: mapDocument.extent + }, shatterIds: {parents: new Set(), children: new Set()}, }); }, From 0fc3333884642fdbedbf1444a20d43b28df915dd Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Thu, 14 Nov 2024 13:43:36 -0600 Subject: [PATCH 5/5] change order --- app/src/app/store/mapStore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/app/store/mapStore.ts b/app/src/app/store/mapStore.ts index a40f0c7b..19cabb0c 100644 --- a/app/src/app/store/mapStore.ts +++ b/app/src/app/store/mapStore.ts @@ -368,8 +368,8 @@ export const useMapStore = create( if (currentMapDocument?.document_id === mapDocument.document_id) { return; } - resetZoneAssignments() setFreshMap(true) + resetZoneAssignments() upsertUserMap({mapDocument}) set({