Skip to content

Commit

Permalink
#296 add uppdates for unit setting in hurricane track tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
lstillwe committed Nov 12, 2024
1 parent 4d04efc commit 4e577dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/components/map/hurricane-track.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
} from "@utils/hurricane/track";
import { useLayers } from '@context';
import { getNamespacedEnvParam } from "@utils";
import { useSettings } from '@context';
import { mphToMps, mphToKnots } from '@utils/map-utils';


export const HurricaneTrackGeoJson = ({index}) => {
Expand All @@ -17,6 +19,11 @@ export const HurricaneTrackGeoJson = ({index}) => {
} = useLayers();
const [hurricaneData, setHurricaneData] = useState();

const {
unitsType,
speedType,
} = useSettings();

function coneStyle() {
return {
fillColor: '#858585',
Expand Down Expand Up @@ -84,9 +91,21 @@ export const HurricaneTrackGeoJson = ({index}) => {

const onEachHurrFeature = (feature, layer) => {
if (feature.properties && feature.properties.time_utc) {

// set wind speed to default units setting values
let windSpeed = mphToMps(feature.properties.max_wind_speed_mph);
let unitStr = "mps";
// now check to see the imperial setting has been selected instead
if(unitsType.current === "imperial") {
windSpeed = (speedType.current === "mph") ? feature.properties.max_wind_speed_mph
:
mphToKnots(feature.properties.max_wind_speed_mph);
unitStr = speedType.current;
}

const popupContent = feature.properties.storm_name + ": " +
feature.properties.time_utc + ", " +
feature.properties.max_wind_speed_mph + "mph";
windSpeed.toFixed(1) + unitStr;

layer.on("mouseover", function (e) {
this.bindPopup(popupContent).openPopup(e.latlng);
Expand Down
3 changes: 3 additions & 0 deletions src/utils/map-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ export const knotsToMps = (s) => {
export const mpsToKnots = (s) => {
return s * 1.943844;
};
export const mphToKnots = (s) => {
return s / 1.15078;
};

// this functiom converts a style to imperial units
// styles will always be saved locally in metric units
Expand Down

0 comments on commit 4e577dd

Please sign in to comment.