Merge pull request #6825 from oterral/tesselate
Read/write Tessellate tag in KML format
This commit is contained in:
@@ -1065,19 +1065,25 @@ ol.format.KML.setCommonGeometryProperties_ = function(multiGeometry,
|
||||
geometries) {
|
||||
var ii = geometries.length;
|
||||
var extrudes = new Array(geometries.length);
|
||||
var tessellates = new Array(geometries.length);
|
||||
var altitudeModes = new Array(geometries.length);
|
||||
var geometry, i, hasExtrude, hasAltitudeMode;
|
||||
hasExtrude = hasAltitudeMode = false;
|
||||
var geometry, i, hasExtrude, hasTessellate, hasAltitudeMode;
|
||||
hasExtrude = hasTessellate = hasAltitudeMode = false;
|
||||
for (i = 0; i < ii; ++i) {
|
||||
geometry = geometries[i];
|
||||
extrudes[i] = geometry.get('extrude');
|
||||
tessellates[i] = geometry.get('tessellate');
|
||||
altitudeModes[i] = geometry.get('altitudeMode');
|
||||
hasExtrude = hasExtrude || extrudes[i] !== undefined;
|
||||
hasTessellate = hasTessellate || tessellates[i] !== undefined;
|
||||
hasAltitudeMode = hasAltitudeMode || altitudeModes[i];
|
||||
}
|
||||
if (hasExtrude) {
|
||||
multiGeometry.set('extrude', extrudes);
|
||||
}
|
||||
if (hasTessellate) {
|
||||
multiGeometry.set('tessellate', tessellates);
|
||||
}
|
||||
if (hasAltitudeMode) {
|
||||
multiGeometry.set('altitudeMode', altitudeModes);
|
||||
}
|
||||
@@ -1371,6 +1377,7 @@ ol.format.KML.LOD_PARSERS_ = ol.xml.makeStructureNS(
|
||||
ol.format.KML.EXTRUDE_AND_ALTITUDE_MODE_PARSERS_ = ol.xml.makeStructureNS(
|
||||
ol.format.KML.NAMESPACE_URIS_, {
|
||||
'extrude': ol.xml.makeObjectPropertySetter(ol.format.XSD.readBoolean),
|
||||
'tessellate': ol.xml.makeObjectPropertySetter(ol.format.XSD.readBoolean),
|
||||
'altitudeMode': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString)
|
||||
});
|
||||
|
||||
@@ -2468,10 +2475,16 @@ ol.format.KML.writePrimitiveGeometry_ = function(node, geometry, objectStack) {
|
||||
var /** @type {ol.XmlNodeStackItem} */ context = {node: node};
|
||||
context['layout'] = geometry.getLayout();
|
||||
context['stride'] = geometry.getStride();
|
||||
ol.xml.pushSerializeAndPop(context,
|
||||
ol.format.KML.PRIMITIVE_GEOMETRY_SERIALIZERS_,
|
||||
ol.format.KML.COORDINATES_NODE_FACTORY_,
|
||||
[flatCoordinates], objectStack);
|
||||
|
||||
// serialize properties (properties unknown to KML are not serialized)
|
||||
var properties = geometry.getProperties();
|
||||
properties.coordinates = flatCoordinates;
|
||||
|
||||
var parentNode = objectStack[objectStack.length - 1].node;
|
||||
var orderedKeys = ol.format.KML.PRIMITIVE_GEOMETRY_SEQUENCE_[parentNode.namespaceURI];
|
||||
var values = ol.xml.makeSequence(properties, orderedKeys);
|
||||
ol.xml.pushSerializeAndPop(context, ol.format.KML.PRIMITIVE_GEOMETRY_SERIALIZERS_,
|
||||
ol.xml.OBJECT_PROPERTY_NODE_FACTORY, values, objectStack, orderedKeys);
|
||||
};
|
||||
|
||||
|
||||
@@ -2632,7 +2645,6 @@ ol.format.KML.GEOMETRY_TYPE_TO_NODENAME_ = {
|
||||
'GeometryCollection': 'MultiGeometry'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object.<string, Array.<string>>}
|
||||
@@ -2808,6 +2820,17 @@ ol.format.KML.PLACEMARK_SERIALIZERS_ = ol.xml.makeStructureNS(
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object.<string, Array.<string>>}
|
||||
* @private
|
||||
*/
|
||||
ol.format.KML.PRIMITIVE_GEOMETRY_SEQUENCE_ = ol.xml.makeStructureNS(
|
||||
ol.format.KML.NAMESPACE_URIS_, [
|
||||
'extrude', 'tessellate', 'altitudeMode', 'coordinates'
|
||||
]);
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
|
||||
@@ -2815,6 +2838,9 @@ ol.format.KML.PLACEMARK_SERIALIZERS_ = ol.xml.makeStructureNS(
|
||||
*/
|
||||
ol.format.KML.PRIMITIVE_GEOMETRY_SERIALIZERS_ = ol.xml.makeStructureNS(
|
||||
ol.format.KML.NAMESPACE_URIS_, {
|
||||
'extrude': ol.xml.makeChildAppender(ol.format.XSD.writeBooleanTextNode),
|
||||
'tessellate': ol.xml.makeChildAppender(ol.format.XSD.writeBooleanTextNode),
|
||||
'altitudeMode': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
|
||||
'coordinates': ol.xml.makeChildAppender(
|
||||
ol.format.KML.writeCoordinatesTextNode_)
|
||||
});
|
||||
@@ -2926,16 +2952,6 @@ ol.format.KML.GEOMETRY_NODE_FACTORY_ = function(value, objectStack,
|
||||
ol.format.KML.COLOR_NODE_FACTORY_ = ol.xml.makeSimpleNodeFactory('color');
|
||||
|
||||
|
||||
/**
|
||||
* A factory for creating coordinates nodes.
|
||||
* @const
|
||||
* @type {function(*, Array.<*>, string=): (Node|undefined)}
|
||||
* @private
|
||||
*/
|
||||
ol.format.KML.COORDINATES_NODE_FACTORY_ =
|
||||
ol.xml.makeSimpleNodeFactory('coordinates');
|
||||
|
||||
|
||||
/**
|
||||
* A factory for creating Data nodes.
|
||||
* @const
|
||||
|
||||
@@ -192,6 +192,33 @@ describe('ol.format.KML', function() {
|
||||
expect(node).to.xmleql(ol.xml.parse(text));
|
||||
});
|
||||
|
||||
|
||||
it('can write properties', function() {
|
||||
var lineString = new ol.geom.LineString([[1, 2], [3, 4]]);
|
||||
lineString.set('extrude', false);
|
||||
lineString.set('tessellate', true);
|
||||
lineString.set('altitudeMode', 'clampToGround');
|
||||
lineString.set('unsupportedProperty', 'foo');
|
||||
var features = [new ol.Feature(lineString)];
|
||||
var node = format.writeFeaturesNode(features);
|
||||
var text =
|
||||
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
|
||||
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
|
||||
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
|
||||
' xsi:schemaLocation="http://www.opengis.net/kml/2.2' +
|
||||
' https://developers.google.com/kml/schema/kml22gx.xsd">' +
|
||||
' <Placemark>' +
|
||||
' <LineString>' +
|
||||
' <extrude>0</extrude>' +
|
||||
' <tessellate>1</tessellate>' +
|
||||
' <altitudeMode>clampToGround</altitudeMode>' +
|
||||
' <coordinates>1,2 3,4</coordinates>' +
|
||||
' </LineString>' +
|
||||
' </Placemark>' +
|
||||
'</kml>';
|
||||
expect(node).to.xmleql(ol.xml.parse(text));
|
||||
});
|
||||
|
||||
it('can read Point geometries', function() {
|
||||
var text =
|
||||
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
|
||||
@@ -412,6 +439,7 @@ describe('ol.format.KML', function() {
|
||||
' <LineString>' +
|
||||
' <coordinates>1,2,3 4,5,6</coordinates>' +
|
||||
' <extrude>0</extrude>' +
|
||||
' <tessellate>1</tessellate>' +
|
||||
' <altitudeMode>absolute</altitudeMode>' +
|
||||
' </LineString>' +
|
||||
' </Placemark>' +
|
||||
@@ -424,6 +452,7 @@ describe('ol.format.KML', function() {
|
||||
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('tessellate')).to.be(true);
|
||||
expect(g.get('altitudeMode')).to.be('absolute');
|
||||
});
|
||||
|
||||
@@ -964,6 +993,7 @@ describe('ol.format.KML', function() {
|
||||
' <MultiGeometry>' +
|
||||
' <LineString>' +
|
||||
' <extrude>0</extrude>' +
|
||||
' <tessellate>0</tessellate>' +
|
||||
' <altitudeMode>absolute</altitudeMode>' +
|
||||
' <coordinates>1,2,3 4,5,6</coordinates>' +
|
||||
' </LineString>' +
|
||||
@@ -985,6 +1015,10 @@ describe('ol.format.KML', function() {
|
||||
expect(g.get('extrude')).to.have.length(2);
|
||||
expect(g.get('extrude')[0]).to.be(false);
|
||||
expect(g.get('extrude')[1]).to.be(undefined);
|
||||
expect(g.get('tessellate')).to.be.an('array');
|
||||
expect(g.get('tessellate')).to.have.length(2);
|
||||
expect(g.get('tessellate')[0]).to.be(false);
|
||||
expect(g.get('tessellate')[1]).to.be(undefined);
|
||||
expect(g.get('altitudeMode')).to.be.an('array');
|
||||
expect(g.get('altitudeMode')).to.have.length(2);
|
||||
expect(g.get('altitudeMode')[0]).to.be('absolute');
|
||||
|
||||
Reference in New Issue
Block a user