Add parser for gml:Envelope
This commit is contained in:
@@ -5,6 +5,7 @@ goog.require('goog.asserts');
|
|||||||
goog.require('goog.dom');
|
goog.require('goog.dom');
|
||||||
goog.require('goog.dom.NodeType');
|
goog.require('goog.dom.NodeType');
|
||||||
goog.require('goog.dom.TagName');
|
goog.require('goog.dom.TagName');
|
||||||
|
goog.require('ol.extent');
|
||||||
goog.require('ol.format.XML');
|
goog.require('ol.format.XML');
|
||||||
goog.require('ol.geom.GeometryCollection');
|
goog.require('ol.geom.GeometryCollection');
|
||||||
goog.require('ol.geom.LineString');
|
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.<number>} */ ([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 {Node} node Node.
|
||||||
* @param {Array.<*>} objectStack Object stack.
|
* @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_),
|
'LinearRing' : ol.xml.makeArrayPusher(ol.format.GML.readLinearRing_),
|
||||||
'Polygon': ol.xml.makeArrayPusher(ol.format.GML.readPolygon_),
|
'Polygon': ol.xml.makeArrayPusher(ol.format.GML.readPolygon_),
|
||||||
'Surface': ol.xml.makeArrayPusher(ol.format.GML.readSurface_),
|
'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.<string, Object.<string, ol.xml.Parser>>}
|
||||||
|
* @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
|
* @const
|
||||||
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||||
|
|||||||
@@ -123,6 +123,21 @@ describe('ol.format.GML', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('envelope', function() {
|
||||||
|
|
||||||
|
it('can read an envelope geometry', function() {
|
||||||
|
var text =
|
||||||
|
'<gml:Envelope xmlns:gml="http://www.opengis.net/gml" ' +
|
||||||
|
' srsName="foo">' +
|
||||||
|
' <gml:lowerCorner>1 2</gml:lowerCorner>' +
|
||||||
|
' <gml:upperCorner>3 4</gml:upperCorner>' +
|
||||||
|
'</gml:Envelope>';
|
||||||
|
var g = format.readGeometry(text);
|
||||||
|
expect(g).to.eql([1, 2, 3, 4]);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user