From 877d5a445e5f906788410a4731260a63e2ec0943 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Thu, 20 Feb 2014 13:54:45 +0100 Subject: [PATCH] Add parser for gml:Envelope --- src/ol/format/gmlformat.js | 34 ++++++++++++++++++++++++++- test/spec/ol/format/gmlformat.test.js | 15 ++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/ol/format/gmlformat.js b/src/ol/format/gmlformat.js index 0dd50c8226..5810158b11 100644 --- a/src/ol/format/gmlformat.js +++ b/src/ol/format/gmlformat.js @@ -5,6 +5,7 @@ goog.require('goog.asserts'); goog.require('goog.dom'); goog.require('goog.dom.NodeType'); goog.require('goog.dom.TagName'); +goog.require('ol.extent'); goog.require('ol.format.XML'); goog.require('ol.geom.GeometryCollection'); goog.require('ol.geom.LineString'); @@ -354,6 +355,24 @@ ol.format.GML.readCurve_ = function(node, objectStack) { }; +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + * @return {ol.Extent|undefined} Envelope. + */ +ol.format.GML.readEnvelope_ = function(node, objectStack) { + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + goog.asserts.assert(node.localName == 'Envelope'); + var flatCoordinates = ol.xml.pushParseAndPop( + /** @type {Array.} */ ([null]), + ol.format.GML.ENVELOPE_PARSERS_, node, objectStack); + return ol.extent.createOrUpdate(flatCoordinates[1][0], + flatCoordinates[1][1], flatCoordinates[2][0], + flatCoordinates[2][1]); +}; + + /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. @@ -423,7 +442,8 @@ ol.format.GML.GEOMETRY_PARSERS_ = ol.xml.makeParsersNS( 'LinearRing' : ol.xml.makeArrayPusher(ol.format.GML.readLinearRing_), 'Polygon': ol.xml.makeArrayPusher(ol.format.GML.readPolygon_), 'Surface': ol.xml.makeArrayPusher(ol.format.GML.readSurface_), - 'Curve': ol.xml.makeArrayPusher(ol.format.GML.readCurve_) + 'Curve': ol.xml.makeArrayPusher(ol.format.GML.readCurve_), + 'Envelope': ol.xml.makeArrayPusher(ol.format.GML.readEnvelope_) }); @@ -473,6 +493,18 @@ ol.format.GML.CURVE_PARSERS_ = ol.xml.makeParsersNS( }); +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML.ENVELOPE_PARSERS_ = ol.xml.makeParsersNS( + ol.format.GML.NAMESPACE_URIS_, { + 'lowerCorner': ol.xml.makeArrayPusher(ol.format.GML.readFlatPosList_), + 'upperCorner': ol.xml.makeArrayPusher(ol.format.GML.readFlatPosList_) + }); + + /** * @const * @type {Object.>} diff --git a/test/spec/ol/format/gmlformat.test.js b/test/spec/ol/format/gmlformat.test.js index 7f7a5ce622..d2d7310b02 100644 --- a/test/spec/ol/format/gmlformat.test.js +++ b/test/spec/ol/format/gmlformat.test.js @@ -123,6 +123,21 @@ describe('ol.format.GML', function() { }); + describe('envelope', function() { + + it('can read an envelope geometry', function() { + var text = + '' + + ' 1 2' + + ' 3 4' + + ''; + var g = format.readGeometry(text); + expect(g).to.eql([1, 2, 3, 4]); + }); + + }); + }); });