From cbdf3522a717b15b808694ccfa652db81c4d521a Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 9 Nov 2007 18:50:06 +0000 Subject: [PATCH] correct writing of multi-part geometries for KML - thanks for the swift review crschmidt (closes #1132). git-svn-id: http://svn.openlayers.org/trunk/openlayers@5161 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Format/KML.js | 6 ++-- tests/Format/test_KML.html | 53 ++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/Format/KML.js b/lib/OpenLayers/Format/KML.js index 91f4c7f982..eb12ff95ce 100644 --- a/lib/OpenLayers/Format/KML.js +++ b/lib/OpenLayers/Format/KML.js @@ -496,7 +496,7 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, { * {DOMElement} A KML GeometryCollection node. */ multipoint: function(geometry) { - return this.buildGeometry.collection(geometry); + return this.buildGeometry.collection.apply(this, [geometry]); }, /** @@ -527,7 +527,7 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, { * {DOMElement} A KML GeometryCollection node. */ multilinestring: function(geometry) { - return this.buildGeometry.collection(geometry); + return this.buildGeometry.collection.apply(this, [geometry]); }, /** @@ -583,7 +583,7 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, { * {DOMElement} A KML GeometryCollection node. */ multipolygon: function(geometry) { - return this.buildGeometry.collection(geometry); + return this.buildGeometry.collection.apply(this, [geometry]); }, /** diff --git a/tests/Format/test_KML.html b/tests/Format/test_KML.html index 23cce029f8..18033760b8 100644 --- a/tests/Format/test_KML.html +++ b/tests/Format/test_KML.html @@ -60,6 +60,59 @@ 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 = 'OpenLayers exporttest outputtest nameNo description available0,1'; + 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 = 'OpenLayers exporttest outputtest nameNo description available1,0 0,1'; + 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 = 'OpenLayers exporttest outputtest nameNo description available0,0 1,0 0,1 0,0'; + t.eq(output, expected, "multilinestring correctly written"); + + }