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

Fix/predefined filters #147

Closed
wants to merge 7 commits into from
Closed
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
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
6 changes: 6 additions & 0 deletions src/store/modules/data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export default {
SET_CQL_FILTER(state, filter) {
state.cqlFilter = filter
},
RESET_CQL_FILTER(state) {
state.cqlFilter = null
},
RESET_TIME_EXTENT(state) {
state.timeExtent = []
},
Expand Down Expand Up @@ -172,6 +175,9 @@ export default {
},
setCQLFilter({ commit }, filter) {
commit('SET_CQL_FILTER', filter)
},
resetCQLFilter({commit}) {
commit('RESET_CQL_FILTER')
},
setOpenedFolders({ commit }, folders) {
commit('SET_OPENED_FOLDERS', folders)
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 changes: 2 additions & 1 deletion src/views/Filters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
selectedLayer() {
if (this.selectedLayer) {
this.setTimeExtent(this.selectedLayer.timeExtent)
this.resetCQLFilter()
}
},
selectedLayerCode( ) {
Expand All @@ -124,7 +125,7 @@
},
},
methods: {
...mapActions('data', [ 'setTimeExtent', 'setCQLFilter' ] ),
...mapActions('data', [ 'setTimeExtent', 'setCQLFilter', 'resetCQLFilter' ] ),
...mapActions('map', [ 'setFilteredLayerId', 'reloadLayerOnMap' ]),
setFilter(value) {
const filter = `${ this.filterName }='${ value }'`
Expand Down
Loading