From bc3043e6e222cb1583895e5e9d07bfa8319c2a66 Mon Sep 17 00:00:00 2001 From: Hanbyul Jo Date: Wed, 25 Oct 2023 11:28:03 -0400 Subject: [PATCH] Use a wrapper for map controls --- app/scripts/components/common/map/index.tsx | 10 +++- app/scripts/components/common/map/maps.tsx | 9 ++- .../exploration/components/map/index.tsx | 58 ++++++++++--------- 3 files changed, 47 insertions(+), 30 deletions(-) diff --git a/app/scripts/components/common/map/index.tsx b/app/scripts/components/common/map/index.tsx index a00e1ab32..36c7d56ca 100644 --- a/app/scripts/components/common/map/index.tsx +++ b/app/scripts/components/common/map/index.tsx @@ -2,11 +2,19 @@ import React, { ReactNode } from 'react'; import { MapProvider } from 'react-map-gl'; import Maps, { MapsContextWrapperProps } from './maps'; +export const COMPARE_NAME = 'Compare'; export function Compare({ children }: { children: ReactNode }) { return <>{children}; } -Compare.displayName = 'Compare'; +Compare.displayName = COMPARE_NAME; + +export const CONTROLS_CONTAINER_NAME = 'MapControlsContainer'; +export function MapControls({ children }: { children: ReactNode }) { + return <>{children}; +} + +MapControls.displayName = CONTROLS_CONTAINER_NAME; export default function MapProviderWrapper(props: MapsContextWrapperProps) { return ( diff --git a/app/scripts/components/common/map/maps.tsx b/app/scripts/components/common/map/maps.tsx index dc15ee7ac..a1910c340 100644 --- a/app/scripts/components/common/map/maps.tsx +++ b/app/scripts/components/common/map/maps.tsx @@ -22,6 +22,7 @@ import { Styles } from './styles'; import useMapCompare from './hooks/use-map-compare'; import MapComponent from './map-component'; import useMaps, { useMapsContext } from './hooks/use-maps'; +import { COMPARE_NAME, CONTROLS_CONTAINER_NAME } from '.'; const chevronRightURI = () => iconDataURI(CollecticonChevronRightSmall, { @@ -96,12 +97,14 @@ function Maps({ children, projection }: MapsProps) { // @ts-expect-error displayName is not in the type const componentName = child.type.displayName ?? ''; - if (componentName === 'Compare') { + if (componentName === COMPARE_NAME) { acc.compareGenerators = Children.toArray( child.props.children ) as ReactElement[]; - } else if (componentName.endsWith('Control')) { - acc.controls = [...acc.controls, child]; + } else if (componentName == CONTROLS_CONTAINER_NAME) { + acc.controls = Children.toArray( + child.props.children + ) as ReactElement[]; } else { acc.generators = [...acc.generators, child]; } diff --git a/app/scripts/components/exploration/components/map/index.tsx b/app/scripts/components/exploration/components/map/index.tsx index 307d092af..f6ed12585 100644 --- a/app/scripts/components/exploration/components/map/index.tsx +++ b/app/scripts/components/exploration/components/map/index.tsx @@ -3,7 +3,11 @@ import { useAtomValue } from 'jotai'; import { Feature, Polygon } from 'geojson'; import { useStacMetadataOnDatasets } from '../../hooks/use-stac-metadata-datasets'; -import { selectedCompareDateAtom, selectedDateAtom, timelineDatasetsAtom } from '../../atoms/atoms'; +import { + selectedCompareDateAtom, + selectedDateAtom, + timelineDatasetsAtom +} from '../../atoms/atoms'; import { TimelineDatasetStatus, TimelineDatasetSuccess @@ -11,7 +15,7 @@ import { import { Layer } from './layer'; import { AnalysisMessageControl } from './analysis-message-control'; -import Map, { Compare } from '$components/common/map'; +import Map, { Compare, MapControls } from '$components/common/map'; import { Basemap } from '$components/common/map/style-generators/basemap'; import GeocoderControl from '$components/common/map/controls/geocoder'; import { ScaleControl } from '$components/common/map/controls'; @@ -82,31 +86,33 @@ export function ExplorationMap() { /> ))} {/* Map controls */} - - - - - + + + + + + - - + + + {comparing && ( // Compare map layers