diff --git a/client/src/components/J40Map.tsx b/client/src/components/J40Map.tsx index ef0cb021..1d63ee39 100644 --- a/client/src/components/J40Map.tsx +++ b/client/src/components/J40Map.tsx @@ -1,6 +1,6 @@ /* eslint-disable no-unused-vars */ // External Libs: -import React, {MouseEvent, useRef, useState, useMemo} from 'react'; +import React, {useRef, useState, useMemo} from 'react'; import {Map, MapboxGeoJSONFeature, LngLatBoundsLike} from 'maplibre-gl'; import ReactMapGL, { MapEvent, @@ -136,29 +136,6 @@ const J40Map = ({location}: IJ40Interface) => { }); }; - const onClickTerritoryFocusButton = (event: MouseEvent) => { - event.stopPropagation(); - const buttonID = event.target && (event.target as HTMLElement).id; - - switch (buttonID) { - case '48': - goToPlace(constants.LOWER_48_BOUNDS); - break; - case 'AK': - goToPlace(constants.ALASKA_BOUNDS); - break; - case 'HI': - goToPlace(constants.HAWAII_BOUNDS); - break; - case 'PR': - goToPlace(constants.PUERTO_RICO_BOUNDS); - break; - - default: - break; - } - }; - const onTransitionStart = () => { setTransitionInProgress(true); }; @@ -273,7 +250,7 @@ const J40Map = ({location}: IJ40Interface) => { onClick={onClickGeolocate} /> : ''} {geolocationInProgress ?
Geolocation in progress...
: ''} - + {'fs' in flags ? :'' } diff --git a/client/src/components/territoryFocusControl.tsx b/client/src/components/territoryFocusControl.tsx index 393462a3..0ec073b0 100644 --- a/client/src/components/territoryFocusControl.tsx +++ b/client/src/components/territoryFocusControl.tsx @@ -1,21 +1,53 @@ import {useIntl} from 'gatsby-plugin-intl'; -import React, {MouseEventHandler} from 'react'; -import {_useMapControl as useMapControl} from 'react-map-gl'; +import React from 'react'; +import {LngLatBoundsLike} from 'mapbox-gl'; import * as styles from './territoryFocusControl.module.scss'; import * as EXPLORE_COPY from '../data/copy/explore'; +import * as constants from '../data/constants'; interface ITerritoryFocusControl { - onClickTerritoryFocusButton: MouseEventHandler; + goToPlace(bounds: LngLatBoundsLike): void; } -const TerritoryFocusControl = ({onClickTerritoryFocusButton}: ITerritoryFocusControl) => { + +const TerritoryFocusControl = ({goToPlace}: ITerritoryFocusControl) => { const intl = useIntl(); - const {containerRef} = useMapControl({ - // @ts-ignore // Types have not caught up yet, see https://github.com/visgl/react-map-gl/issues/1492 - onClick: onClickTerritoryFocusButton, - }); + const onClickTerritoryFocusButton = (event: React.MouseEvent) => { + event.stopPropagation(); + const buttonID = event.target && (event.target as HTMLElement).id; + + switch (buttonID) { + case '48': + goToPlace(constants.LOWER_48_BOUNDS); + break; + case 'AK': + goToPlace(constants.ALASKA_BOUNDS); + break; + case 'HI': + goToPlace(constants.HAWAII_BOUNDS); + break; + case 'PR': + goToPlace(constants.PUERTO_RICO_BOUNDS); + break; + case 'GU': + goToPlace(constants.GUAM_BOUNDS); + break; + case 'AS': + goToPlace(constants.AMERICAN_SAMOA_BOUNDS); + break; + case 'MP': + goToPlace(constants.MARIANA_ISLAND_BOUNDS); + break; + case 'VI': + goToPlace(constants.US_VIRGIN_ISLANDS_BOUNDS); + break; + + default: + break; + } + }; const territories = [ { @@ -34,6 +66,22 @@ const TerritoryFocusControl = ({onClickTerritoryFocusButton}: ITerritoryFocusCon short: intl.formatMessage(EXPLORE_COPY.MAP.PR_SHORT), long: intl.formatMessage(EXPLORE_COPY.MAP.PR_LONG), }, + { + short: intl.formatMessage(EXPLORE_COPY.MAP.GU_SHORT), + long: intl.formatMessage(EXPLORE_COPY.MAP.GU_LONG), + }, + { + short: intl.formatMessage(EXPLORE_COPY.MAP.AS_SHORT), + long: intl.formatMessage(EXPLORE_COPY.MAP.AS_LONG), + }, + { + short: intl.formatMessage(EXPLORE_COPY.MAP.MP_SHORT), + long: intl.formatMessage(EXPLORE_COPY.MAP.MP_LONG), + }, + { + short: intl.formatMessage(EXPLORE_COPY.MAP.VI_SHORT), + long: intl.formatMessage(EXPLORE_COPY.MAP.VI_LONG), + }, ]; // the offset for this array should map the territories variable const territoriesIconClassName = [ @@ -41,16 +89,20 @@ const TerritoryFocusControl = ({onClickTerritoryFocusButton}: ITerritoryFocusCon 'mapboxgl-ctrl-zoom-to-ak', 'mapboxgl-ctrl-zoom-to-hi', 'mapboxgl-ctrl-zoom-to-pr', + 'mapboxgl-ctrl-zoom-to-gu', + 'mapboxgl-ctrl-zoom-to-as', + 'mapboxgl-ctrl-zoom-to-mp', + 'mapboxgl-ctrl-zoom-to-vi', ]; return ( -
+
{territories.map((territory, index) =>