Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a wrapper for map controls #711

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/scripts/components/common/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
9 changes: 6 additions & 3 deletions app/scripts/components/common/map/maps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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];
}
Expand Down
58 changes: 32 additions & 26 deletions app/scripts/components/exploration/components/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ 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
} from '../../types.d.ts';
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';
Expand Down Expand Up @@ -82,31 +86,33 @@ export function ExplorationMap() {
/>
))}
{/* Map controls */}
<DrawControl
displayControlsDefault={false}
controls={
{
polygon: true,
trash: true
} as any
}
customFeatures={customAoIFeatures}
/>
<CustomAoIControl onConfirm={onCustomAoIConfirm} />
<AnalysisMessageControl />
<GeocoderControl />
<MapOptionsControl
projection={projection}
onProjectionChange={setProjection}
basemapStyleId={mapBasemapId}
onBasemapStyleIdChange={setBasemapId}
labelsOption={labelsOption}
boundariesOption={boundariesOption}
onOptionChange={onOptionChange}
/>
<MapControls>
<DrawControl
displayControlsDefault={false}
controls={
{
polygon: true,
trash: true
} as any
}
customFeatures={customAoIFeatures}
/>
<CustomAoIControl onConfirm={onCustomAoIConfirm} />
<AnalysisMessageControl />
<GeocoderControl />
<MapOptionsControl
projection={projection}
onProjectionChange={setProjection}
basemapStyleId={mapBasemapId}
onBasemapStyleIdChange={setBasemapId}
labelsOption={labelsOption}
boundariesOption={boundariesOption}
onOptionChange={onOptionChange}
/>

<ScaleControl />
<MapCoordsControl />
<ScaleControl />
<MapCoordsControl />
</MapControls>
{comparing && (
// Compare map layers
<Compare>
Expand Down
Loading