Add gml:MultiPoint parsing
This commit is contained in:
@@ -9,6 +9,7 @@ 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');
|
||||||
|
goog.require('ol.geom.MultiPoint');
|
||||||
goog.require('ol.geom.Point');
|
goog.require('ol.geom.Point');
|
||||||
goog.require('ol.geom.Polygon');
|
goog.require('ol.geom.Polygon');
|
||||||
goog.require('ol.xml');
|
goog.require('ol.xml');
|
||||||
@@ -92,6 +93,38 @@ ol.format.GML.readPoint_ = function(node, objectStack) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Node} node Node.
|
||||||
|
* @param {Array.<*>} objectStack Object stack.
|
||||||
|
* @private
|
||||||
|
* @return {ol.geom.MultiPoint|undefined} Point.
|
||||||
|
*/
|
||||||
|
ol.format.GML.readMultiPoint_ = function(node, objectStack) {
|
||||||
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
|
goog.asserts.assert(node.localName == 'MultiPoint');
|
||||||
|
var coordinates = ol.xml.pushParseAndPop(
|
||||||
|
/** @type {Array.<Array.<number>>} */ ([]),
|
||||||
|
ol.format.GML.MULTIPOINT_PARSERS_, node, objectStack);
|
||||||
|
if (goog.isDefAndNotNull(coordinates)) {
|
||||||
|
return new ol.geom.MultiPoint(coordinates);
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Node} node Node.
|
||||||
|
* @param {Array.<*>} objectStack Object stack.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.format.GML.pointMemberParser_ = function(node, objectStack) {
|
||||||
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
|
goog.asserts.assert(node.localName == 'pointMember');
|
||||||
|
ol.xml.parse(ol.format.GML.POINTMEMBER_PARSERS_, node, objectStack);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Node} node Node.
|
* @param {Node} node Node.
|
||||||
* @param {Array.<*>} objectStack Object stack.
|
* @param {Array.<*>} objectStack Object stack.
|
||||||
@@ -443,6 +476,7 @@ ol.format.GML.readFlatPosList_ = function(node, objectStack) {
|
|||||||
ol.format.GML.GEOMETRY_PARSERS_ = ol.xml.makeParsersNS(
|
ol.format.GML.GEOMETRY_PARSERS_ = ol.xml.makeParsersNS(
|
||||||
ol.format.GML.NAMESPACE_URIS_, {
|
ol.format.GML.NAMESPACE_URIS_, {
|
||||||
'Point': ol.xml.makeArrayPusher(ol.format.GML.readPoint_),
|
'Point': ol.xml.makeArrayPusher(ol.format.GML.readPoint_),
|
||||||
|
'MultiPoint': ol.xml.makeArrayPusher(ol.format.GML.readMultiPoint_),
|
||||||
'LineString': ol.xml.makeArrayPusher(ol.format.GML.readLineString_),
|
'LineString': ol.xml.makeArrayPusher(ol.format.GML.readLineString_),
|
||||||
'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_),
|
||||||
@@ -476,6 +510,29 @@ ol.format.GML.FLAT_LINEAR_RINGS_PARSERS_ = ol.xml.makeParsersNS(
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.format.GML.MULTIPOINT_PARSERS_ = ol.xml.makeParsersNS(
|
||||||
|
ol.format.GML.NAMESPACE_URIS_, {
|
||||||
|
'pointMember': ol.xml.makeArrayPusher(ol.format.GML.pointMemberParser_)
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.format.GML.POINTMEMBER_PARSERS_ = ol.xml.makeParsersNS(
|
||||||
|
ol.format.GML.NAMESPACE_URIS_, {
|
||||||
|
'Point': ol.xml.makeArrayPusher(
|
||||||
|
ol.format.GML.readFlatCoordinatesFromNode_)
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @const
|
* @const
|
||||||
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||||
|
|||||||
@@ -153,6 +153,35 @@ describe('ol.format.GML', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('multipoint', function() {
|
||||||
|
|
||||||
|
it('can read a singular multipoint geometry', function() {
|
||||||
|
var text =
|
||||||
|
'<gml:MultiPoint xmlns:gml="http://www.opengis.net/gml" ' +
|
||||||
|
' srsName="foo">' +
|
||||||
|
' <gml:pointMember>' +
|
||||||
|
' <gml:Point>' +
|
||||||
|
' <gml:pos>1 2</gml:pos>' +
|
||||||
|
' </gml:Point>' +
|
||||||
|
' </gml:pointMember>' +
|
||||||
|
' <gml:pointMember>' +
|
||||||
|
' <gml:Point>' +
|
||||||
|
' <gml:pos>2 3</gml:pos>' +
|
||||||
|
' </gml:Point>' +
|
||||||
|
' </gml:pointMember>' +
|
||||||
|
' <gml:pointMember>' +
|
||||||
|
' <gml:Point>' +
|
||||||
|
' <gml:pos>3 4</gml:pos>' +
|
||||||
|
' </gml:Point>' +
|
||||||
|
' </gml:pointMember>' +
|
||||||
|
'</gml:MultiPoint>';
|
||||||
|
var g = format.readGeometry(text);
|
||||||
|
expect(g).to.be.an(ol.geom.MultiPoint);
|
||||||
|
expect(g.getCoordinates()).to.eql([[1, 2, 0], [2, 3, 0], [3, 4, 0]]);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -160,5 +189,6 @@ describe('ol.format.GML', function() {
|
|||||||
|
|
||||||
goog.require('ol.format.GML');
|
goog.require('ol.format.GML');
|
||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
|
goog.require('ol.geom.MultiPoint');
|
||||||
goog.require('ol.geom.Point');
|
goog.require('ol.geom.Point');
|
||||||
goog.require('ol.geom.Polygon');
|
goog.require('ol.geom.Polygon');
|
||||||
|
|||||||
Reference in New Issue
Block a user