Add write support for gml:Curve

This commit is contained in:
Bart van den Eijnden
2014-02-27 20:55:50 +01:00
parent a6d6317d9e
commit c4c53a7ac3
3 changed files with 83 additions and 3 deletions

View File

@@ -312,6 +312,9 @@
* @property {boolean|undefined} surface Write gml:Surface instead of
* gml:Polygon elements. This also affects the elements in multi-part
* 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´.
*/
/**

View File

@@ -59,6 +59,13 @@ ol.format.GML = function(opt_options) {
this.surface_ = goog.isDef(options.surface) ?
options.surface : false;
/**
* @private
* @type {boolean}
*/
this.curve_ = goog.isDef(options.curve) ?
options.curve : false;
goog.base(this);
};
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];
goog.asserts.assert(goog.isObject(context));
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);
}
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 {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>>}
* @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>>}
* @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>>}
* @private
*/
ol.format.GML.GEOMETRY_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'Curve': ol.xml.makeChildAppender(ol.format.GML.writeCurve_),
'Point': ol.xml.makeChildAppender(ol.format.GML.writePoint_),
'LineString': ol.xml.makeChildAppender(ol.format.GML.writeLineString_),
'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];
goog.asserts.assert(goog.isObject(context));
var surface = goog.object.get(context, 'surface');
var curve = goog.object.get(context, 'curve');
goog.asserts.assertInstanceof(value, ol.geom.Geometry);
var parentNode = objectStack[objectStack.length - 1].node;
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) {
nodeName = 'Surface';
}
if (nodeName === 'LineString' && curve === true) {
nodeName = 'Curve';
}
return ol.xml.createElementNS(parentNode.namespaceURI,
nodeName);
};
@@ -1362,7 +1435,8 @@ ol.format.GML.GEOMETRY_NODE_FACTORY_ = function(value, objectStack,
*/
ol.format.GML.prototype.writeGeometryNode = function(geometry) {
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} */
(context), ol.format.GML.GEOMETRY_SERIALIZERS_,
ol.format.GML.GEOMETRY_NODE_FACTORY_, [geometry], []);