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/build-download-url.js b/src/lib/build-download-url.js index ea9eb500..5911d5b4 100644 --- a/src/lib/build-download-url.js +++ b/src/lib/build-download-url.js @@ -7,7 +7,12 @@ import { export default function({ layer = {}, filters = [], format, coordinates = '' }) { - const { url } = layer + let url + if (layer.downloadUrl) { + url = layer.downloadUrl + } else { + url = layer.url + } const params = createDownloadParameters({ layerData: layer, filters, coordinates, format }) diff --git a/src/lib/get-capabilities.js b/src/lib/get-capabilities.js index f897f822..0afdb916 100644 --- a/src/lib/get-capabilities.js +++ b/src/lib/get-capabilities.js @@ -1,7 +1,7 @@ +/* Contains any functions and utils related to the wms, wfs and wcs getCapabilities */ import axios from 'axios' import { map, uniq, pipe } from 'ramda' - import { WCS_LAYER_TYPE, WFS_LAYER_TYPE, @@ -52,7 +52,19 @@ function createParameters(type) { } } - +async function getServiceType(serviceUrl) { + try { + await axios.get(`${serviceUrl.replace('wms', 'wfs') }?${ createParameters('wfs') }`) + return 'wfs' + } catch (error) { + try { + await axios.get(`${ serviceUrl.replace('wfs', 'wcs') }?${ createParameters('wcs') }`) + return 'wcs' + } catch (error) { + return 'Unknown' + } + } +} export async function getCapabilities(service, type) { /** @@ -60,13 +72,25 @@ export async function getCapabilities(service, type) { * create parameters and make the request * parse it as a dom element */ - const _type = type + + 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) { @@ -77,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') @@ -137,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 @@ -149,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'), @@ -173,7 +197,7 @@ export function getLayerProperties(capabilities, layer) { getTags('Keyword'), map(getTagContent), )() - + if (!keywords.length) { keywords = pipe( @@ -183,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/lib/wfs-filter-helpers.js b/src/lib/wfs-filter-helpers.js index f91359fc..4b50000a 100644 --- a/src/lib/wfs-filter-helpers.js +++ b/src/lib/wfs-filter-helpers.js @@ -27,7 +27,9 @@ export async function describeFeatureType({ url, layer }) { excludes geom */ export function readFeatureProperties(describeFeatureTypeResponse) { - + if (describeFeatureTypeResponse === undefined) { + return [] + } const { featureTypes } = describeFeatureTypeResponse const properties = featureTypes[0].properties @@ -39,16 +41,20 @@ export function readFeatureProperties(describeFeatureTypeResponse) { } //const of the filterTemplate -export const filterTemplate = (filters) => - ` +export function filterTemplate(filters) { + if (filters.length) { + return ` - ${ filters.length ? createOgcFiltersXml(filters) : '' } + ${ createOgcFiltersXml(filters) } ` + } + return '' +} //For each filter object in the filtersArray, calls the ogcFilterLibrary to create the filter based on the comparer case function createOgcFiltersXml(filtersArray) { let ogcFilters = '' 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 } }))