Skip to content
Closed
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
68 changes: 33 additions & 35 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MapMetadataResponse, Band, SourceList } from './types/maps';
import { ColorMapControls } from './components/ColorMapControls';
import { fetchProducts } from './utils/fetchUtils';
import {
assertBand,
baselayerReducer,
CHANGE_BASELAYER,
CHANGE_CMAP_TYPE,
Expand All @@ -13,6 +14,7 @@ import { useQuery } from './hooks/useQuery';
import { useHighlightBoxes } from './hooks/useHighlightBoxes';
import { OpenLayersMap } from './components/OpenLayersMap';
import { handleSelectChange } from './utils/layerUtils';
import { EXTERNAL_BASELAYERS } from './configs/mapSettings';

function App() {
/** contains useful state of the baselayer for tile requests and matplotlib color mapping */
Expand Down Expand Up @@ -98,10 +100,12 @@ function App() {
* TileLayer requests.
*/
const onBaseLayerChange = useCallback(
(selectedBaselayerId: number) => {
const newActiveBaselayer = bands?.find(
(b) => b.id === selectedBaselayerId
);
(selectedBaselayerId: string) => {
const isExternalBaselayer = selectedBaselayerId.includes('external');

const newActiveBaselayer = isExternalBaselayer
? EXTERNAL_BASELAYERS.find((b) => b.id === selectedBaselayerId)
: bands?.find((b) => b.id === Number(selectedBaselayerId));

if (!newActiveBaselayer) return;

Expand Down Expand Up @@ -149,7 +153,7 @@ function App() {
/** Creates an object of data needed by the submap endpoints to download and to add regions. Since it's
composed from state at this level, we must construct it here and pass it down. */
const submapData = useMemo(() => {
if (baselayerState.activeBaselayer) {
if (assertBand(baselayerState.activeBaselayer)) {
const { map_id: mapId, id: bandId } = baselayerState.activeBaselayer;
const { cmap, cmapValues } = baselayerState;
return {
Expand All @@ -162,33 +166,27 @@ function App() {
}
}, [baselayerState]);

if (
!baselayerState.activeBaselayer ||
!baselayerState.cmap ||
!baselayerState.cmapValues
) {
return null;
} else {
const { activeBaselayer, cmap, cmapValues } = baselayerState;
return (
<>
{baselayerState.activeBaselayer && bands && (
<OpenLayersMap
bands={bands}
baselayerState={baselayerState}
onBaseLayerChange={onBaseLayerChange}
sourceLists={sourceLists}
activeSourceListIds={activeSourceListIds}
onSelectedSourceListsChange={onSelectedSourceListsChange}
highlightBoxes={optimisticHighlightBoxes}
setBoxes={updateHighlightBoxes}
activeBoxIds={activeBoxIds}
setActiveBoxIds={setActiveBoxIds}
onSelectedHighlightBoxChange={onSelectedHighlightBoxChange}
submapData={submapData}
addOptimisticHighlightBox={addOptimisticHighlightBox}
/>
)}
const { activeBaselayer, cmap, cmapValues } = baselayerState;
return (
<>
{baselayerState.activeBaselayer && bands && (
<OpenLayersMap
bands={bands}
baselayerState={baselayerState}
onBaseLayerChange={onBaseLayerChange}
sourceLists={sourceLists}
activeSourceListIds={activeSourceListIds}
onSelectedSourceListsChange={onSelectedSourceListsChange}
highlightBoxes={optimisticHighlightBoxes}
setBoxes={updateHighlightBoxes}
activeBoxIds={activeBoxIds}
setActiveBoxIds={setActiveBoxIds}
onSelectedHighlightBoxChange={onSelectedHighlightBoxChange}
submapData={submapData}
addOptimisticHighlightBox={addOptimisticHighlightBox}
/>
)}
{assertBand(activeBaselayer) && cmap && cmapValues && (
<ColorMapControls
values={[cmapValues.min, cmapValues.max]}
onCmapValuesChange={onCmapValuesChange}
Expand All @@ -198,9 +196,9 @@ function App() {
units={activeBaselayer.units}
quantity={activeBaselayer.quantity}
/>
</>
);
}
)}
</>
);
}

export default App;
1 change: 1 addition & 0 deletions src/components/BoxMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function BoxMenu({
<button
className="area-select-button highlight-box-button"
key={option.display}
disabled={!submapData}
onClick={() => {
if (submapData) {
downloadSubmap(
Expand Down
26 changes: 20 additions & 6 deletions src/components/LayerSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { makeLayerName } from '../utils/layerUtils';
import { LayersIcon } from './icons/LayersIcon';
import './styles/layer-selector.css';
import { MapProps } from './OpenLayersMap';
import { EXTERNAL_BASELAYERS } from '../configs/mapSettings';

interface Props
extends Omit<
Expand All @@ -14,7 +15,7 @@ interface Props
| 'setBoxes'
| 'addOptimisticHighlightBox'
> {
activeBaselayerId?: number;
activeBaselayerId?: number | string;
sourceLists: SourceList[];
}

Expand Down Expand Up @@ -65,13 +66,26 @@ export function LayerSelector({
value={band.id}
name="baselayer"
checked={band.id === activeBaselayerId}
onChange={(e) => onBaseLayerChange(Number(e.target.value))}
onChange={(e) => onBaseLayerChange(e.target.value)}
/>
<label htmlFor={String(band.id)}>{makeLayerName(band)}</label>
</div>
))}
{EXTERNAL_BASELAYERS.map((bl) => (
<div className="input-container" key={bl.id}>
<input
type="radio"
id={bl.id}
value={bl.id}
name="baselayer"
checked={bl.id === activeBaselayerId}
onChange={(e) => onBaseLayerChange(e.target.value)}
/>
<label htmlFor={bl.id}>{bl.name}</label>
</div>
))}
</fieldset>
{sourceLists.length && (
{sourceLists.length ? (
<fieldset>
<legend>Source catalogs</legend>
{sourceLists.map((sl) => (
Expand All @@ -87,8 +101,8 @@ export function LayerSelector({
</div>
))}
</fieldset>
)}
{highlightBoxes && (
) : null}
{highlightBoxes && highlightBoxes.length ? (
<fieldset>
<legend>Highlight regions</legend>
{highlightBoxes.map((box) => (
Expand All @@ -104,7 +118,7 @@ export function LayerSelector({
</div>
))}
</fieldset>
)}
) : null}
</div>
</>
);
Expand Down
Loading