[OpenLayers-Commits] r5161 - in trunk/openlayers: lib/OpenLayers/Format tests/Format
commits at openlayers.org
commits at openlayers.org
Fri Nov 9 13:50:07 EST 2007
Author: tschaub
Date: 2007-11-09 13:50:06 -0500 (Fri, 09 Nov 2007)
New Revision: 5161
Modified:
trunk/openlayers/lib/OpenLayers/Format/KML.js
trunk/openlayers/tests/Format/test_KML.html
Log:
correct writing of multi-part geometries for KML - thanks for the swift review crschmidt (closes #1132).
Modified: trunk/openlayers/lib/OpenLayers/Format/KML.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/KML.js 2007-11-09 18:19:14 UTC (rev 5160)
+++ trunk/openlayers/lib/OpenLayers/Format/KML.js 2007-11-09 18:50:06 UTC (rev 5161)
@@ -496,7 +496,7 @@
* {DOMElement} A KML GeometryCollection node.
*/
multipoint: function(geometry) {
- return this.buildGeometry.collection(geometry);
+ return this.buildGeometry.collection.apply(this, [geometry]);
},
/**
@@ -527,7 +527,7 @@
* {DOMElement} A KML GeometryCollection node.
*/
multilinestring: function(geometry) {
- return this.buildGeometry.collection(geometry);
+ return this.buildGeometry.collection.apply(this, [geometry]);
},
/**
@@ -583,7 +583,7 @@
* {DOMElement} A KML GeometryCollection node.
*/
multipolygon: function(geometry) {
- return this.buildGeometry.collection(geometry);
+ return this.buildGeometry.collection.apply(this, [geometry]);
},
/**
Modified: trunk/openlayers/tests/Format/test_KML.html
===================================================================
--- trunk/openlayers/tests/Format/test_KML.html 2007-11-09 18:19:14 UTC (rev 5160)
+++ trunk/openlayers/tests/Format/test_KML.html 2007-11-09 18:50:06 UTC (rev 5161)
@@ -60,7 +60,60 @@
var kmlOut = format.write(features);
t.eq(kmlOut, kmlExpected, "correctly writes an KML doc string");
}
+
+ function test_Format_KML_write_multis(t) {
+ /**
+ * KML doesn't have a representation for multi geometries of a
+ * specific type. KML MultiGeometry maps to OL Geometry.Collection.
+ * Because of this, multi-geometries in OL can't make a round trip
+ * through KML (an OL MultiPoint maps to a KML MultiGeometry
+ * containing points, which maps back to an OL Collection containing
+ * points). So we need to acceptance tests for the writing of
+ * multi-geometries specifically instead of relying on the round-trip
+ * write test above.
+ */
+ t.plan(3);
+ var format = new OpenLayers.Format.KML({foldersDesc: "test output"});
+ var multi, feature, output, expected;
+
+ // test multipoint
+ var multi = new OpenLayers.Geometry.MultiPoint([
+ new OpenLayers.Geometry.Point(0, 1)
+ ]);
+ feature = new OpenLayers.Feature.Vector(multi, {name: "test name"});
+ output = format.write(feature);
+ expected = '<kml xmlns="http://earth.google.com/kml/2.0"><Folder><name>OpenLayers export</name><description>test output</description><Placemark><name>test name</name><description>No description available</description><MultiGeometry><Point><coordinates>0,1</coordinates></Point></MultiGeometry></Placemark></Folder></kml>';
+ t.eq(output, expected, "multipoint correctly written");
+
+ // test multilinestring
+ var multi = new OpenLayers.Geometry.MultiLineString([
+ new OpenLayers.Geometry.LineString([
+ new OpenLayers.Geometry.Point(1, 0),
+ new OpenLayers.Geometry.Point(0, 1)
+ ])
+ ]);
+ feature = new OpenLayers.Feature.Vector(multi, {name: "test name"});
+ output = format.write(feature);
+ expected = '<kml xmlns="http://earth.google.com/kml/2.0"><Folder><name>OpenLayers export</name><description>test output</description><Placemark><name>test name</name><description>No description available</description><MultiGeometry><LineString><coordinates>1,0 0,1</coordinates></LineString></MultiGeometry></Placemark></Folder></kml>';
+ t.eq(output, expected, "multilinestring correctly written");
+ // test multipolygon
+ var multi = new OpenLayers.Geometry.MultiPolygon([
+ new OpenLayers.Geometry.Polygon([
+ new OpenLayers.Geometry.LinearRing([
+ new OpenLayers.Geometry.Point(0, 0),
+ new OpenLayers.Geometry.Point(1, 0),
+ new OpenLayers.Geometry.Point(0, 1)
+ ])
+ ])
+ ]);
+ feature = new OpenLayers.Feature.Vector(multi, {name: "test name"});
+ output = format.write(feature);
+ expected = '<kml xmlns="http://earth.google.com/kml/2.0"><Folder><name>OpenLayers export</name><description>test output</description><Placemark><name>test name</name><description>No description available</description><MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>0,0 1,0 0,1 0,0</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry></Placemark></Folder></kml>';
+ t.eq(output, expected, "multilinestring correctly written");
+
+ }
+
</script>
</head>
<body>
More information about the Commits
mailing list