Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getCapabilities improvements #133

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
52 changes: 41 additions & 11 deletions src/lib/get-capabilities.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -52,21 +52,45 @@ 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) {
/**
* GetCapabilities wfs or wcs based on the input 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) {
Expand All @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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'),
Expand All @@ -173,7 +197,7 @@ export function getLayerProperties(capabilities, layer) {
getTags('Keyword'),
map(getTagContent),
)()

if (!keywords.length) {

keywords = pipe(
Expand All @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }))
Expand Down
Loading