From dc6f57a2a8cbb6b0e54a73018e598ebbc99f63cc Mon Sep 17 00:00:00 2001 From: Vim USDS Date: Tue, 16 Aug 2022 16:53:35 -0700 Subject: [PATCH] Remove zooming in on Alaska data point --- client/src/components/J40Map.tsx | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/client/src/components/J40Map.tsx b/client/src/components/J40Map.tsx index ec31b2ee..bc84643b 100644 --- a/client/src/components/J40Map.tsx +++ b/client/src/components/J40Map.tsx @@ -166,10 +166,24 @@ const J40Map = ({location}: IJ40Interface) => { // @ts-ignore const feature = event.features && event.features[0]; + /** + * Given that Alaska has Points as their data type, we will not zoom into them when + * selected. In order to detect if a feature is a Point we will use Regex to determine + * the Alaska Point based on it's unique ID: + * + * E.g. {33FF6457-324C-4643-94E8-D543DD4339E0} + * + * The regex will test for any numeric, upper-case alpha with hyphens string enclosed + * in curly braces. + */ + const alaskaIDRegex = /\{[0-9,A-Z,-]+\}/g; + const isFeatureAlaskaPoint = alaskaIDRegex.test(feature.id); + if (feature) { // Get the current selected feature's bounding box: const [minLng, minLat, maxLng, maxLat] = bbox(feature); + // Set the selectedFeature ID if (feature.id !== selectedFeatureId) { setSelectedFeature(feature); @@ -177,8 +191,9 @@ const J40Map = ({location}: IJ40Interface) => { setSelectedFeature(undefined); } - // Go to the newly selected feature - goToPlace([ + + // Go to the newly selected feature (as long as it's not an Alaska Point) + !isFeatureAlaskaPoint && goToPlace([ [minLng, minLat], [maxLng, maxLat], ]); @@ -239,7 +254,7 @@ const J40Map = ({location}: IJ40Interface) => { * @param {LngLatBoundsLike} bounds * @param {boolean} isTerritory */ - const goToPlace = (bounds: LngLatBoundsLike, isTerritory = false ) => { + const goToPlace = (bounds: LngLatBoundsLike, isTerritory = false) => { const newViewPort = new WebMercatorViewport({height: viewport.height!, width: viewport.width!}); const {longitude, latitude, zoom} = newViewPort.fitBounds( bounds as [[number, number], [number, number]], {