Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
majkshkurti committed Sep 4, 2024
1 parent fc64c23 commit bdecaf2
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 42 deletions.
6 changes: 3 additions & 3 deletions apps/web/components/map/panels/layer/Layer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ const LayerPanel = ({ projectId }: PanelProps) => {
{layer.type === "table" ? null : (
<Tooltip
key={layer.id}
title={layer.properties.visibility ? t("show_layer") : t("hide_layer")}
title={layer.properties?.visibility ? t("show_layer") : t("hide_layer")}
arrow
placement="top">
<IconButton
Expand All @@ -536,11 +536,11 @@ const LayerPanel = ({ projectId }: PanelProps) => {
transition: theme.transitions.create(["opacity"], {
duration: theme.transitions.duration.standard,
}),
opacity: !layer.properties.visibility ? 1 : 0,
opacity: !layer.properties?.visibility ? 1 : 0,
}}>
<Icon
iconName={
!layer.properties.visibility ? ICON_NAME.EYE_SLASH : ICON_NAME.EYE
!layer.properties?.visibility ? ICON_NAME.EYE_SLASH : ICON_NAME.EYE
}
style={{
fontSize: 15,
Expand Down
49 changes: 23 additions & 26 deletions apps/web/components/modals/DatasetExternal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ interface CapabilitiesType {
}

const externalDatasetTypes: ExternalDatasetType[] = [
{
name: "Web Feature Service (WFS)",
value: vectorDataType.Enum.wfs,
urlPlaceholder: "https://serviceurl.com",
icon: ICON_NAME.WFS,
},
{
name: "Web Map Service (WMS)",
value: imageryDataType.Enum.wms,
Expand All @@ -87,12 +93,6 @@ const externalDatasetTypes: ExternalDatasetType[] = [
urlPlaceholder: "https://serviceurl.com",
icon: ICON_NAME.WMTS,
},
{
name: "Web Feature Service (WFS)",
value: vectorDataType.Enum.wfs,
urlPlaceholder: "https://serviceurl.com",
icon: ICON_NAME.WFS,
},
{
name: "XYZ Tiles",
value: "xyz",
Expand Down Expand Up @@ -129,10 +129,12 @@ const DatasetsSelectTable = ({ options, type, selectedDatasets, setSelectedDatas
const columnsMap = {
wfs: ["Title", "Name", "Abstract"],
wms: ["Title", "Name", "Abstract"],
wmts: ["Title", "Identifier", "Style", "Abstract"],
wmts: ["Title", "Identifier", "Style", "Format", "Abstract"],
xyz: ["Title", "Identifier"],
};

console.log(selectedDatasets);

const handleSelectDataset = (dataset) => {
setSelectedDatasets((prevSelectedDatasets) => {
if (type === vectorDataType.Enum.wfs || type === imageryDataType.Enum.wmts) {
Expand Down Expand Up @@ -167,7 +169,7 @@ const DatasetsSelectTable = ({ options, type, selectedDatasets, setSelectedDatas
<TableBody>
{options.map((dataset) => (
<TableRow
key={dataset.Name}
key={dataset.Name || dataset.Identifier || dataset.Title}
sx={{
cursor: "pointer",
}}
Expand Down Expand Up @@ -206,13 +208,13 @@ const DatasetsSelectTable = ({ options, type, selectedDatasets, setSelectedDatas
))}
</TableRow>
))}
{options.length === 0 && (
<Stack sx={{ mt: 4 }}>
<NoValuesFound text={t("no_datasets_found")} />
</Stack>
)}
</TableBody>
</Table>
{options.length === 0 && (
<Stack sx={{ mt: 4 }}>
<NoValuesFound text={t("no_datasets_found")} />
</Stack>
)}
{(type === imageryDataType.Enum.wms || type === imageryDataType.Enum.wmts) && (
<Stack sx={{ mt: 4 }}>
<Typography variant="caption" color="textSecondary">
Expand Down Expand Up @@ -240,7 +242,6 @@ const DatasetExternal: React.FC<DatasetExternalProps> = ({ open, onClose, projec
const [capabilities, setCapabilities] = useState<CapabilitiesType | null>(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<any[]>([]);
Expand All @@ -258,11 +259,9 @@ const DatasetExternal: React.FC<DatasetExternalProps> = ({ 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);
Expand Down Expand Up @@ -301,7 +300,6 @@ const DatasetExternal: React.FC<DatasetExternalProps> = ({ 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");
Expand Down Expand Up @@ -372,8 +370,6 @@ const DatasetExternal: React.FC<DatasetExternalProps> = ({ 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);
}
Expand Down Expand Up @@ -442,6 +438,9 @@ const DatasetExternal: React.FC<DatasetExternalProps> = ({ open, onClose, projec
type: "raster",
data_type: capabilities.type,
url,
properties: {
visibility: true,
},
other_properties: {
...(layers && { layers }),
},
Expand All @@ -450,8 +449,7 @@ const DatasetExternal: React.FC<DatasetExternalProps> = ({ 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);
Expand Down Expand Up @@ -489,7 +487,7 @@ const DatasetExternal: React.FC<DatasetExternalProps> = ({ open, onClose, projec

return (
<>
<Dialog open={open} onClose={handleOnClose} fullWidth maxWidth="sm">
<Dialog open={open} onClose={handleOnClose} fullWidth maxWidth={activeStep === 1 ? "md" : "sm"}>
<DialogTitle>
{t("dataset_external")}
<Box sx={{ width: "100%", pt: 6 }}>
Expand All @@ -514,7 +512,6 @@ const DatasetExternal: React.FC<DatasetExternalProps> = ({ open, onClose, projec
helperText={errorMessage}
placeholder={t("url")}
onChange={(e) => {
console.log(e.target.value);
setErrorMessage(null);
setExternalUrl(e.target.value);
setCapabilities(null);
Expand Down
32 changes: 32 additions & 0 deletions apps/web/hooks/map/LayerPanelHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
Expand Down
34 changes: 21 additions & 13 deletions apps/web/lib/transformers/wmts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
});
});
}
Expand Down
1 change: 1 addition & 0 deletions apps/web/lib/validations/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down

0 comments on commit bdecaf2

Please sign in to comment.