Add support for gml:MultiLineString
This commit is contained in:
@@ -9,6 +9,7 @@ goog.require('ol.extent');
|
||||
goog.require('ol.format.XML');
|
||||
goog.require('ol.geom.GeometryCollection');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
goog.require('ol.geom.MultiPoint');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
@@ -97,7 +98,7 @@ ol.format.GML.readPoint_ = function(node, objectStack) {
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
* @return {ol.geom.MultiPoint|undefined} Point.
|
||||
* @return {ol.geom.MultiPoint|undefined} MultiPoint.
|
||||
*/
|
||||
ol.format.GML.readMultiPoint_ = function(node, objectStack) {
|
||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||
@@ -113,6 +114,28 @@ ol.format.GML.readMultiPoint_ = function(node, objectStack) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
* @return {ol.geom.MultiLineString|undefined} MultiLineString.
|
||||
*/
|
||||
ol.format.GML.readMultiLineString_ = function(node, objectStack) {
|
||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||
goog.asserts.assert(node.localName == 'MultiLineString');
|
||||
var lineStrings = ol.xml.pushParseAndPop(
|
||||
/** @type {Array.<ol.geom.LineString>} */ ([]),
|
||||
ol.format.GML.MULTILINESTRING_PARSERS_, node, objectStack);
|
||||
if (goog.isDefAndNotNull(lineStrings)) {
|
||||
var multiLineString = new ol.geom.MultiLineString(null);
|
||||
multiLineString.setLineStrings(lineStrings);
|
||||
return multiLineString;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
@@ -120,11 +143,25 @@ ol.format.GML.readMultiPoint_ = function(node, objectStack) {
|
||||
*/
|
||||
ol.format.GML.pointMemberParser_ = function(node, objectStack) {
|
||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||
goog.asserts.assert(node.localName == 'pointMember');
|
||||
goog.asserts.assert(node.localName == 'pointMember' ||
|
||||
node.localName == 'pointMembers');
|
||||
ol.xml.parse(ol.format.GML.POINTMEMBER_PARSERS_, node, objectStack);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
*/
|
||||
ol.format.GML.lineStringMemberParser_ = function(node, objectStack) {
|
||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||
goog.asserts.assert(node.localName == 'lineStringMember' ||
|
||||
node.localName == 'lineStringMembers');
|
||||
ol.xml.parse(ol.format.GML.LINESTRINGMEMBER_PARSERS_, node, objectStack);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
@@ -478,6 +515,8 @@ ol.format.GML.GEOMETRY_PARSERS_ = ol.xml.makeParsersNS(
|
||||
'Point': ol.xml.makeArrayPusher(ol.format.GML.readPoint_),
|
||||
'MultiPoint': ol.xml.makeArrayPusher(ol.format.GML.readMultiPoint_),
|
||||
'LineString': ol.xml.makeArrayPusher(ol.format.GML.readLineString_),
|
||||
'MultiLineString': ol.xml.makeArrayPusher(
|
||||
ol.format.GML.readMultiLineString_),
|
||||
'LinearRing' : ol.xml.makeArrayPusher(ol.format.GML.readLinearRing_),
|
||||
'Polygon': ol.xml.makeArrayPusher(ol.format.GML.readPolygon_),
|
||||
'Surface': ol.xml.makeArrayPusher(ol.format.GML.readSurface_),
|
||||
@@ -517,7 +556,22 @@ ol.format.GML.FLAT_LINEAR_RINGS_PARSERS_ = ol.xml.makeParsersNS(
|
||||
*/
|
||||
ol.format.GML.MULTIPOINT_PARSERS_ = ol.xml.makeParsersNS(
|
||||
ol.format.GML.NAMESPACE_URIS_, {
|
||||
'pointMember': ol.xml.makeArrayPusher(ol.format.GML.pointMemberParser_)
|
||||
'pointMember': ol.xml.makeArrayPusher(ol.format.GML.pointMemberParser_),
|
||||
'pointMembers': ol.xml.makeArrayPusher(ol.format.GML.pointMemberParser_)
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||
* @private
|
||||
*/
|
||||
ol.format.GML.MULTILINESTRING_PARSERS_ = ol.xml.makeParsersNS(
|
||||
ol.format.GML.NAMESPACE_URIS_, {
|
||||
'lineStringMember': ol.xml.makeArrayPusher(
|
||||
ol.format.GML.lineStringMemberParser_),
|
||||
'lineStringMembers': ol.xml.makeArrayPusher(
|
||||
ol.format.GML.lineStringMemberParser_)
|
||||
});
|
||||
|
||||
|
||||
@@ -533,6 +587,18 @@ ol.format.GML.POINTMEMBER_PARSERS_ = ol.xml.makeParsersNS(
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||
* @private
|
||||
*/
|
||||
ol.format.GML.LINESTRINGMEMBER_PARSERS_ = ol.xml.makeParsersNS(
|
||||
ol.format.GML.NAMESPACE_URIS_, {
|
||||
'LineString': ol.xml.makeArrayPusher(
|
||||
ol.format.GML.readLineString_)
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||
|
||||
@@ -180,6 +180,71 @@ describe('ol.format.GML', function() {
|
||||
expect(g.getCoordinates()).to.eql([[1, 2, 0], [2, 3, 0], [3, 4, 0]]);
|
||||
});
|
||||
|
||||
it('can read a plural multipoint geometry', function() {
|
||||
var text =
|
||||
'<gml:MultiPoint xmlns:gml="http://www.opengis.net/gml" ' +
|
||||
' srsName="foo">' +
|
||||
' <gml:pointMembers>' +
|
||||
' <gml:Point>' +
|
||||
' <gml:pos>1 2</gml:pos>' +
|
||||
' </gml:Point>' +
|
||||
' <gml:Point>' +
|
||||
' <gml:pos>2 3</gml:pos>' +
|
||||
' </gml:Point>' +
|
||||
' <gml:Point>' +
|
||||
' <gml:pos>3 4</gml:pos>' +
|
||||
' </gml:Point>' +
|
||||
' </gml:pointMembers>' +
|
||||
'</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]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('multilinestring', function() {
|
||||
|
||||
it('can read a singular multilinestring geometry', function() {
|
||||
var text =
|
||||
'<gml:MultiLineString xmlns:gml="http://www.opengis.net/gml" ' +
|
||||
' srsName="foo">' +
|
||||
' <gml:lineStringMember>' +
|
||||
' <gml:LineString>' +
|
||||
' <gml:posList>1 2 2 3</gml:posList>' +
|
||||
' </gml:LineString>' +
|
||||
' </gml:lineStringMember>' +
|
||||
' <gml:lineStringMember>' +
|
||||
' <gml:LineString>' +
|
||||
' <gml:posList>3 4 4 5</gml:posList>' +
|
||||
' </gml:LineString>' +
|
||||
' </gml:lineStringMember>' +
|
||||
'</gml:MultiLineString>';
|
||||
var g = format.readGeometry(text);
|
||||
expect(g).to.be.an(ol.geom.MultiLineString);
|
||||
expect(g.getCoordinates()).to.eql(
|
||||
[[[1, 2, 0], [2, 3, 0]], [[3, 4, 0], [4, 5, 0]]]);
|
||||
});
|
||||
|
||||
it('can read a plural multilinestring geometry', function() {
|
||||
var text =
|
||||
'<gml:MultiLineString xmlns:gml="http://www.opengis.net/gml" ' +
|
||||
' srsName="foo">' +
|
||||
' <gml:lineStringMembers>' +
|
||||
' <gml:LineString>' +
|
||||
' <gml:posList>1 2 2 3</gml:posList>' +
|
||||
' </gml:LineString>' +
|
||||
' <gml:LineString>' +
|
||||
' <gml:posList>3 4 4 5</gml:posList>' +
|
||||
' </gml:LineString>' +
|
||||
' </gml:lineStringMembers>' +
|
||||
'</gml:MultiLineString>';
|
||||
var g = format.readGeometry(text);
|
||||
expect(g).to.be.an(ol.geom.MultiLineString);
|
||||
expect(g.getCoordinates()).to.eql(
|
||||
[[[1, 2, 0], [2, 3, 0]], [[3, 4, 0], [4, 5, 0]]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
@@ -190,5 +255,6 @@ describe('ol.format.GML', function() {
|
||||
goog.require('ol.format.GML');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.MultiPoint');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
|
||||
Reference in New Issue
Block a user