Add parsing for gml:Curve

This commit is contained in:
Bart van den Eijnden
2014-02-20 13:09:10 +01:00
parent e845d6558c
commit 85fe1bf737
2 changed files with 106 additions and 1 deletions

View File

@@ -132,6 +132,26 @@ ol.format.GML.patchesParser_ = function(node, objectStack) {
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
* @return {Array.<number>} flat coordinates.
*/
ol.format.GML.segmentsParser_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'segments');
var result = ol.xml.pushParseAndPop(
/** @type {Array.<number>} */ ([null]),
ol.format.GML.SEGMENTS_PARSERS_, node, objectStack);
if (!goog.isDef(result)) {
return null;
} else {
return result;
}
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
@@ -152,6 +172,26 @@ ol.format.GML.polygonPatchParser_ = function(node, objectStack) {
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
* @return {Array.<number>} flat coordinates.
*/
ol.format.GML.lineStringSegmentParser_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'LineStringSegment');
var result = ol.xml.pushParseAndPop(
/** @type {Array.<number>} */ ([null]),
ol.format.GML.GEOMETRY_FLAT_COORDINATES_PARSERS_, node, objectStack);
if (!goog.isDef(result)) {
return null;
} else {
return result;
}
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
@@ -292,6 +332,28 @@ ol.format.GML.readSurface_ = function(node, objectStack) {
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
* @return {ol.geom.LineString|undefined} LineString.
*/
ol.format.GML.readCurve_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'Curve');
var flatCoordinates = ol.xml.pushParseAndPop(
/** @type {Array.<number>} */ ([null]),
ol.format.GML.CURVE_PARSERS_, node, objectStack);
if (goog.isDefAndNotNull(flatCoordinates)) {
var lineString = new ol.geom.LineString(null);
lineString.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates);
return lineString;
} else {
return undefined;
}
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
@@ -360,7 +422,8 @@ ol.format.GML.GEOMETRY_PARSERS_ = ol.xml.makeParsersNS(
'LineString': ol.xml.makeArrayPusher(ol.format.GML.readLineString_),
'LinearRing' : ol.xml.makeArrayPusher(ol.format.GML.readLinearRing_),
'Polygon': ol.xml.makeArrayPusher(ol.format.GML.readPolygon_),
'Surface': ol.xml.makeArrayPusher(ol.format.GML.readSurface_)
'Surface': ol.xml.makeArrayPusher(ol.format.GML.readSurface_),
'Curve': ol.xml.makeArrayPusher(ol.format.GML.readCurve_)
});
@@ -399,6 +462,17 @@ ol.format.GML.SURFACE_PARSERS_ = ol.xml.makeParsersNS(
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @private
*/
ol.format.GML.CURVE_PARSERS_ = ol.xml.makeParsersNS(
ol.format.GML.NAMESPACE_URIS_, {
'segments': ol.xml.makeReplacer(ol.format.GML.segmentsParser_)
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
@@ -410,6 +484,18 @@ ol.format.GML.PATCHES_PARSERS_ = ol.xml.makeParsersNS(
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @private
*/
ol.format.GML.SEGMENTS_PARSERS_ = ol.xml.makeParsersNS(
ol.format.GML.NAMESPACE_URIS_, {
'LineStringSegment': ol.xml.makeReplacer(
ol.format.GML.lineStringSegmentParser_)
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}

View File

@@ -104,6 +104,25 @@ describe('ol.format.GML', function() {
});
describe('curve', function() {
it('can read a curve geometry', function() {
var text =
'<gml:Curve xmlns:gml="http://www.opengis.net/gml" ' +
' srsName="foo">' +
' <gml:segments>' +
' <gml:LineStringSegment>' +
' <gml:posList>1 2 3 4</gml:posList>' +
' </gml:LineStringSegment>' +
' </gml:segments>' +
'</gml:Curve>';
var g = format.readGeometry(text);
expect(g).to.be.an(ol.geom.LineString);
expect(g.getCoordinates()).to.eql([[1, 2, 0], [3, 4, 0]]);
});
});
});
});