Skip to content

Commit

Permalink
296 updates to use new default styles when switching unit types
Browse files Browse the repository at this point in the history
  • Loading branch information
lstillwe committed Oct 31, 2024
1 parent 3c421ad commit 40669ad
Show file tree
Hide file tree
Showing 4 changed files with 318 additions and 23 deletions.
40 changes: 33 additions & 7 deletions src/components/trays/settings/units.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React, { useState } from 'react';
import { FormControl, RadioGroup, Radio, Sheet, Typography } from '@mui/joy';
import { useSettings } from '@context';
import { maxeleStyle, maxeleImperialStyle,
maxwvelStyle, maxwvelImperialMPHStyle, maxwvelImperialKnotsStyle,
swanStyle, swanImperialStyle } from '@utils';


/**
Expand All @@ -17,6 +20,7 @@ import { useSettings } from '@context';
export const Units = () => {

const {
mapStyle,
unitsType,
speedType,
} = useSettings();
Expand All @@ -29,25 +33,47 @@ export const Units = () => {
imperial: "mph",
};

const setLayerStyles = (unitType) => {
if (unitType === "metric") {
mapStyle.maxele.set(maxeleStyle);
mapStyle.swan.set(swanStyle);
mapStyle.maxwvel.set(maxwvelStyle);
}
else {
mapStyle.maxele.set(maxeleImperialStyle);
mapStyle.swan.set(swanImperialStyle);
mapStyle.maxwvel.set(maxwvelImperialMPHStyle);
}
};

const handleUnitChange = (event) => {
console.log(event.target.value);
setUnit(event.target.value);
unitsType.set(event.target.value);
const unitType = event.target.value;
console.log(unitType);
setUnit(unitType);
unitsType.set(unitType);
// if units type is set to metric - reset speed type to meters/sec
if (event.target.value === "metric") {
if (unitType === "metric") {
setSpeed(default_speed.metric);
speedType.set(default_speed.metric);
}
else {
setSpeed(default_speed.imperial);
speedType.set(default_speed.imperial);
}
setLayerStyles(unitType);
};

const handleSpeedType = (event) => {
console.log(event.target.value);
setSpeed(event.target.value);
speedType.set(event.target.value);
const stype = event.target.value;
console.log(stype);
setSpeed(stype);
speedType.set(stype);
if (stype === "mph") {
mapStyle.maxwvel.set(maxwvelImperialMPHStyle);
}
else {
mapStyle.maxwvel.set(maxwvelImperialKnotsStyle);
}
};

return (
Expand Down
15 changes: 0 additions & 15 deletions src/context/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@ import { maxeleStyle, maxwvelStyle, swanStyle } from '@utils';
export const SettingsContext = createContext({});
export const useSettings = () => useContext(SettingsContext);

export const metersToFeet = (m) => {
return m * 3.28084;
};

export const mpsToMph = (s) => {
return s * 2.236936;
};

export const mpsToKnots = (s) => {
return s *1.943844;
};

export const SettingsProvider = ({ children }) => {
const { mode, setMode } = useColorScheme();
const booleanValue = useToggleState();
Expand Down Expand Up @@ -73,9 +61,6 @@ export const SettingsProvider = ({ children }) => {
current: storedSpeedType,
set: setStoredSpeedType,
},
metersToFeet,
mpsToMph,
mpsToKnots,

mapStyle: {
maxele: {
Expand Down
185 changes: 185 additions & 0 deletions src/utils/default-styles.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Metric based styles
export const maxeleStyle = '<?xml version="1.0" encoding="UTF-8"?> \
<sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" version="1.1.0"> \
<sld:NamedLayer> \
Expand Down Expand Up @@ -131,4 +132,188 @@ export const swanStyle = '<?xml version="1.0" encoding="UTF-8"?><sld:StyledLayer
</sld:FeatureTypeStyle> \
</sld:UserStyle> \
</sld:NamedLayer> \
</sld:StyledLayerDescriptor>';

// Imperial based styles
export const maxeleImperialStyle = '<?xml version="1.0" encoding="UTF-8"?> \
<sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" version="1.1.0"> \
<sld:NamedLayer> \
<sld:Name>maxele_client_style</sld:Name> \
<sld:UserStyle> \
<sld:Name>maxele_client_style</sld:Name> \
<sld:FeatureTypeStyle> \
<sld:Name>name</sld:Name> \
<sld:Rule> \
<sld:RasterSymbolizer> \
<sld:ChannelSelection> \
<sld:GrayChannel> \
<sld:SourceChannelName>1</sld:SourceChannelName> \
<sld:ContrastEnhancement> \
<sld:GammaValue>1.0</sld:GammaValue> \
</sld:ContrastEnhancement> \
</sld:GrayChannel> \
</sld:ChannelSelection> \
<sld:ColorMap> \
<sld:ColorMapEntry color="#313695" quantity="0.00" label="0.00 m"/> \
<sld:ColorMapEntry color="#323C98" quantity="0.3048" label="1.0 ft"/> \
<sld:ColorMapEntry color="#4E80B9" quantity="0.6096" label="2.0 ft"/> \
<sld:ColorMapEntry color="#84BAD8" quantity="0.9144000000000001" label="3.0 ft"/> \
<sld:ColorMapEntry color="#C0E3EF" quantity="1.2192" label="4.0 ft"/> \
<sld:ColorMapEntry color="#EFF9DB" quantity="1.524" label="5.0 ft"/> \
<sld:ColorMapEntry color="#FEECA2" quantity="1.8288000000000002" label="6.0 ft"/> \
<sld:ColorMapEntry color="#FDBD6F" quantity="2.1336" label="7.0 ft"/> \
<sld:ColorMapEntry color="#F57A49" quantity="2.4384" label="8.0 ft"/> \
<sld:ColorMapEntry color="#D93629" quantity="2.7432000000000003" label="9.0 ft"/> \
<sld:ColorMapEntry color="#A50026" quantity="3.048" label="10.0 ft"/> \
</sld:ColorMap> \
<sld:ContrastEnhancement/> \
</sld:RasterSymbolizer> \
</sld:Rule> \
</sld:FeatureTypeStyle> \
</sld:UserStyle> \
</sld:NamedLayer> \
</sld:StyledLayerDescriptor>';

export const maxwvelImperialMPHStyle = '<?xml version="1.0" encoding="UTF-8"?><sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" version="1.1.0"> \
<sld:NamedLayer> \
<sld:Name>maxwvel_client_style</sld:Name> \
<sld:UserStyle> \
<sld:Name>maxwvel_client_style</sld:Name> \
<sld:FeatureTypeStyle> \
<sld:Name>name</sld:Name> \
<sld:Rule> \
<sld:RasterSymbolizer> \
<sld:ChannelSelection> \
<sld:GrayChannel> \
<sld:SourceChannelName>1</sld:SourceChannelName> \
<sld:ContrastEnhancement> \
<sld:GammaValue>1.0</sld:GammaValue> \
</sld:ContrastEnhancement> \
</sld:GrayChannel> \
</sld:ChannelSelection> \
<sld:ColorMap> \
<sld:ColorMapEntry color="#3E26A9" quantity="0.0" label="0.0 mph"/> \
<sld:ColorMapEntry color="#4433CD" quantity="2.2352" label="5.0 mph"/> \
<sld:ColorMapEntry color="#4743E8" quantity="4.4704" label="10.0 mph"/> \
<sld:ColorMapEntry color="#4755F6" quantity="6.7056" label="15.0 mph"/> \
<sld:ColorMapEntry color="#4367FE" quantity="8.9408" label="20.0 mph"/> \
<sld:ColorMapEntry color="#337AFD" quantity="11.176" label="25.0 mph"/> \
<sld:ColorMapEntry color="#2D8CF4" quantity="13.4112" label="30.0 mph"/> \
<sld:ColorMapEntry color="#259CE8" quantity="15.6464" label="35.0 mph"/> \
<sld:ColorMapEntry color="#1BAADF" quantity="17.8816" label="40.0 mph"/> \
<sld:ColorMapEntry color="#04B6CE" quantity="20.1168" label="45.0 mph"/> \
<sld:ColorMapEntry color="#12BEB9" quantity="22.352" label="50.0 mph"/> \
<sld:ColorMapEntry color="#2FC5A2" quantity="24.5872" label="55.0 mph"/> \
<sld:ColorMapEntry color="#47CB86" quantity="26.8224" label="60.0 mph"/> \
<sld:ColorMapEntry color="#71CD64" quantity="29.0576" label="65.0 mph"/> \
<sld:ColorMapEntry color="#9FC941" quantity="31.2928" label="70.0 mph"/> \
<sld:ColorMapEntry color="#C9C128" quantity="33.528" label="75.0 mph"/> \
<sld:ColorMapEntry color="#EBBB30" quantity="35.7632" label="80.0 mph"/> \
<sld:ColorMapEntry color="#FFC13A" quantity="37.9984" label="85.0 mph"/> \
<sld:ColorMapEntry color="#FBD42E" quantity="40.2336" label="90.0 mph"/> \
<sld:ColorMapEntry color="#F5E824" quantity="42.4688" label="95.0 mph"/> \
<sld:ColorMapEntry color="#FAFB14" quantity="44.704" label="100.0 mph"/> \
</sld:ColorMap> \
<sld:ContrastEnhancement/> \
</sld:RasterSymbolizer> \
</sld:Rule> \
</sld:FeatureTypeStyle> \
</sld:UserStyle> \
</sld:NamedLayer> \
</sld:StyledLayerDescriptor>';

export const maxwvelImperialKnotsStyle = '<?xml version="1.0" encoding="UTF-8"?><sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" version="1.1.0"> \
<sld:NamedLayer> \
<sld:Name>maxwvel_client_style</sld:Name> \
<sld:UserStyle> \
<sld:Name>maxwvel_client_style</sld:Name> \
<sld:FeatureTypeStyle> \
<sld:Name>name</sld:Name> \
<sld:Rule> \
<sld:RasterSymbolizer> \
<sld:ChannelSelection> \
<sld:GrayChannel> \
<sld:SourceChannelName>1</sld:SourceChannelName> \
<sld:ContrastEnhancement> \
<sld:GammaValue>1.0</sld:GammaValue> \
</sld:ContrastEnhancement> \
</sld:GrayChannel> \
</sld:ChannelSelection> \
<sld:ColorMap> \
<sld:ColorMapEntry color="#3E26A9" quantity="0.0" label="0.0 kn"/> \
<sld:ColorMapEntry color="#4433CD" quantity="2.57222" label="5.0 kn"/> \
<sld:ColorMapEntry color="#4743E8" quantity="5.14444" label="10.0 kn"/> \
<sld:ColorMapEntry color="#4755F6" quantity="7.71666" label="15 kn"/> \
<sld:ColorMapEntry color="#4367FE" quantity="10.28888" label="20.0 kn"/> \
<sld:ColorMapEntry color="#337AFD" quantity="12.8611" label="25.0 kn"/> \
<sld:ColorMapEntry color="#2D8CF4" quantity="15.43332" label="30.0 kn"/> \
<sld:ColorMapEntry color="#259CE8" quantity="18.00554" label="35.0 kn"/> \
<sld:ColorMapEntry color="#1BAADF" quantity="20.57776" label="40.0 kn"/> \
<sld:ColorMapEntry color="#04B6CE" quantity="23.14998" label="45.0 kn"/> \
<sld:ColorMapEntry color="#12BEB9" quantity="25.7222" label="50.0 kn"/> \
<sld:ColorMapEntry color="#2FC5A2" quantity="28.294420000000002" label="55.0 kn"/> \
<sld:ColorMapEntry color="#47CB86" quantity="30.86664" label="60.0 kn"/> \
<sld:ColorMapEntry color="#71CD64" quantity="33.43886" label="65.0 kn"/> \
<sld:ColorMapEntry color="#9FC941" quantity="36.01108" label="70.0 kn"/> \
<sld:ColorMapEntry color="#C9C128" quantity="38.5833" label="75.0 kn"/> \
<sld:ColorMapEntry color="#EBBB30" quantity="41.15552" label="80.0 kn"/> \
<sld:ColorMapEntry color="#FFC13A" quantity="43.727740000000004" label="85.0 kn"/> \
<sld:ColorMapEntry color="#FBD42E" quantity="46.29996" label="90.0 kn"/> \
<sld:ColorMapEntry color="#F5E824" quantity="48.87218" label="95.0 kn"/> \
<sld:ColorMapEntry color="#FAFB14" quantity="51.4444" label="100.0 kn"/> \
</sld:ColorMap> \
<sld:ContrastEnhancement/> \
</sld:RasterSymbolizer> \
</sld:Rule> \
</sld:FeatureTypeStyle> \
</sld:UserStyle> \
</sld:NamedLayer> \
</sld:StyledLayerDescriptor>';

export const swanImperialStyle = '<?xml version="1.0" encoding="UTF-8"?><sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" version="1.1.0"> \
<sld:NamedLayer> \
<sld:Name>swan_client_style</sld:Name> \
<sld:UserStyle> \
<sld:Name>swan_client_style</sld:Name> \
<sld:FeatureTypeStyle> \
<sld:Name>name</sld:Name> \
<sld:Rule> \
<sld:RasterSymbolizer> \
<sld:ChannelSelection> \
<sld:GrayChannel> \
<sld:SourceChannelName>1</sld:SourceChannelName> \
<sld:ContrastEnhancement> \
<sld:GammaValue>1.0</sld:GammaValue> \
</sld:ContrastEnhancement> \
</sld:GrayChannel> \
</sld:ChannelSelection> \
<sld:ColorMap> \
<sld:ColorMapEntry color="#30123B" quantity="0.0" label="0.0 ft"/> \
<sld:ColorMapEntry color="#3D3790" quantity="0.9144000000000001" label="3.0 ft"/> \
<sld:ColorMapEntry color="#455ACD" quantity="1.8288000000000002" label="6.0 ft"/> \
<sld:ColorMapEntry color="#467BF3" quantity="2.7432000000000003" label="9.0 ft"/> \
<sld:ColorMapEntry color="#3E9BFF" quantity="3.6576000000000004" label="12.0 ft"/> \
<sld:ColorMapEntry color="#28BBEC" quantity="4.572" label="15.0 ft"/> \
<sld:ColorMapEntry color="#18D7CC" quantity="5.486400000000001" label="18.0 ft"/> \
<sld:ColorMapEntry color="#21EBAC" quantity="6.4008" label="21.0 ft"/> \
<sld:ColorMapEntry color="#46F884" quantity="7.315200000000001" label="24.0 ft"/> \
<sld:ColorMapEntry color="#78FF5A" quantity="8.2296" label="27.0 ft"/> \
<sld:ColorMapEntry color="#A3FD3C" quantity="9.144" label="30.0 ft"/> \
<sld:ColorMapEntry color="#C4F133" quantity="10.0584" label="33.0 ft"/> \
<sld:ColorMapEntry color="#E2DD37" quantity="10.972800000000001" label="36.0 ft"/> \
<sld:ColorMapEntry color="#F6C33A" quantity="11.8872" label="39.0 ft"/> \
<sld:ColorMapEntry color="#FEA531" quantity="12.8016" label="42.0 ft"/> \
<sld:ColorMapEntry color="#FC8021" quantity="13.716000000000001" label="45.0 ft"/> \
<sld:ColorMapEntry color="#F05B11" quantity="14.630400000000002" label="48.0 ft"/> \
<sld:ColorMapEntry color="#DE3D08" quantity="15.5448" label="51.0 ft"/> \
<sld:ColorMapEntry color="#C42502" quantity="16.4592" label="54.0 ft"/> \
<sld:ColorMapEntry color="#A31201" quantity="17.3736" label="57.0 ft"/> \
<sld:ColorMapEntry color="#7A0402" quantity="18.288" label="60.0 ft"/> \
</sld:ColorMap> \
<sld:ContrastEnhancement/> \
</sld:RasterSymbolizer> \
</sld:Rule> \
</sld:FeatureTypeStyle> \
</sld:UserStyle> \
</sld:NamedLayer> \
</sld:StyledLayerDescriptor>';
Loading

0 comments on commit 40669ad

Please sign in to comment.