From bdecaf234244d0566097c002322eb1fe471ddc55 Mon Sep 17 00:00:00 2001 From: majkshkurti Date: Wed, 4 Sep 2024 09:44:26 +0200 Subject: [PATCH] fix --- .../web/components/map/panels/layer/Layer.tsx | 6 +-- .../web/components/modals/DatasetExternal.tsx | 49 +++++++++---------- apps/web/hooks/map/LayerPanelHooks.ts | 32 ++++++++++++ apps/web/lib/transformers/wmts.ts | 34 ++++++++----- apps/web/lib/validations/layer.ts | 1 + 5 files changed, 80 insertions(+), 42 deletions(-) diff --git a/apps/web/components/map/panels/layer/Layer.tsx b/apps/web/components/map/panels/layer/Layer.tsx index 32f0a60f..91a1d87e 100644 --- a/apps/web/components/map/panels/layer/Layer.tsx +++ b/apps/web/components/map/panels/layer/Layer.tsx @@ -523,7 +523,7 @@ const LayerPanel = ({ projectId }: PanelProps) => { {layer.type === "table" ? null : ( { transition: theme.transitions.create(["opacity"], { duration: theme.transitions.duration.standard, }), - opacity: !layer.properties.visibility ? 1 : 0, + opacity: !layer.properties?.visibility ? 1 : 0, }}> { setSelectedDatasets((prevSelectedDatasets) => { if (type === vectorDataType.Enum.wfs || type === imageryDataType.Enum.wmts) { @@ -167,7 +169,7 @@ const DatasetsSelectTable = ({ options, type, selectedDatasets, setSelectedDatas {options.map((dataset) => ( ))} - {options.length === 0 && ( - - - - )} + {options.length === 0 && ( + + + + )} {(type === imageryDataType.Enum.wms || type === imageryDataType.Enum.wmts) && ( @@ -240,7 +242,6 @@ const DatasetExternal: React.FC = ({ open, onClose, projec const [capabilities, setCapabilities] = useState(null); // Step 1: Select Layer - // The reason why this is an array is because WMS can have multiple layers. // Technically, WFS can have multiple layers too but we only support one layer to be able to use features for analytics. const [selectedDatasets, setSelectedDatasets] = useState([]); @@ -258,11 +259,9 @@ const DatasetExternal: React.FC = ({ open, onClose, projec }); } } else if (capabilities?.type === imageryDataType.Enum.wms) { - const datasets = _capabilities?.Capability?.Layer; - if (datasets?.length) { - datasets.forEach((dataset: any) => { - options.push(dataset); - }); + const dataset = _capabilities?.Capability?.Layer; + if (dataset) { + options.push(dataset); } } else if (capabilities?.type === imageryDataType.Enum.wmts && _capabilities) { const datasets = getWmtsFlatLayers(_capabilities); @@ -301,7 +300,6 @@ const DatasetExternal: React.FC = ({ open, onClose, projec if (activeStep === 0) { if (!externalUrl) return; const urlCapabilities = findExternalDatasetType(externalUrl); - console.log(urlCapabilities); if (urlCapabilities) { setCapabilities(urlCapabilities); const homeFolder = folders?.find((folder) => folder.name === "home"); @@ -372,8 +370,6 @@ const DatasetExternal: React.FC = ({ open, onClose, projec setValue("name", selectedDatasets[0].Title || selectedDatasets[0].Name || ""); setValue("description", selectedDatasets[0].Abstract || ""); } - - console.log(selectedDatasets); } else if (activeStep === 2) { setActiveStep((prevActiveStep) => prevActiveStep + 1); } @@ -442,6 +438,9 @@ const DatasetExternal: React.FC = ({ open, onClose, projec type: "raster", data_type: capabilities.type, url, + properties: { + visibility: true, + }, other_properties: { ...(layers && { layers }), }, @@ -450,8 +449,7 @@ const DatasetExternal: React.FC = ({ open, onClose, projec } toast.success(t("success_adding_external_dataset")); - } catch (error) { - console.error(error); + } catch (_error) { toast.error(t("error_adding_external_dataset")); } finally { setIsBusy(false); @@ -489,7 +487,7 @@ const DatasetExternal: React.FC = ({ open, onClose, projec return ( <> - + {t("dataset_external")} @@ -514,7 +512,6 @@ const DatasetExternal: React.FC = ({ open, onClose, projec helperText={errorMessage} placeholder={t("url")} onChange={(e) => { - console.log(e.target.value); setErrorMessage(null); setExternalUrl(e.target.value); setCapabilities(null); diff --git a/apps/web/hooks/map/LayerPanelHooks.ts b/apps/web/hooks/map/LayerPanelHooks.ts index 9e70a714..d43673b4 100644 --- a/apps/web/hooks/map/LayerPanelHooks.ts +++ b/apps/web/hooks/map/LayerPanelHooks.ts @@ -123,6 +123,38 @@ export const useLayerSettingsMoreMenu = () => { return tableOptions; } + if (layerType === "raster") { + const rasterOptions = [ + { + id: MapLayerActions.PROPERTIES, + label: t("properties"), + icon: ICON_NAME.CIRCLEINFO, + }, + { + id: MapLayerActions.ZOOM_TO, + label: t("zoom_to"), + icon: ICON_NAME.ZOOM_IN, + }, + { + id: MapLayerActions.DUPLICATE, + label: t("duplicate"), + icon: ICON_NAME.COPY, + }, + { + id: MapLayerActions.RENAME, + label: t("rename"), + icon: ICON_NAME.EDIT, + }, + { + id: ContentActions.DELETE, + label: t("remove"), + icon: ICON_NAME.TRASH, + color: "error.main", + }, + ]; + + return rasterOptions; + } return []; } diff --git a/apps/web/lib/transformers/wmts.ts b/apps/web/lib/transformers/wmts.ts index c48f9365..63599d8b 100644 --- a/apps/web/lib/transformers/wmts.ts +++ b/apps/web/lib/transformers/wmts.ts @@ -81,20 +81,28 @@ export const getWmtsFlatLayers = (capabilities) => { const tileMatrixSetLink = dataset.TileMatrixSetLink.find((link) => link.TileMatrixSet.includes(webMercator.Identifier) ); - const supportsPng = dataset.Format.includes("image/png"); - const resourceUrl = dataset.ResourceURL.find((url) => url.format.includes("image/png")); - if (tileMatrixSetLink && supportsPng) { + const supportedFormats = ["image/png", "image/jpeg", "image/tiff", "image/png8"]; + const resourceUrls = supportedFormats.map((format) => ({ + format, + url: dataset.ResourceURL.find((url) => url.format.includes(format)), + })); + + if (tileMatrixSetLink) { dataset.Style.forEach((style) => { - options.push({ - Identifier: dataset.Identifier, - ResourceURL: resourceUrl.template, - Format: "image/png", - TileMatrixSet: tileMatrixSetLink.TileMatrixSet, - CRS: "EPSG:3857", - Style: style.Identifier, - Title: dataset.Title, - Abstract: dataset.Abstract, - WGS84BoundingBox: dataset.WGS84BoundingBox, + resourceUrls.forEach(({ format, url }) => { + if (url) { + options.push({ + Identifier: dataset.Identifier, + ResourceURL: url.template, + Format: format, + TileMatrixSet: tileMatrixSetLink.TileMatrixSet, + CRS: "EPSG:3857", + Style: style.Identifier, + Title: dataset.Title, + Abstract: dataset.Abstract, + WGS84BoundingBox: dataset.WGS84BoundingBox, + }); + } }); }); } diff --git a/apps/web/lib/validations/layer.ts b/apps/web/lib/validations/layer.ts index 6fc2bc51..9fb07594 100644 --- a/apps/web/lib/validations/layer.ts +++ b/apps/web/lib/validations/layer.ts @@ -223,6 +223,7 @@ export const createRasterLayerSchema = createLayerBaseSchema.extend({ url: z.string().url(), data_type: dataType, extent: z.string().optional(), + properties: z.record(z.any()).optional(), // add validation for raster properties other_properties: otherPropertiesSchmea, })