Add write support for gml:Curve
This commit is contained in:
@@ -312,6 +312,9 @@
|
|||||||
* @property {boolean|undefined} surface Write gml:Surface instead of
|
* @property {boolean|undefined} surface Write gml:Surface instead of
|
||||||
* gml:Polygon elements. This also affects the elements in multi-part
|
* gml:Polygon elements. This also affects the elements in multi-part
|
||||||
* geometries. Default is `false´.
|
* geometries. Default is `false´.
|
||||||
|
* @property {boolean|undefined} curve Write gml:Curve instead of
|
||||||
|
* gml:LineString elements. This also affects the elements in multi-part
|
||||||
|
* geometries. Default is `false´.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,6 +59,13 @@ ol.format.GML = function(opt_options) {
|
|||||||
this.surface_ = goog.isDef(options.surface) ?
|
this.surface_ = goog.isDef(options.surface) ?
|
||||||
options.surface : false;
|
options.surface : false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.curve_ = goog.isDef(options.curve) ?
|
||||||
|
options.curve : false;
|
||||||
|
|
||||||
goog.base(this);
|
goog.base(this);
|
||||||
};
|
};
|
||||||
goog.inherits(ol.format.GML, ol.format.XMLFeature);
|
goog.inherits(ol.format.GML, ol.format.XMLFeature);
|
||||||
@@ -1114,7 +1121,8 @@ ol.format.GML.writeLineString_ = function(node, geometry, objectStack) {
|
|||||||
var context = objectStack[objectStack.length - 1];
|
var context = objectStack[objectStack.length - 1];
|
||||||
goog.asserts.assert(goog.isObject(context));
|
goog.asserts.assert(goog.isObject(context));
|
||||||
var srsName = goog.object.get(context, 'srsName');
|
var srsName = goog.object.get(context, 'srsName');
|
||||||
if (goog.isDefAndNotNull(srsName)) {
|
var writeSrsName = goog.object.get(context, 'writeSrsName');
|
||||||
|
if (goog.isDefAndNotNull(srsName) && writeSrsName !== false) {
|
||||||
node.setAttribute('srsName', srsName);
|
node.setAttribute('srsName', srsName);
|
||||||
}
|
}
|
||||||
ol.xml.pushSerializeAndPop({node: node, srsName: srsName},
|
ol.xml.pushSerializeAndPop({node: node, srsName: srsName},
|
||||||
@@ -1192,6 +1200,26 @@ ol.format.GML.writeSurface_ = function(node, geometry, objectStack) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Node} node Node.
|
||||||
|
* @param {ol.geom.LineString} geometry LineString geometry.
|
||||||
|
* @param {Array.<*>} objectStack Node stack.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.format.GML.writeCurve_ = 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);
|
||||||
|
}
|
||||||
|
ol.xml.pushSerializeAndPop({node: node, srsName: srsName},
|
||||||
|
ol.format.GML.SEGMENT_SERIALIZERS_,
|
||||||
|
ol.xml.makeSimpleNodeFactory('segments'), [geometry],
|
||||||
|
objectStack);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Node} node Node.
|
* @param {Node} node Node.
|
||||||
* @param {ol.geom.MultiPolygon} geometry MultiPolygon geometry.
|
* @param {ol.geom.MultiPolygon} geometry MultiPolygon geometry.
|
||||||
@@ -1268,6 +1296,23 @@ ol.format.GML.writeSurfacePatches_ = function(node, polygon, objectStack) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Node} node Node.
|
||||||
|
* @param {ol.geom.LineString} line LineString geometry.
|
||||||
|
* @param {Array.<*>} objectStack Node stack.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.format.GML.writeCurveSegments_ = 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.CURVE_SERIALIZERS_,
|
||||||
|
ol.xml.makeSimpleNodeFactory('LineStringSegment'), [line], []);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Object.<string, Object.<string, ol.xml.Serializer>>}
|
* @type {Object.<string, Object.<string, ol.xml.Serializer>>}
|
||||||
* @private
|
* @private
|
||||||
@@ -1290,6 +1335,17 @@ ol.format.GML.PATCH_SERIALIZERS_ = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Object.<string, Object.<string, ol.xml.Serializer>>}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.format.GML.SEGMENT_SERIALIZERS_ = {
|
||||||
|
'http://www.opengis.net/gml': {
|
||||||
|
'segments': ol.xml.makeChildAppender(ol.format.GML.writeCurveSegments_)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Object.<string, Object.<string, ol.xml.Serializer>>}
|
* @type {Object.<string, Object.<string, ol.xml.Serializer>>}
|
||||||
* @private
|
* @private
|
||||||
@@ -1313,12 +1369,25 @@ ol.format.GML.SURFACE_SERIALIZERS_ = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Object.<string, Object.<string, ol.xml.Serializer>>}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.format.GML.CURVE_SERIALIZERS_ = {
|
||||||
|
'http://www.opengis.net/gml': {
|
||||||
|
'LineStringSegment': ol.xml.makeChildAppender(
|
||||||
|
ol.format.GML.writeLineString_)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Object.<string, Object.<string, ol.xml.Serializer>>}
|
* @type {Object.<string, Object.<string, ol.xml.Serializer>>}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.format.GML.GEOMETRY_SERIALIZERS_ = {
|
ol.format.GML.GEOMETRY_SERIALIZERS_ = {
|
||||||
'http://www.opengis.net/gml': {
|
'http://www.opengis.net/gml': {
|
||||||
|
'Curve': ol.xml.makeChildAppender(ol.format.GML.writeCurve_),
|
||||||
'Point': ol.xml.makeChildAppender(ol.format.GML.writePoint_),
|
'Point': ol.xml.makeChildAppender(ol.format.GML.writePoint_),
|
||||||
'LineString': ol.xml.makeChildAppender(ol.format.GML.writeLineString_),
|
'LineString': ol.xml.makeChildAppender(ol.format.GML.writeLineString_),
|
||||||
'LinearRing': ol.xml.makeChildAppender(ol.format.GML.writeLinearRing_),
|
'LinearRing': ol.xml.makeChildAppender(ol.format.GML.writeLinearRing_),
|
||||||
@@ -1342,6 +1411,7 @@ ol.format.GML.GEOMETRY_NODE_FACTORY_ = function(value, objectStack,
|
|||||||
var context = objectStack[objectStack.length - 1];
|
var context = objectStack[objectStack.length - 1];
|
||||||
goog.asserts.assert(goog.isObject(context));
|
goog.asserts.assert(goog.isObject(context));
|
||||||
var surface = goog.object.get(context, 'surface');
|
var surface = goog.object.get(context, 'surface');
|
||||||
|
var curve = goog.object.get(context, 'curve');
|
||||||
goog.asserts.assertInstanceof(value, ol.geom.Geometry);
|
goog.asserts.assertInstanceof(value, ol.geom.Geometry);
|
||||||
var parentNode = objectStack[objectStack.length - 1].node;
|
var parentNode = objectStack[objectStack.length - 1].node;
|
||||||
goog.asserts.assert(ol.xml.isNode(parentNode));
|
goog.asserts.assert(ol.xml.isNode(parentNode));
|
||||||
@@ -1352,6 +1422,9 @@ ol.format.GML.GEOMETRY_NODE_FACTORY_ = function(value, objectStack,
|
|||||||
if (nodeName === 'Polygon' && surface === true) {
|
if (nodeName === 'Polygon' && surface === true) {
|
||||||
nodeName = 'Surface';
|
nodeName = 'Surface';
|
||||||
}
|
}
|
||||||
|
if (nodeName === 'LineString' && curve === true) {
|
||||||
|
nodeName = 'Curve';
|
||||||
|
}
|
||||||
return ol.xml.createElementNS(parentNode.namespaceURI,
|
return ol.xml.createElementNS(parentNode.namespaceURI,
|
||||||
nodeName);
|
nodeName);
|
||||||
};
|
};
|
||||||
@@ -1362,7 +1435,8 @@ ol.format.GML.GEOMETRY_NODE_FACTORY_ = function(value, objectStack,
|
|||||||
*/
|
*/
|
||||||
ol.format.GML.prototype.writeGeometryNode = function(geometry) {
|
ol.format.GML.prototype.writeGeometryNode = function(geometry) {
|
||||||
var geom = ol.xml.createElementNS('http://www.opengis.net/gml', 'geom');
|
var geom = ol.xml.createElementNS('http://www.opengis.net/gml', 'geom');
|
||||||
var context = {node: geom, srsName: this.srsName_, surface: this.surface_};
|
var context = {node: geom, srsName: this.srsName_,
|
||||||
|
curve: this.curve_, surface: this.surface_};
|
||||||
ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */
|
ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */
|
||||||
(context), ol.format.GML.GEOMETRY_SERIALIZERS_,
|
(context), ol.format.GML.GEOMETRY_SERIALIZERS_,
|
||||||
ol.format.GML.GEOMETRY_NODE_FACTORY_, [geometry], []);
|
ol.format.GML.GEOMETRY_NODE_FACTORY_, [geometry], []);
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ describe('ol.format.GML', function() {
|
|||||||
|
|
||||||
describe('curve', function() {
|
describe('curve', function() {
|
||||||
|
|
||||||
it('can read a curve geometry', function() {
|
it('can read and write a curve geometry', function() {
|
||||||
var text =
|
var text =
|
||||||
'<gml:Curve xmlns:gml="http://www.opengis.net/gml" ' +
|
'<gml:Curve xmlns:gml="http://www.opengis.net/gml" ' +
|
||||||
' srsName="CRS:84">' +
|
' srsName="CRS:84">' +
|
||||||
@@ -230,6 +230,9 @@ describe('ol.format.GML', function() {
|
|||||||
var g = readGeometry(format, text);
|
var g = readGeometry(format, text);
|
||||||
expect(g).to.be.an(ol.geom.LineString);
|
expect(g).to.be.an(ol.geom.LineString);
|
||||||
expect(g.getCoordinates()).to.eql([[1, 2, 0], [3, 4, 0]]);
|
expect(g.getCoordinates()).to.eql([[1, 2, 0], [3, 4, 0]]);
|
||||||
|
format = new ol.format.GML({srsName: 'CRS:84', curve: true});
|
||||||
|
var serialized = format.writeGeometry(g);
|
||||||
|
expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text));
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user