Separate geometry and extent parsing

This commit is contained in:
Andreas Hocevar
2022-03-18 19:37:01 +01:00
parent 0ee9c8f4ab
commit e0b62016d2
2 changed files with 37 additions and 17 deletions

View File

@@ -238,34 +238,51 @@ class GMLBase extends XMLFeature {
* @param {Array<*>} objectStack Object stack.
* @return {import("../geom/Geometry.js").default|import("../extent.js").Extent|undefined} Geometry.
*/
readGeometryElement(node, objectStack) {
readGeometryOrExtent(node, objectStack) {
const context = /** @type {Object} */ (objectStack[0]);
context['srsName'] = node.firstElementChild.getAttribute('srsName');
context['srsDimension'] =
node.firstElementChild.getAttribute('srsDimension');
const geometry = pushParseAndPop(
return pushParseAndPop(
null,
this.GEOMETRY_PARSERS,
node,
objectStack,
this
);
if (geometry) {
if (Array.isArray(geometry)) {
return transformExtentWithOptions(
/** @type {import("../extent.js").Extent} */ (geometry),
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
* @return {import("../geom/Geometry.js").default|import("../extent.js").Extent|undefined} Geometry.
*/
readExtentElement(node, objectStack) {
const context = /** @type {Object} */ (objectStack[0]);
const extent = this.readGeometryOrExtent(node, objectStack);
return extent
? transformExtentWithOptions(
/** @type {import("../extent.js").Extent} */ (extent),
context
);
} else {
return transformGeometryWithOptions(
)
: undefined;
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
* @return {import("../geom/Geometry.js").default|import("../extent.js").Extent|undefined} Geometry.
*/
readGeometryElement(node, objectStack) {
const context = /** @type {Object} */ (objectStack[0]);
const geometry = this.readGeometryOrExtent(node, objectStack);
return geometry
? transformGeometryWithOptions(
/** @type {import("../geom/Geometry.js").default} */ (geometry),
false,
context
);
}
} else {
return undefined;
}
)
: undefined;
}
/**
@@ -292,8 +309,11 @@ class GMLBase extends XMLFeature {
}
} else {
if (asFeature) {
//if feature, try it as a geometry
value = this.readGeometryElement(n, objectStack);
//if feature, try it as a geometry or extent
value =
localName === 'boundedBy'
? this.readExtentElement(n, objectStack)
: this.readGeometryElement(n, objectStack);
}
if (!value) {
//if not a geometry or not a feature, treat it as a complex attribute

View File

@@ -36,7 +36,7 @@ import {
const FEATURE_COLLECTION_PARSERS = {
'http://www.opengis.net/gml': {
'boundedBy': makeObjectPropertySetter(
GMLBase.prototype.readGeometryElement,
GMLBase.prototype.readExtentElement,
'bounds'
),
},