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