Add write support for gml:MultiLineString
This commit is contained in:
@@ -1269,6 +1269,30 @@ ol.format.GML.writeMultiPoint_ = function(node, geometry,
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Node} node Node.
|
||||||
|
* @param {ol.geom.MultiLineString} geometry MultiLineString geometry.
|
||||||
|
* @param {Array.<*>} objectStack Node stack.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.format.GML.writeMultiLineString_ = function(node, geometry,
|
||||||
|
objectStack) {
|
||||||
|
var context = objectStack[objectStack.length - 1];
|
||||||
|
goog.asserts.assert(goog.isObject(context));
|
||||||
|
var srsName = goog.object.get(context, 'srsName');
|
||||||
|
if (goog.isDefAndNotNull(srsName)) {
|
||||||
|
node.setAttribute('srsName', srsName);
|
||||||
|
}
|
||||||
|
var lines = geometry.getLineStrings();
|
||||||
|
for (var i = 0, ii = lines.length; i < ii; ++i) {
|
||||||
|
ol.xml.pushSerializeAndPop({node: node, srsName: srsName},
|
||||||
|
ol.format.GML.LINESTRINGMEMBER_SERIALIZERS_,
|
||||||
|
ol.xml.makeSimpleNodeFactory('lineStringMember'), [lines[i]],
|
||||||
|
objectStack);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Node} node Node.
|
* @param {Node} node Node.
|
||||||
* @param {ol.geom.LinearRing} ring LinearRing geometry.
|
* @param {ol.geom.LinearRing} ring LinearRing geometry.
|
||||||
@@ -1321,6 +1345,23 @@ ol.format.GML.writePointMember_ = function(node, point, objectStack) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Node} node Node.
|
||||||
|
* @param {ol.geom.LineString} line LineString geometry.
|
||||||
|
* @param {Array.<*>} objectStack Node stack.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.format.GML.writeLineStringMember_ = function(node, line, objectStack) {
|
||||||
|
var context = objectStack[objectStack.length - 1];
|
||||||
|
goog.asserts.assert(goog.isObject(context));
|
||||||
|
var srsName = goog.object.get(context, 'srsName');
|
||||||
|
ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */
|
||||||
|
({node: node, srsName: srsName, writeSrsName: false}),
|
||||||
|
ol.format.GML.GEOMETRY_SERIALIZERS_,
|
||||||
|
ol.format.GML.GEOMETRY_NODE_FACTORY_, [line], []);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Node} node Node.
|
* @param {Node} node Node.
|
||||||
* @param {ol.geom.Polygon} polygon Polygon geometry.
|
* @param {ol.geom.Polygon} polygon Polygon geometry.
|
||||||
@@ -1377,6 +1418,18 @@ ol.format.GML.POINTMEMBER_SERIALIZERS_ = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Object.<string, Object.<string, ol.xml.Serializer>>}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.format.GML.LINESTRINGMEMBER_SERIALIZERS_ = {
|
||||||
|
'http://www.opengis.net/gml': {
|
||||||
|
'lineStringMember': ol.xml.makeChildAppender(
|
||||||
|
ol.format.GML.writeLineStringMember_)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Object.<string, Object.<string, ol.xml.Serializer>>}
|
* @type {Object.<string, Object.<string, ol.xml.Serializer>>}
|
||||||
* @private
|
* @private
|
||||||
@@ -1444,6 +1497,8 @@ ol.format.GML.GEOMETRY_SERIALIZERS_ = {
|
|||||||
'Point': ol.xml.makeChildAppender(ol.format.GML.writePoint_),
|
'Point': ol.xml.makeChildAppender(ol.format.GML.writePoint_),
|
||||||
'MultiPoint': ol.xml.makeChildAppender(ol.format.GML.writeMultiPoint_),
|
'MultiPoint': ol.xml.makeChildAppender(ol.format.GML.writeMultiPoint_),
|
||||||
'LineString': ol.xml.makeChildAppender(ol.format.GML.writeLineString_),
|
'LineString': ol.xml.makeChildAppender(ol.format.GML.writeLineString_),
|
||||||
|
'MultiLineString': ol.xml.makeChildAppender(
|
||||||
|
ol.format.GML.writeMultiLineString_),
|
||||||
'LinearRing': ol.xml.makeChildAppender(ol.format.GML.writeLinearRing_),
|
'LinearRing': ol.xml.makeChildAppender(ol.format.GML.writeLinearRing_),
|
||||||
'Polygon': ol.xml.makeChildAppender(ol.format.GML.writePolygon_),
|
'Polygon': ol.xml.makeChildAppender(ol.format.GML.writePolygon_),
|
||||||
'Surface': ol.xml.makeChildAppender(ol.format.GML.writeSurface_),
|
'Surface': ol.xml.makeChildAppender(ol.format.GML.writeSurface_),
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ describe('ol.format.GML', function() {
|
|||||||
|
|
||||||
describe('multilinestring', function() {
|
describe('multilinestring', function() {
|
||||||
|
|
||||||
it('can read a singular multilinestring geometry', function() {
|
it('can read and write a singular multilinestring geometry', function() {
|
||||||
var text =
|
var text =
|
||||||
'<gml:MultiLineString xmlns:gml="http://www.opengis.net/gml" ' +
|
'<gml:MultiLineString xmlns:gml="http://www.opengis.net/gml" ' +
|
||||||
' srsName="CRS:84">' +
|
' srsName="CRS:84">' +
|
||||||
@@ -325,6 +325,8 @@ describe('ol.format.GML', function() {
|
|||||||
expect(g).to.be.an(ol.geom.MultiLineString);
|
expect(g).to.be.an(ol.geom.MultiLineString);
|
||||||
expect(g.getCoordinates()).to.eql(
|
expect(g.getCoordinates()).to.eql(
|
||||||
[[[1, 2, 0], [2, 3, 0]], [[3, 4, 0], [4, 5, 0]]]);
|
[[[1, 2, 0], [2, 3, 0]], [[3, 4, 0], [4, 5, 0]]]);
|
||||||
|
var serialized = format.writeGeometry(g);
|
||||||
|
expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can read a plural multilinestring geometry', function() {
|
it('can read a plural multilinestring geometry', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user