diff --git a/src/components/map/hurricane-track.js b/src/components/map/hurricane-track.js index b8d4b4d..33bf6f4 100644 --- a/src/components/map/hurricane-track.js +++ b/src/components/map/hurricane-track.js @@ -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}) => { @@ -17,6 +19,11 @@ export const HurricaneTrackGeoJson = ({index}) => { } = useLayers(); const [hurricaneData, setHurricaneData] = useState(); + const { + unitsType, + speedType, +} = useSettings(); + function coneStyle() { return { fillColor: '#858585', @@ -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); diff --git a/src/utils/map-utils.js b/src/utils/map-utils.js index 6696f3a..4270ead 100644 --- a/src/utils/map-utils.js +++ b/src/utils/map-utils.js @@ -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