Skip to content

Commit

Permalink
fix: wms
Browse files Browse the repository at this point in the history
  • Loading branch information
majkshkurti committed Sep 5, 2024
1 parent 14ca43f commit 9981486
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
21 changes: 10 additions & 11 deletions apps/web/components/modals/DatasetExternal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ interface DatasetExternalProps {
interface ExternalDatasetType {
name: string;
value: DataType;
urlPlaceholder: string;
icon: ICON_NAME;
}

Expand All @@ -85,25 +84,21 @@ 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,
urlPlaceholder: "https://serviceurl.com",
icon: ICON_NAME.WMS,
},
{
name: "Web Map Tile Service (WMTS)",
value: imageryDataType.Enum.wmts,
urlPlaceholder: "https://serviceurl.com",
icon: ICON_NAME.WMTS,
},
{
name: "XYZ Tiles",
value: "xyz",
urlPlaceholder: "https://serviceurl.com/{z}/{x}/{y}",
icon: ICON_NAME.XYZ,
},
];
Expand Down Expand Up @@ -243,7 +238,7 @@ const getNestedLayerMultiSelectionTableBody = (
type
) => {
if (depth > 4) return null;

console.log(layers);
return (
<React.Fragment>
{layers.map((layer) => (
Expand Down Expand Up @@ -581,20 +576,24 @@ const DatasetExternal: React.FC<DatasetExternalProps> = ({ open, onClose, projec
capabilities?.type === imageryDataType.Enum.wmts ||
(capabilities?.type === imageryDataType.Enum.xyz && capabilities.directUrl)
) {
let layers;
let layers = [] as string[];
let url = externalUrl;
const legendUrls = [] as string[];
if (capabilities.type === imageryDataType.Enum.wms) {
layers = selectedDatasets.map((d) => d.Name);
if (!externalUrl) return;
const baseUrl = getBaseUrl(externalUrl);
let styles = [] as string[];
const version = capabilities.capabilities?.version;
url = generateWmsUrl(baseUrl, layers, version);
const baseUrl = getBaseUrl(externalUrl);
selectedDatasets.forEach((dataset) => {
const _layer = dataset.Name;
const legendGraphicUrl = generateLayerGetLegendGraphicUrl(baseUrl, _layer, "default", version);
const styleName = dataset.Style[0]?.Name; //todo: WMS can have multiple styles. This has to be handled in the future.
if (!styleName || !_layer) return;
layers.push(_layer);
styles.push(styleName);
const legendGraphicUrl = generateLayerGetLegendGraphicUrl(baseUrl, _layer, styleName, version);
legendUrls.push(legendGraphicUrl);
});
url = generateWmsUrl(baseUrl, layers, styles, version);
} else if (capabilities.type === imageryDataType.Enum.wmts) {
if (capabilities.directUrl) {
url = convertWmtsToXYZUrl(capabilities.directUrl);
Expand Down
4 changes: 2 additions & 2 deletions apps/web/lib/transformers/wms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export const DEFAULT_VERSION = '1.3.0';
* @returns {string} - The generated WMS URL with the specified parameters.
*/

export const generateWmsUrl = (baseUrl, layers, version?, dpi?) => {
export const generateWmsUrl = (baseUrl, layers, styles, version?, dpi?) => {
const width = 256;
const height = 256;
const _dpi = dpi || 90;
const _version = version || DEFAULT_VERSION;
return `${baseUrl}?bbox={bbox-epsg-3857}&service=WMS&REQUEST=GetMap&layers=${layers}&FORMAT=image/png&TRANSPARENT=true&WIDTH=${width}&HEIGHT=${height}&SRS=EPSG:3857&CRS=EPSG:3857&VERSION=${_version}&STYLES=default&DPI=${_dpi}&MAP_RESOLUTION=${_dpi}&FORMAT_OPTIONS=dpi:${_dpi}`;
return `${baseUrl}?bbox={bbox-epsg-3857}&service=WMS&REQUEST=GetMap&layers=${layers}&FORMAT=image/png&TRANSPARENT=true&WIDTH=${width}&HEIGHT=${height}&SRS=EPSG:3857&CRS=EPSG:3857&VERSION=${_version}&STYLES=${styles}&DPI=${_dpi}&MAP_RESOLUTION=${_dpi}&FORMAT_OPTIONS=dpi:${_dpi}`;
};


Expand Down

0 comments on commit 9981486

Please sign in to comment.