Skip to content

Commit

Permalink
Merge pull request #133 from openearth/fix-getcapabilities-type
Browse files Browse the repository at this point in the history
getCapabilities improvements
  • Loading branch information
luisrodriguezgalvez authored Jan 29, 2025
2 parents 0ca4674 + 8d58e07 commit f289718
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 19 deletions.
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
7 changes: 6 additions & 1 deletion src/lib/build-download-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

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
14 changes: 10 additions & 4 deletions src/lib/wfs-filter-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -39,16 +41,20 @@ export function readFeatureProperties(describeFeatureTypeResponse) {
}

//const of the filterTemplate
export const filterTemplate = (filters) =>
`
export function filterTemplate(filters) {
if (filters.length) {
return `
<ogc:Filter
xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
${ filters.length ? createOgcFiltersXml(filters) : '' }
${ createOgcFiltersXml(filters) }
</ogc:And>
</ogc:Filter>
`
}
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 = ''
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

3 comments on commit f289718

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://nl2120.netlify.app as production
🚀 Deployed on https://679a62864084d20d4b363b87--nl2120.netlify.app

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.