Skip to content

Commit

Permalink
show small landfall popup
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Chaillet committed Jan 14, 2025
1 parent 19015fb commit 9199a46
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
import { createStyles, makeStyles } from '@material-ui/core';
import { Point } from 'geojson';
import { Popup } from 'react-map-gl/maplibre';
import { LandfallInfo } from 'context/anticipatoryAction/AAStormStateSlice/parsedStromDataTypes';
import { AAStormTimeSeriesFeature } from 'context/anticipatoryAction/AAStormStateSlice/rawStormDataTypes';
import PopupContent from './PopupContent';
import { isFeatureAtLandfallEstimateTime } from './utils';

function AAStormLandfallPopup({
point,
feature,
onClose,
landfallInfo,
reportDate,
}: AAStormLandfallPopupProps) {
const classes = useStyles();

const lng = point.coordinates[0];
const lat = point.coordinates[1];
if (!landfallInfo) {
return null;
}

const isVisible = isFeatureAtLandfallEstimateTime(feature, landfallInfo.time);

if (!isVisible || !landfallInfo) {
return null;
}

const lng = feature.geometry.coordinates[0];
const lat = feature.geometry.coordinates[1];

return (
<Popup
Expand All @@ -33,8 +44,8 @@ function AAStormLandfallPopup({
}

interface AAStormLandfallPopupProps {
point: Point;
landfallInfo: LandfallInfo;
feature: AAStormTimeSeriesFeature;
landfallInfo: LandfallInfo | undefined;
reportDate: string;
onClose: () => void;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ParsedStormData } from 'context/anticipatoryAction/AAStormStateSlice/parsedStromDataTypes';
import { AAStormTimeSeriesFeature } from 'context/anticipatoryAction/AAStormStateSlice/rawStormDataTypes';

/* find the wind point which time corresponds to the landfall estimated time */
export function findLandfallWindPoint(stormData: ParsedStormData) {
const { landfall } = stormData;
if (!landfall) {
return null;
}

const landfallEstimatedtime = landfall.time;

const windpoints = stormData.timeSeries?.features;
return windpoints?.find(windpoint =>
isFeatureAtLandfallEstimateTime(windpoint, landfallEstimatedtime),
);
}

export function isFeatureAtLandfallEstimateTime(
feature: AAStormTimeSeriesFeature,
landfallEstimatedtime: string[],
) {
return (
landfallEstimatedtime &&
feature.properties.time === landfallEstimatedtime[0]
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import { useWindStatesByTime } from 'components/MapView/DateSelector/TimelineIte
import { getAAColor } from 'components/MapView/LeftPanel/AnticipatoryActionPanel/AnticipatoryActionStormPanel/utils';
import { AACategory } from 'context/anticipatoryAction/AAStormStateSlice/parsedStromDataTypes';
import anticipatoryActionIcons from 'components/Common/AnticipatoryAction/icons';
import { AAStormTimeSeriesFeature } from 'context/anticipatoryAction/AAStormStateSlice/rawStormDataTypes';
import AAStormDatePopup from './AAStormDatePopup';
import AAStormLandfallPopup from './AAStormLandfallPopup';

import { TimeSeries } from './types';
import AAStormLandfallMarker from './AAStormLandfallPopup/AAStormLandfallMarker/AAStormLandfallMarker';

Check failure on line 31 in frontend/src/components/MapView/Layers/AnticipatoryActionStormLayer/index.tsx

View workflow job for this annotation

GitHub Actions / frontend_tests (ubuntu-latest)

Missing file extension for "./AAStormLandfallPopup/AAStormLandfallMarker/AAStormLandfallMarker"

Check failure on line 31 in frontend/src/components/MapView/Layers/AnticipatoryActionStormLayer/index.tsx

View workflow job for this annotation

GitHub Actions / frontend_tests (ubuntu-latest)

Unable to resolve path to module './AAStormLandfallPopup/AAStormLandfallMarker/AAStormLandfallMarker'

interface AnticipatoryActionStormLayerProps {
layer: AnticipatoryActionLayerProps;
Expand Down Expand Up @@ -105,7 +107,7 @@ const AnticipatoryActionStormLayer = React.memo(
const { data: boundaryData } = boundaryLayerState || {};

const [selectedFeature, setSelectedFeature] =
useState<Feature<Point> | null>(null);
useState<AAStormTimeSeriesFeature | null>(null);

function enhanceTimeSeries(timeSeries: TimeSeries) {
const { features, ...timeSeriesRest } = timeSeries;
Expand Down Expand Up @@ -227,7 +229,7 @@ const AnticipatoryActionStormLayer = React.memo(
e.preventDefault();
dispatch(hidePopup()); // hides the black tooltip containing the district names
const feature = e.features?.[0];
setSelectedFeature(feature as Feature<Point>);
setSelectedFeature(feature as unknown as AAStormTimeSeriesFeature);
};

useMapCallback<'click', null>(
Expand Down Expand Up @@ -436,14 +438,16 @@ const AnticipatoryActionStormLayer = React.memo(

<AAStormDatePopup timeSeries={stormData.timeSeries} />

{selectedFeature && stormData.landfall?.time && (
{selectedFeature && (
<AAStormLandfallPopup
point={selectedFeature.geometry}
feature={selectedFeature}
reportDate={stormData.forecastDetails?.reference_time || ''}
landfallInfo={stormData.landfall}
onClose={() => landfallPopupCloseHandler()}
/>
)}

<AAStormLandfallMarker stormData={stormData} />
</>
);
},
Expand Down

0 comments on commit 9199a46

Please sign in to comment.