Parse KML extrude and altitudeMode of simple geometries
Point, LineString and Polygon are handled. LinearRing properties are not handled. An 'extrude' boolean property is set in the geometry properties. An 'altitudeMode' string property is set in the geometry properties.
This commit is contained in:
@@ -802,11 +802,15 @@ ol.format.KML.readLineString_ = function(node, objectStack) {
|
||||
'node.nodeType should be ELEMENT');
|
||||
goog.asserts.assert(node.localName == 'LineString',
|
||||
'localName should be LineString');
|
||||
var properties = ol.xml.pushParseAndPop(/** @type {Object<string,*>} */ ({}),
|
||||
ol.format.KML.EXTRUDE_AND_ALTITUDE_MODE_PARSERS_, node,
|
||||
objectStack);
|
||||
var flatCoordinates =
|
||||
ol.format.KML.readFlatCoordinatesFromNode_(node, objectStack);
|
||||
if (goog.isDef(flatCoordinates)) {
|
||||
var lineString = new ol.geom.LineString(null);
|
||||
lineString.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates);
|
||||
lineString.setProperties(properties);
|
||||
return lineString;
|
||||
} else {
|
||||
return undefined;
|
||||
@@ -825,12 +829,16 @@ ol.format.KML.readLinearRing_ = function(node, objectStack) {
|
||||
'node.nodeType should be ELEMENT');
|
||||
goog.asserts.assert(node.localName == 'LinearRing',
|
||||
'localName should be LinearRing');
|
||||
var properties = ol.xml.pushParseAndPop(/** @type {Object<string,*>} */ ({}),
|
||||
ol.format.KML.EXTRUDE_AND_ALTITUDE_MODE_PARSERS_, node,
|
||||
objectStack);
|
||||
var flatCoordinates =
|
||||
ol.format.KML.readFlatCoordinatesFromNode_(node, objectStack);
|
||||
if (goog.isDef(flatCoordinates)) {
|
||||
var polygon = new ol.geom.Polygon(null);
|
||||
polygon.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates,
|
||||
[flatCoordinates.length]);
|
||||
polygon.setProperties(properties);
|
||||
return polygon;
|
||||
} else {
|
||||
return undefined;
|
||||
@@ -920,6 +928,9 @@ ol.format.KML.readPoint_ = function(node, objectStack) {
|
||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT,
|
||||
'node.nodeType should be ELEMENT');
|
||||
goog.asserts.assert(node.localName == 'Point', 'localName should be Point');
|
||||
var properties = ol.xml.pushParseAndPop(/** @type {Object<string,*>} */ ({}),
|
||||
ol.format.KML.EXTRUDE_AND_ALTITUDE_MODE_PARSERS_, node,
|
||||
objectStack);
|
||||
var flatCoordinates =
|
||||
ol.format.KML.readFlatCoordinatesFromNode_(node, objectStack);
|
||||
if (goog.isDefAndNotNull(flatCoordinates)) {
|
||||
@@ -927,6 +938,7 @@ ol.format.KML.readPoint_ = function(node, objectStack) {
|
||||
goog.asserts.assert(flatCoordinates.length == 3,
|
||||
'flatCoordinates should have a length of 3');
|
||||
point.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates);
|
||||
point.setProperties(properties);
|
||||
return point;
|
||||
} else {
|
||||
return undefined;
|
||||
@@ -945,6 +957,9 @@ ol.format.KML.readPolygon_ = function(node, objectStack) {
|
||||
'node.nodeType should be ELEMENT');
|
||||
goog.asserts.assert(node.localName == 'Polygon',
|
||||
'localName should be Polygon');
|
||||
var properties = ol.xml.pushParseAndPop(/** @type {Object<string,*>} */ ({}),
|
||||
ol.format.KML.EXTRUDE_AND_ALTITUDE_MODE_PARSERS_, node,
|
||||
objectStack);
|
||||
var flatLinearRings = ol.xml.pushParseAndPop(
|
||||
/** @type {Array.<Array.<number>>} */ ([null]),
|
||||
ol.format.KML.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack);
|
||||
@@ -960,6 +975,7 @@ ol.format.KML.readPolygon_ = function(node, objectStack) {
|
||||
}
|
||||
polygon.setFlatCoordinates(
|
||||
ol.geom.GeometryLayout.XYZ, flatCoordinates, ends);
|
||||
polygon.setProperties(properties);
|
||||
return polygon;
|
||||
} else {
|
||||
return undefined;
|
||||
@@ -1266,6 +1282,18 @@ ol.format.KML.EXTENDED_DATA_PARSERS_ = ol.xml.makeParsersNS(
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||
* @private
|
||||
*/
|
||||
ol.format.KML.EXTRUDE_AND_ALTITUDE_MODE_PARSERS_ = ol.xml.makeParsersNS(
|
||||
ol.format.KML.NAMESPACE_URIS_, {
|
||||
'extrude': ol.xml.makeObjectPropertySetter(ol.format.XSD.readBoolean),
|
||||
'altitudeMode': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString)
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||
|
||||
@@ -133,6 +133,8 @@ describe('ol.format.KML', function() {
|
||||
' <Placemark>' +
|
||||
' <Point>' +
|
||||
' <coordinates>1,2,3</coordinates>' +
|
||||
' <extrude>0</extrude>' +
|
||||
' <altitudeMode>absolute</altitudeMode>' +
|
||||
' </Point>' +
|
||||
' </Placemark>' +
|
||||
'</kml>';
|
||||
@@ -143,6 +145,8 @@ describe('ol.format.KML', function() {
|
||||
var g = f.getGeometry();
|
||||
expect(g).to.be.an(ol.geom.Point);
|
||||
expect(g.getCoordinates()).to.eql([1, 2, 3]);
|
||||
expect(g.get('extrude')).to.be(false);
|
||||
expect(g.get('altitudeMode')).to.be('absolute');
|
||||
});
|
||||
|
||||
it('can transform and read Point geometries', function() {
|
||||
@@ -338,6 +342,8 @@ describe('ol.format.KML', function() {
|
||||
' <Placemark>' +
|
||||
' <LineString>' +
|
||||
' <coordinates>1,2,3 4,5,6</coordinates>' +
|
||||
' <extrude>0</extrude>' +
|
||||
' <altitudeMode>absolute</altitudeMode>' +
|
||||
' </LineString>' +
|
||||
' </Placemark>' +
|
||||
'</kml>';
|
||||
@@ -348,6 +354,8 @@ describe('ol.format.KML', function() {
|
||||
var g = f.getGeometry();
|
||||
expect(g).to.be.an(ol.geom.LineString);
|
||||
expect(g.getCoordinates()).to.eql([[1, 2, 3], [4, 5, 6]]);
|
||||
expect(g.get('extrude')).to.be(false);
|
||||
expect(g.get('altitudeMode')).to.be('absolute');
|
||||
});
|
||||
|
||||
it('can write XY LineString geometries', function() {
|
||||
@@ -540,6 +548,8 @@ describe('ol.format.KML', function() {
|
||||
'<kml xmlns="http://earth.google.com/kml/2.2">' +
|
||||
' <Placemark>' +
|
||||
' <Polygon>' +
|
||||
' <extrude>0</extrude>' +
|
||||
' <altitudeMode>absolute</altitudeMode>' +
|
||||
' <outerBoundaryIs>' +
|
||||
' <LinearRing>' +
|
||||
' <coordinates>0,0,1 0,5,1 5,5,2 5,0,3</coordinates>' +
|
||||
@@ -556,6 +566,8 @@ describe('ol.format.KML', function() {
|
||||
expect(g).to.be.an(ol.geom.Polygon);
|
||||
expect(g.getCoordinates()).to.eql(
|
||||
[[[0, 0, 1], [0, 5, 1], [5, 5, 2], [5, 0, 3]]]);
|
||||
expect(g.get('extrude')).to.be(false);
|
||||
expect(g.get('altitudeMode')).to.be('absolute');
|
||||
});
|
||||
|
||||
it('can write XY Polygon geometries', function() {
|
||||
|
||||
Reference in New Issue
Block a user