From 0686f05f7322f14084b1a1fee753fbab25631e8e Mon Sep 17 00:00:00 2001 From: sjoerdbeentjes <11621275+sjoerdbeentjes@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:41:56 +0200 Subject: [PATCH 1/3] Add better checking for getCapabilities type --- .../DownloadFormatChooser.vue | 4 ++-- src/lib/get-capabilities.js | 24 ++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/components/DownloadFormatChooser/DownloadFormatChooser.vue b/src/components/DownloadFormatChooser/DownloadFormatChooser.vue index 1e2f16a8..b390dbea 100644 --- a/src/components/DownloadFormatChooser/DownloadFormatChooser.vue +++ b/src/components/DownloadFormatChooser/DownloadFormatChooser.vue @@ -53,8 +53,8 @@ async mounted() { let supportedOutputFormats = getSupportedOutputFormats(this.layer.serviceType, this.layerCapabilities) - supportedOutputFormats = moveInArrayByValue(supportedOutputFormats, 'csv', 0) - supportedOutputFormats = moveInArrayByValue(supportedOutputFormats, 'SHAPE-ZIP', 1) + supportedOutputFormats = moveInArrayByValue(supportedOutputFormats || [], 'csv', 0) + supportedOutputFormats = moveInArrayByValue(supportedOutputFormats || [], 'SHAPE-ZIP', 1) this.supportedFormats = supportedOutputFormats }, diff --git a/src/lib/get-capabilities.js b/src/lib/get-capabilities.js index f897f822..53cb883e 100644 --- a/src/lib/get-capabilities.js +++ b/src/lib/get-capabilities.js @@ -1,7 +1,6 @@ import axios from 'axios' import { map, uniq, pipe } from 'ramda' - import { WCS_LAYER_TYPE, WFS_LAYER_TYPE, @@ -52,7 +51,19 @@ function createParameters(type) { } } - +async function getType(service) { + try { + await axios.get(`${ service }?${ createParameters('WFS') }`) + return 'WFS' + } catch (error) { + try { + await axios.get(`${ service.replace('wfs', 'wcs') }?${ createParameters('WCS') }`) + return 'WCS' + } catch (error) { + return 'Unknown' + } + } +} export async function getCapabilities(service, type) { /** @@ -60,7 +71,14 @@ export async function getCapabilities(service, type) { * create parameters and make the request * parse it as a dom element */ - const _type = type + let _type = type + + if (!_type) { + _type = await getType(service) + } + + console.log(_type) + const serviceUrl = new URL(service) const servicePath = `${ serviceUrl.origin }${ serviceUrl.pathname }` From 6721c983b18129f4705710f91c77912c3920cbcc Mon Sep 17 00:00:00 2001 From: sjoerdbeentjes <11621275+sjoerdbeentjes@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:42:57 +0200 Subject: [PATCH 2/3] remove console.log --- src/lib/get-capabilities.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib/get-capabilities.js b/src/lib/get-capabilities.js index 53cb883e..0234df2e 100644 --- a/src/lib/get-capabilities.js +++ b/src/lib/get-capabilities.js @@ -77,8 +77,6 @@ export async function getCapabilities(service, type) { _type = await getType(service) } - console.log(_type) - const serviceUrl = new URL(service) const servicePath = `${ serviceUrl.origin }${ serviceUrl.pathname }` From 98f98742d06f36e9f4fa07e3a81ad17e8fbbb8c4 Mon Sep 17 00:00:00 2001 From: IoannaMi Date: Wed, 23 Oct 2024 18:53:14 +0200 Subject: [PATCH 3/3] WIP fix pdok wcs wfs capabilities --- src/lib/get-capabilities.js | 50 ++++++++++++++++++++++------------ src/store/modules/map/index.js | 2 +- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/lib/get-capabilities.js b/src/lib/get-capabilities.js index 0234df2e..0afdb916 100644 --- a/src/lib/get-capabilities.js +++ b/src/lib/get-capabilities.js @@ -1,3 +1,4 @@ +/* Contains any functions and utils related to the wms, wfs and wcs getCapabilities */ import axios from 'axios' import { map, uniq, pipe } from 'ramda' @@ -51,14 +52,14 @@ function createParameters(type) { } } -async function getType(service) { +async function getServiceType(serviceUrl) { try { - await axios.get(`${ service }?${ createParameters('WFS') }`) - return 'WFS' + await axios.get(`${serviceUrl.replace('wms', 'wfs') }?${ createParameters('wfs') }`) + return 'wfs' } catch (error) { try { - await axios.get(`${ service.replace('wfs', 'wcs') }?${ createParameters('WCS') }`) - return 'WCS' + await axios.get(`${ serviceUrl.replace('wfs', 'wcs') }?${ createParameters('wcs') }`) + return 'wcs' } catch (error) { return 'Unknown' } @@ -71,18 +72,25 @@ export async function getCapabilities(service, type) { * create parameters and make the request * parse it as a dom element */ - let _type = type - - if (!_type) { - _type = await getType(service) - } + const serviceUrl = new URL(service) - const servicePath = `${ serviceUrl.origin }${ serviceUrl.pathname }` - const { data } = await axios(`${ servicePath }?${ createParameters(_type) }`) - return new DOMParser().parseFromString(data, 'text/xml') + + try { + + const {data} = await axios(`${ servicePath }?${ createParameters(type) }`) + let parsedData = new DOMParser().parseFromString(data, 'text/xml'); + if (parsedData.getElementsByTagName('ServiceExceptionReport').length > 0) { + throw new Error('ServiceExceptionReport found'); + } + return parsedData + + } catch (error) { + const {data} = await axios (`${servicePath.replace('wms', type) }?${ createParameters(type) }`) + return new DOMParser().parseFromString(data, 'text/xml') + } } export async function getWmsCapabilities(service) { @@ -93,7 +101,6 @@ export async function getWmsCapabilities(service) { //the getcapabilities returns the capabilities of the layers in the workspace. need to search for the layer first const serviceUrl = new URL(service) const servicePath = `${ serviceUrl.origin }${ serviceUrl.pathname }` - const { data } = await axios(`${ servicePath }?service=WMS&request=GetCapabilities`) return new DOMParser().parseFromString(data, 'text/xml') @@ -153,7 +160,7 @@ export function isRasterLayer(type, capabilities, layer) { return keywords.includes('GeoTIFF') } -export function getLayerProperties(capabilities, layer) { +export async function getLayerProperties(capabilities, layerObject) { /** * function that reads the wms capabilities response of the workpspace * 1. find the given layer @@ -165,7 +172,8 @@ export function getLayerProperties(capabilities, layer) { * -time extent of layer * * * */ - + const {layer} = layerObject + const serviceUrl = layerObject.downloadUrl || layerObject.url const wmsVersion = pipe( () => capabilities.querySelector('WMS_Capabilities'), el => el.getAttribute('version'), @@ -189,7 +197,7 @@ export function getLayerProperties(capabilities, layer) { getTags('Keyword'), map(getTagContent), )() - + if (!keywords.length) { keywords = pipe( @@ -199,10 +207,16 @@ export function getLayerProperties(capabilities, layer) { )() } - const serviceType = [ 'features', 'wfs', 'FEATURES', 'WFS' ].some(val => keywords.includes(val)) ? 'wfs' + + let serviceType = [ 'features', 'wfs', 'FEATURES', 'WFS' ].some(val => keywords.includes(val)) ? 'wfs' :[ 'WCS', 'GeoTIFF', 'wcs' ].some(val => keywords.includes(val)) ? 'wcs' : null + + if (!serviceType) { + serviceType = await getServiceType(serviceUrl) + } + const timeExtent = pipe( () => [ ...capabilities.querySelectorAll('[queryable="1"], [queryable="0"], [opaque="0"]') ], getChildTags('Name'), diff --git a/src/store/modules/map/index.js b/src/store/modules/map/index.js index dd1fe42a..0bb9dc82 100644 --- a/src/store/modules/map/index.js +++ b/src/store/modules/map/index.js @@ -169,7 +169,7 @@ export default { layersToAdd.forEach((layer) => { getWmsCapabilities(layer.url) - .then(capabilities => getLayerProperties(capabilities, layer.layer)) + .then(capabilities => getLayerProperties(capabilities, layer)) .then(({ serviceType, timeExtent, wmsVersion, bbox }) => { commit('ADD_ACTIVE_FLATTENED_LAYER', { ...layer, ...{ serviceType: serviceType }, ... { timeExtent: timeExtent }, ... { version: wmsVersion }, ... { bbox: bbox } } ) commit('ADD_WMS_LAYER', buildWmsLayer({ ...layer, ...{ serviceType: serviceType }, ... { timeExtent: timeExtent }, ... { version: wmsVersion }, ... { bbox: bbox } }))