Skip to content
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
2 changes: 1 addition & 1 deletion src/components/ColorMapControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export function ColorMapControls(props: ColorMapControlsProps) {
const step = stepCalc >= 1 ? Math.floor(stepCalc) : stepCalc;

return { min, max, step };
}, [processedHistogramData?.edges, values, isLogScale]);
}, [processedHistogramData?.edges, values]);

/** Change handler for the color map <select> element */
const handleCmapChange: ChangeEventHandler<HTMLSelectElement> = useCallback(
Expand Down
18 changes: 15 additions & 3 deletions src/components/CoordinatesDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { useCallback, useEffect, useRef, useState, FormEvent } from 'react';
import { Map, Feature } from 'ol';
import { Map, Feature, MapBrowserEvent } from 'ol';
import { Geometry } from 'ol/geom';
import { NUMBER_OF_FIXED_COORDINATE_DECIMALS } from '../configs/mapSettings';
import { transformGraticuleCoords } from '../utils/layerUtils';
import './styles/coordinates-display.css';
import { searchOverlayHelper } from '../utils/externalSearchUtils';

export function CoordinatesDisplay({
coordinates,
flipped,
mapRef,
externalSearchRef,
externalSearchMarkerRef,
}: {
coordinates: number[];
flipped: boolean;
mapRef: React.RefObject<Map | null>;
externalSearchRef: React.RefObject<HTMLDivElement | null>;
externalSearchMarkerRef: React.RefObject<Feature<Geometry> | null>;
}) {
const [coordinates, setCoordinates] = useState<number[] | undefined>(
undefined
);
const [showCoordInputs, setShowCoordInputs] = useState(false);
const formRef = useRef<HTMLFormElement>(null);
const firstInputRef = useRef<HTMLInputElement>(null);
Expand Down Expand Up @@ -54,6 +55,14 @@ export function CoordinatesDisplay({
};
}, []);

useEffect(() => {
if (!mapRef.current) return;
const currentMapRef = mapRef.current;
const updateCoords = (e: MapBrowserEvent) => setCoordinates(e.coordinate);
currentMapRef.on('pointermove', updateCoords);
return () => currentMapRef.un('pointermove', updateCoords);
}, [mapRef]);

const onSubmit = useCallback(
(e: FormEvent) => {
e.preventDefault();
Expand Down Expand Up @@ -87,6 +96,9 @@ export function CoordinatesDisplay({
[mapRef, externalSearchRef, externalSearchMarkerRef, flipped]
);

// Return early if coordinates aren't defined
if (!coordinates) return;

const transformedCoords = transformGraticuleCoords(coordinates, flipped);
return (
<form
Expand Down
4 changes: 2 additions & 2 deletions src/components/LayerSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function LayerSelector({
'keypress',
previousLockMenuHandlerRef.current ?? newHandler
);
}, [setLockMenu, lockMenu, menuRef.current]);
}, [setLockMenu, lockMenu, menuRef]);

const toggleMenu = useCallback(
(e: MouseEvent) => {
Expand All @@ -102,7 +102,7 @@ export function LayerSelector({
menuRef.current.classList.add('hide');
}
},
[menuRef.current, lockMenu]
[menuRef, lockMenu]
);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function Login({
const hasRefreshToken = getCookie('valid_refresh_token');

setIsAuthenticated(!!hasAccessToken && !!hasRefreshToken);
}, []);
}, [setIsAuthenticated]);

if (isAuthenticated === null) return null;

Expand Down
93 changes: 37 additions & 56 deletions src/components/OpenLayersMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ export function OpenLayersMap({
const previousSearchOverlayHandlerRef =
useRef<(e: MapBrowserEvent<any>) => void | null>(null);
const previousKeyboardHandlerRef = useRef<(e: KeyboardEvent) => void>(null);
const [coordinates, setCoordinates] = useState<number[] | undefined>(
undefined
);
const [isDrawing, setIsDrawing] = useState(false);
const [isNewBoxDrawn, setIsNewBoxDrawn] = useState(false);
const [flipTiles, setFlipTiles] = useState(true);
Expand All @@ -104,7 +101,7 @@ export function OpenLayersMap({
{ id: string; flipped: boolean }[]
>([]);

const { activeBaselayer, internalBaselayers } = baselayersState;
const { activeBaselayer } = baselayersState;

/**
* Handler fires when user changes map layers. If the units of the new
Expand Down Expand Up @@ -175,13 +172,7 @@ export function OpenLayersMap({
newBaselayer: newActiveBaselayer,
});
},
[
baselayersState.internalBaselayers,
baselayersState.activeBaselayer,
backHistoryStack,
flipTiles,
setFlipTiles,
]
[baselayersState, dispatchBaselayersChange, flipTiles, setFlipTiles]
);

const goBack = useCallback(() => {
Expand All @@ -194,30 +185,30 @@ export function OpenLayersMap({
onBaselayerChange(baselayer.id, 'goForward', baselayer.flipped);
}, [onBaselayerChange, forwardHistoryStack]);

const tileLayers = useMemo(() => {
return internalBaselayers?.map(
(layer) =>
new TileLayer({
properties: { id: 'baselayer-' + layer.layer_id },
source: new XYZ({
url: `${SERVICE_URL}/maps/${layer.layer_id}/{z}/{-y}/{x}/tile.png?cmap=${layer.cmap}&vmin=${layer.isLogScale ? Math.pow(10, layer.vmin) : layer.vmin}&vmax=${layer.isLogScale ? Math.pow(10, layer.vmax) : layer.vmax}&flip=${flipTiles}&log_norm=${layer.isLogScale}&abs=${layer.isAbsoluteValue}`,
tileGrid: new TileGrid({
extent: [-180, -90, 180, 90],
origin: [-180, 90],
tileSize: layer.tile_size,
resolutions: getBaselayerResolutions(
180,
layer.tile_size,
layer.number_of_levels - 1
),
}),
interpolate: false,
projection: 'EPSG:4326',
tilePixelRatio: layer.tile_size / 256,
const activeInternalTileLayer = useMemo(() => {
if (assertInternalBaselayer(activeBaselayer)) {
const layer = activeBaselayer;
return new TileLayer({
properties: { id: 'baselayer-' + layer.layer_id },
source: new XYZ({
url: `${SERVICE_URL}/maps/${layer.layer_id}/{z}/{-y}/{x}/tile.png?cmap=${layer.cmap}&vmin=${layer.isLogScale ? Math.pow(10, layer.vmin) : layer.vmin}&vmax=${layer.isLogScale ? Math.pow(10, layer.vmax) : layer.vmax}&flip=${flipTiles}&log_norm=${layer.isLogScale}&abs=${layer.isAbsoluteValue}`,
tileGrid: new TileGrid({
extent: [-180, -90, 180, 90],
origin: [-180, 90],
tileSize: layer.tile_size,
resolutions: getBaselayerResolutions(
180,
layer.tile_size,
layer.number_of_levels - 1
),
}),
})
);
}, [internalBaselayers, flipTiles]);
interpolate: false,
projection: 'EPSG:4326',
tilePixelRatio: layer.tile_size / 256,
}),
});
}
}, [flipTiles, activeBaselayer]);

const externalTileLayers = useMemo(() => {
return EXTERNAL_BASELAYERS.map((b) => {
Expand Down Expand Up @@ -254,10 +245,6 @@ export function OpenLayersMap({
view: new View(DEFAULT_INTERNAL_MAP_SETTINGS),
});

mapRef.current.on('pointermove', (e) => {
setCoordinates(e.coordinate);
});

/**
* BEGIN
* Set up overlay, markers, and events for the external searches functionality
Expand Down Expand Up @@ -347,7 +334,7 @@ export function OpenLayersMap({
}
}
},
[externalSearchMarkerRef.current, flipTiles]
[externalSearchMarkerRef, flipTiles]
);

useEffect(() => {
Expand Down Expand Up @@ -390,7 +377,7 @@ export function OpenLayersMap({
}, [flipTiles]);

/**
* Updates tilelayers when new baselayer is selected and/or color map settings change
* Updates map layer when new baselayer is selected and/or color map settings change
*/
useEffect(() => {
if (mapRef.current && activeBaselayer) {
Expand All @@ -401,11 +388,8 @@ export function OpenLayersMap({
mapRef.current?.removeLayer(layer);
}
});
if (assertInternalBaselayer(activeBaselayer)) {
const activeLayer = tileLayers!.find(
(t) => t.get('id') === 'baselayer-' + activeBaselayer!.layer_id
)!;
mapRef.current.addLayer(activeLayer);
if (assertInternalBaselayer(activeBaselayer) && activeInternalTileLayer) {
mapRef.current.addLayer(activeInternalTileLayer);
} else {
const externalBaselayer = EXTERNAL_BASELAYERS.find(
(b) => b.layer_id === activeBaselayer.layer_id
Expand All @@ -419,7 +403,7 @@ export function OpenLayersMap({
mapRef.current.addLayer(activeLayer);
}
}
}, [activeBaselayer, tileLayers]);
}, [activeBaselayer, activeInternalTileLayer, externalTileLayers]);

/**
* Add keyboard support for switching baselayers
Expand Down Expand Up @@ -474,7 +458,7 @@ export function OpenLayersMap({
view.setCenter(newCenter);
}
setFlipTiles(!flipTiles);
}, [setFlipTiles, flipTiles, mapRef.current]);
}, [setFlipTiles, flipTiles, mapRef]);

return (
<div id="map" style={{ cursor: isDrawing ? 'crosshair' : 'auto' }}>
Expand Down Expand Up @@ -548,15 +532,12 @@ export function OpenLayersMap({
goForward={goForward}
/>
<GraticuleLayer mapRef={mapRef} flipped={flipTiles} />
{coordinates && (
<CoordinatesDisplay
coordinates={coordinates}
flipped={flipTiles}
mapRef={mapRef}
externalSearchRef={externalSearchRef}
externalSearchMarkerRef={externalSearchMarkerRef}
/>
)}
<CoordinatesDisplay
flipped={flipTiles}
mapRef={mapRef}
externalSearchRef={externalSearchRef}
externalSearchMarkerRef={externalSearchMarkerRef}
/>
</div>
);
}
11 changes: 9 additions & 2 deletions src/components/layers/AddHighlightBoxLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,14 @@ export function AddHighlightBoxLayer({
}
};
}
}, [mapRef.current, isDrawing]);
}, [
mapRef,
isDrawing,
drawBoxRef,
setIsDrawing,
setIsNewBoxDrawn,
showMenuOverlay,
]);

const handleAddBoxCleanup = useCallback(() => {
setNewBoxData(undefined);
Expand All @@ -128,7 +135,7 @@ export function AddHighlightBoxLayer({
if (source) {
source.clear();
}
}, [drawBoxRef.current]);
}, [setIsNewBoxDrawn, drawBoxRef]);

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/components/layers/GraticuleLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function GraticuleLayer({
mapRef.current.addLayer(graticule1);
mapRef.current.addLayer(graticule2);
}
}, [mapRef.current, flipped]);
}, [mapRef, flipped, handleLatLabelFormat, handleLonLabelFormat]);

return null;
}
8 changes: 4 additions & 4 deletions src/components/layers/HighlightBoxLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function HighlightBoxLayer({
map?.addLayer(layer);
addedLayerIdsRef.current.add(layerId);
});
}, [mapRef.current, highlightBoxes, activeBoxIds, flipped]);
}, [mapRef, highlightBoxes, activeBoxIds, flipped]);

useEffect(() => {
if (!mapRef.current || !boxOverlayRef.current) return;
Expand All @@ -152,7 +152,7 @@ export function HighlightBoxLayer({
});
mapRef.current.addOverlay(overlayRef.current);
}
}, [mapRef.current, boxOverlayRef.current]);
}, [mapRef, boxOverlayRef]);

useEffect(() => {
if (mapRef.current) {
Expand All @@ -162,7 +162,7 @@ export function HighlightBoxLayer({
handleBoxHoverRef.current = handleBoxHover;
mapRef.current.on('pointermove', handleBoxHover);
}
}, [mapRef.current, handleBoxHover]);
}, [mapRef, handleBoxHover]);

useEffect(() => {
const map = mapRef.current;
Expand Down Expand Up @@ -240,7 +240,7 @@ export function HighlightBoxLayer({
}
}
});
}, [flipped, highlightBoxes]);
}, [mapRef, flipped, highlightBoxes]);

return (
<>
Expand Down
8 changes: 4 additions & 4 deletions src/components/layers/SourcesLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function SourcesLayer({

sourceGroupRef.current = group;
map.addLayer(group);
}, [sourceGroups, activeSourceGroupIds, flipped]);
}, [mapRef, sourceGroups, activeSourceGroupIds, flipped]);

// Set up interaction and popup
useEffect(() => {
Expand Down Expand Up @@ -149,7 +149,7 @@ export function SourcesLayer({
map.removeOverlay(popupOverlay);
map.removeInteraction(select);
};
}, [mapRef.current]);
}, [mapRef]);

useEffect(() => {
if (mapRef.current) {
Expand All @@ -162,7 +162,7 @@ export function SourcesLayer({
handleSourceClickRef.current = handleSourceClick;
selectInteractionRef.current?.on('select', handleSourceClick);
}
}, [handleSourceClick, selectInteractionRef.current]);
}, [mapRef, handleSourceClick, selectInteractionRef]);

useEffect(() => {
const map = mapRef.current;
Expand Down Expand Up @@ -190,7 +190,7 @@ export function SourcesLayer({
});
}
});
}, [flipped]);
}, [mapRef, flipped, selectedSourceId]);

return null;
}
2 changes: 1 addition & 1 deletion src/hooks/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, useEffect } from 'react';

type UseQueryParams<T> = {
queryFn: () => Promise<T>;
queryKey: any[];
queryKey: unknown[];
initialData: T;
};

Expand Down
2 changes: 1 addition & 1 deletion src/utils/layerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function transformSources(feature: Feature, flipped: boolean) {
}

export function transformBoxes(boxExtent: BoxExtent, flipped: boolean) {
let newBoxPosition = {
const newBoxPosition = {
...boxExtent,
};

Expand Down