From 921263c0a8fd205510fe1c1cfba6710421521377 Mon Sep 17 00:00:00 2001 From: Junqiu Lei Date: Fri, 30 Dec 2022 18:21:31 -0800 Subject: [PATCH] Update WMS Signed-off-by: Junqiu Lei --- .../custom_map_config/custom_map_source.tsx | 61 +++++++++++++++++-- .../public/model/customLayerFunctions.ts | 3 +- maps_dashboards/public/model/mapLayerType.ts | 2 + .../public/utils/getIntialConfig.ts | 8 ++- 4 files changed, 66 insertions(+), 8 deletions(-) diff --git a/maps_dashboards/public/components/layer_config/custom_map_config/custom_map_source.tsx b/maps_dashboards/public/components/layer_config/custom_map_config/custom_map_source.tsx index 68bc21fa..a00ac4b2 100644 --- a/maps_dashboards/public/components/layer_config/custom_map_config/custom_map_source.tsx +++ b/maps_dashboards/public/components/layer_config/custom_map_config/custom_map_source.tsx @@ -36,15 +36,17 @@ export const CustomMapSource = ({ const [customMapURL, setCustomMapURL] = useState(''); const [customMapAttribution, setCustomMapAttribution] = useState(''); - const [protocol, setProtocol] = useState(customMapProtocolOptions[0].value); + const [protocol, setProtocol] = useState(customMapProtocolOptions[1].value); const [WMSLayers, setWMSLayers] = useState(''); const [WMSVersion, setWMSVersion] = useState(''); const [WMSFormat, setWMSFormat] = useState(''); const [WMSStyles, setWMSStyles] = useState(''); + // CRS: Coordinate reference systems in WMS + const [WMSCRS, setWMSCRS] = useState(''); + const [WMSBbox, setWMSBbox] = useState(''); const onChangeCustomMapURL = (e: any) => { setCustomMapURL(e.target.value); - setIsUpdateDisabled(false); setSelectedLayerConfig({ ...selectedLayerConfig, source: { @@ -56,7 +58,6 @@ export const CustomMapSource = ({ const onChangeCustomMapAttribution = (e: any) => { setCustomMapAttribution(e.target.value); - setIsUpdateDisabled(false); setSelectedLayerConfig({ ...selectedLayerConfig, source: { @@ -121,7 +122,30 @@ export const CustomMapSource = ({ }); }; + const onChangeWMSCRS = (e: any) => { + setWMSCRS(e.target.value); + setSelectedLayerConfig({ + ...selectedLayerConfig, + source: { + ...selectedLayerConfig?.source, + crs: e.target.value, + }, + }); + }; + + const onChangeWMSBbox = (e: any) => { + setWMSBbox(e.target.value); + setSelectedLayerConfig({ + ...selectedLayerConfig, + source: { + ...selectedLayerConfig?.source, + bbox: e.target.value, + }, + }); + }; + const isInvalidURL = (url: string): boolean => { + if (url === '') return false; try { new URL(url); return false; @@ -139,6 +163,8 @@ export const CustomMapSource = ({ setWMSVersion(selectedLayerConfig.source.version); setWMSFormat(selectedLayerConfig.source.format); setWMSStyles(selectedLayerConfig.source.styles); + setWMSCRS(selectedLayerConfig.source.crs); + setWMSBbox(selectedLayerConfig.source.bbox); } }, [selectedLayerConfig]); @@ -147,9 +173,22 @@ export const CustomMapSource = ({ }, [selectedLayerConfig.source.attribution]); useEffect(() => { - const disableUpdate = isInvalidURL(customMapURL); - setIsUpdateDisabled(disableUpdate); - }, [customMapURL, setIsUpdateDisabled]); + if (protocol === 'wms') { + setIsUpdateDisabled(isInvalidURL(customMapURL) || WMSLayers === '' || WMSVersion === ''); + } else { + setIsUpdateDisabled(isInvalidURL(customMapURL)); + } + }, [ + WMSBbox, + WMSCRS, + WMSFormat, + WMSLayers, + WMSStyles, + WMSVersion, + customMapURL, + protocol, + setIsUpdateDisabled, + ]); return (
@@ -234,6 +273,16 @@ export const CustomMapSource = ({ + + WMS CRS + + + + + WMS bbox + + + WMS attribution diff --git a/maps_dashboards/public/model/customLayerFunctions.ts b/maps_dashboards/public/model/customLayerFunctions.ts index 24f7bc17..d318ce9f 100644 --- a/maps_dashboards/public/model/customLayerFunctions.ts +++ b/maps_dashboards/public/model/customLayerFunctions.ts @@ -79,7 +79,8 @@ const getCustomMapURL = (layerConfig: CustomLayerSpecification) => { if (layerSource?.protocol === 'tms') { return layerSource?.url; } else if (layerSource?.protocol === 'wms') { - return `${layerSource?.url}?service=WMS&version=${layerSource.version}&request=GetMap&format=${layerSource.format}&transparent=true&layers=${layerSource?.layers}&styles=${layerSource.styles}&SRS=EPSG%3A3857&WIDTH=256&HEIGHT=256&BBOX={bbox-epsg-3857}`; + const referenceSystemName = layerSource.version === '1.3.0' ? 'crs' : 'srs'; + return `${layerSource?.url}?service=WMS&version=${layerSource.version}&request=GetMap&format=${layerSource.format}&transparent=true&layers=${layerSource?.layers}&styles=${layerSource.styles}&${referenceSystemName}=${layerSource.crs}&width=256&height=256&bbox={bbox-epsg-3857}`; } else { return ''; } diff --git a/maps_dashboards/public/model/mapLayerType.ts b/maps_dashboards/public/model/mapLayerType.ts index f44b141b..76e72899 100644 --- a/maps_dashboards/public/model/mapLayerType.ts +++ b/maps_dashboards/public/model/mapLayerType.ts @@ -86,5 +86,7 @@ export type CustomWMSLayerSpecification = { styles: string; version: string; format: string; + crs: string; + bbox: string; }; }; diff --git a/maps_dashboards/public/utils/getIntialConfig.ts b/maps_dashboards/public/utils/getIntialConfig.ts index 7e073834..007e3788 100644 --- a/maps_dashboards/public/utils/getIntialConfig.ts +++ b/maps_dashboards/public/utils/getIntialConfig.ts @@ -71,8 +71,14 @@ export const getLayerConfigMap = () => ({ visibility: LAYER_VISIBILITY.VISIBLE, source: { url: '', - protocol: 'tms', + protocol: 'wms', attribution: '', + layers: '', + styles: '', + version: '', + format: '', + crs: '', + bbox: '', }, }, });