|
|
@@ -80,7 +80,21 @@ function p5WFS_GetFeature(typeName, query) { // @returns Promise
|
|
|
link += '&Filter=' + ogcFilter
|
|
|
}
|
|
|
if ('ogc:Filter' in query && 'string' === typeof query['ogc:Filter']) {
|
|
|
- postData = query['ogc:Filter']
|
|
|
+ var headerOgcFilter = '<GetFeature xmlns="http://www.opengis.net/wfs/2.0"' +
|
|
|
+ ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
|
|
|
+ ' xmlns:ogc="http://www.opengis.net/ogc"' +
|
|
|
+ ' xmlns:wfs="http://www.opengis.net/wfs"' +
|
|
|
+ ' service="WFS"' +
|
|
|
+ ' version="2.0.2"' + '>'
|
|
|
+ if ('<GetFeature' === query['ogc:Filter'].substr(0, '<GetFeature'.length)) {
|
|
|
+ postData = query['ogc:Filter']
|
|
|
+ } else if ('<ogc:Filter>' === query['ogc:Filter'].substr(0, '<ogc:Filter>'.length)) {
|
|
|
+ postData = headerOgcFilter + '<wfs:Query>' + query['ogc:Filter'] + '</wfs:Query>' + '</GetFeature>'
|
|
|
+ } else if ('<wfs:Query>' === query['ogc:Filter'].substr(0, '<wfs:Query>'.length)) {
|
|
|
+ postData = headerOgcFilter + query['ogc:Filter'] + '</GetFeature>'
|
|
|
+ } else {
|
|
|
+ throw 'Error - wrong sytax ogc:Filter'
|
|
|
+ }
|
|
|
}
|
|
|
if ('sortBy' in query) link += '&sortBy=' + query['sortBy']
|
|
|
if ('maxFeatures' in query) link += '&maxFeatures=' + query['maxFeatures']
|
|
|
@@ -103,7 +117,17 @@ function p5WFS_GetFeature(typeName, query) { // @returns Promise
|
|
|
if (!xmlResponse.children.length) throw "Missing response xml root element"
|
|
|
return xmlResponse.children[0]
|
|
|
}).then(function (xmlRoot) {
|
|
|
- if ('FeatureCollection' !== xmlRoot.localName) throw "Missing FeatureCollection as root element in wfs response"
|
|
|
+ if ('html' === xmlRoot.localName) {
|
|
|
+ console.log(xmlRoot) // html / body / parseerror / div
|
|
|
+ throw "Parse xml error"
|
|
|
+ }
|
|
|
+ if ('FeatureCollection' !== xmlRoot.localName) {
|
|
|
+ if ('ServiceExceptionReport' === xmlRoot.tagName) {
|
|
|
+ if (xmlRoot.children[0] && xmlRoot.children[0].textContent) throw xmlRoot.children[0].textContent
|
|
|
+ throw "WFS API Exception"
|
|
|
+ }
|
|
|
+ throw "Missing FeatureCollection as root element in wfs response"
|
|
|
+ }
|
|
|
var features = []
|
|
|
for (var i = 0; i < xmlRoot.children.length; i++) {
|
|
|
features.push(p5WFS_ParseFeatureMember(xmlRoot.children[i]))
|