diff --git a/lib/OpenLayers/Format/WKT.js b/lib/OpenLayers/Format/WKT.js index 14ea6bf593..0d0a6c53b7 100644 --- a/lib/OpenLayers/Format/WKT.js +++ b/lib/OpenLayers/Format/WKT.js @@ -69,6 +69,9 @@ OpenLayers.Format.WKT.prototype = } geometry = collection[i]; type = geometry.CLASS_NAME.split('.')[2].toLowerCase(); + if(!this.extract[type]) { + return null; + } data = this.extract[type].apply(this, [geometry]); pieces.push(type.toUpperCase() + '(' + data + ')'); } diff --git a/lib/OpenLayers/Geometry.js b/lib/OpenLayers/Geometry.js index 6898034059..75d8d4210f 100644 --- a/lib/OpenLayers/Geometry.js +++ b/lib/OpenLayers/Geometry.js @@ -4,6 +4,7 @@ /** * @class + * @requires OpenLayers/Format/WKT.js */ OpenLayers.Geometry = OpenLayers.Class.create(); OpenLayers.Geometry.prototype = { @@ -160,6 +161,14 @@ OpenLayers.Geometry.prototype = { return 0.0; }, + /** + * @returns the Well-Known Text representation of a geometry + * @type String + */ + toString: function() { + return OpenLayers.Format.WKT.prototype.write(this); + }, + /** @final @type String */ CLASS_NAME: "OpenLayers.Geometry" }; diff --git a/lib/OpenLayers/Geometry/Collection.js b/lib/OpenLayers/Geometry/Collection.js index 5dc2044094..c75ab9c3d9 100644 --- a/lib/OpenLayers/Geometry/Collection.js +++ b/lib/OpenLayers/Geometry/Collection.js @@ -54,15 +54,6 @@ OpenLayers.Geometry.Collection.prototype = this.components = null; }, - /** - * @returns The coordinates components as a string - * @type String - */ - toString: function() { - return this.components.toString(); - }, - - /** * @returns An exact clone of this collection * @type OpenLayers.Geometry.Collection diff --git a/lib/OpenLayers/Geometry/Point.js b/lib/OpenLayers/Geometry/Point.js index d3ad6e9a97..929ffcbe1c 100644 --- a/lib/OpenLayers/Geometry/Point.js +++ b/lib/OpenLayers/Geometry/Point.js @@ -84,14 +84,6 @@ OpenLayers.Geometry.Point.prototype = } return equals; }, - - /** - * @returns the coordinates as a string - * @type String - */ - toString: function() { - return this.toShortString(); - }, /** * @return Shortened String representation of Point object. diff --git a/tests/Geometry/test_LineString.html b/tests/Geometry/test_LineString.html index eca8f579a8..4ab0a91a50 100644 --- a/tests/Geometry/test_LineString.html +++ b/tests/Geometry/test_LineString.html @@ -28,7 +28,9 @@ t.plan(1); line = new OpenLayers.Geometry.LineString(components); - t.eq( line.toString(), components.toString(), "toString output checks in"); + t.eq(line.toString(), + "LINESTRING(10 15,0 0)", + "toString() returns WKT"); } function test_03_LineString_removeComponent(t) { @@ -56,7 +58,9 @@ function test_04_LineString_move(t) { t.plan(4); - line = new OpenLayers.Geometry.LineString(components); + var components = [new OpenLayers.Geometry.Point(10,15), + new OpenLayers.Geometry.Point(0,0)]; + var line = new OpenLayers.Geometry.LineString(components); var x0 = components[0].x; var y0 = components[0].y; diff --git a/tests/Geometry/test_LinearRing.html b/tests/Geometry/test_LinearRing.html index 3f93f9b479..cca2423ad9 100644 --- a/tests/Geometry/test_LinearRing.html +++ b/tests/Geometry/test_LinearRing.html @@ -97,13 +97,6 @@ t.eq(ring.getArea(), 100, "getArea works lovely"); } - function test_05_LinearRing_toString(t) { - t.plan(1); - - ring = new OpenLayers.Geometry.LinearRing(components); - t.eq( ring.toString(), components.toString() + ',' + components[0].toString(), "toString output is ok"); - } - // --> diff --git a/tests/Geometry/test_Point.html b/tests/Geometry/test_Point.html index db70f24832..c0f01959ce 100644 --- a/tests/Geometry/test_Point.html +++ b/tests/Geometry/test_Point.html @@ -60,7 +60,8 @@ var y = 20; point = new OpenLayers.Geometry.Point(x, y); bounds = point.getBounds(); - t.eq( point.toString(), x + ", " + y, "toString() works" ); + t.eq(point.toString(), "POINT(" + x + " " + y + ")", + "toString() returns WKT" ); }