From 66de55ef9b12b435c6488873f59f3863b9635b65 Mon Sep 17 00:00:00 2001 From: tschaub Date: Sat, 10 Dec 2011 16:36:53 -0700 Subject: [PATCH 1/4] Allowing for WKT free builds. The WKT format is used for converting geometries to and from string representations. For builds that do not explicitly include the WKT format, the `OpenLayers.Geometry.fromWKT` returns `undefined`. --- lib/OpenLayers/Geometry.js | 57 +++++++++++++++++++++++--------------- tests/Geometry.html | 11 ++++++++ 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/lib/OpenLayers/Geometry.js b/lib/OpenLayers/Geometry.js index 17e10a4f11..e9b527c01b 100644 --- a/lib/OpenLayers/Geometry.js +++ b/lib/OpenLayers/Geometry.js @@ -5,8 +5,6 @@ /** * @requires OpenLayers/BaseTypes/Class.js - * @requires OpenLayers/Format/WKT.js - * @requires OpenLayers/Feature/Vector.js */ /** @@ -14,6 +12,9 @@ * A Geometry is a description of a geographic object. Create an instance of * this class with the constructor. This is a base class, * typical geometry types are described by subclasses of this class. + * + * Note that if you use the method, you must + * explicitly include the OpenLayers.Format.WKT in your build. */ OpenLayers.Geometry = OpenLayers.Class({ @@ -240,15 +241,23 @@ OpenLayers.Geometry = OpenLayers.Class({ /** * Method: toString - * Returns the Well-Known Text representation of a geometry + * Returns a text representation of the geometry. If the WKT format is + * included in a build, this will be the Well-Known Text + * representation. * * Returns: - * {String} Well-Known Text + * {String} String representation of this geometry. */ toString: function() { - return OpenLayers.Format.WKT.prototype.write( - new OpenLayers.Feature.Vector(this) - ); + var string; + if (OpenLayers.Format && OpenLayers.Format.WKT) { + string = OpenLayers.Format.WKT.prototype.write( + new OpenLayers.Feature.Vector(this) + ); + } else { + string = Object.prototype.toString.call(this); + } + return string; }, CLASS_NAME: "OpenLayers.Geometry" @@ -256,7 +265,9 @@ OpenLayers.Geometry = OpenLayers.Class({ /** * Function: OpenLayers.Geometry.fromWKT - * Generate a geometry given a Well-Known Text string. + * Generate a geometry given a Well-Known Text string. For this method to + * work, you must include the OpenLayers.Format.WKT in your build + * explicitly. * * Parameters: * wkt - {String} A string representing the geometry in Well-Known Text. @@ -265,22 +276,24 @@ OpenLayers.Geometry = OpenLayers.Class({ * {} A geometry of the appropriate class. */ OpenLayers.Geometry.fromWKT = function(wkt) { - var format = arguments.callee.format; - if(!format) { - format = new OpenLayers.Format.WKT(); - arguments.callee.format = format; - } var geom; - var result = format.read(wkt); - if(result instanceof OpenLayers.Feature.Vector) { - geom = result.geometry; - } else if(OpenLayers.Util.isArray(result)) { - var len = result.length; - var components = new Array(len); - for(var i=0; i From 4c97f492c61f2d987cec75e1ae6739e165affda1 Mon Sep 17 00:00:00 2001 From: tschaub Date: Sat, 10 Dec 2011 17:04:26 -0700 Subject: [PATCH 2/4] Describing changes in release notes. --- notes/2.12.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/notes/2.12.md b/notes/2.12.md index 5c9d60e125..b8faf0ad33 100644 --- a/notes/2.12.md +++ b/notes/2.12.md @@ -43,3 +43,10 @@ The `roundedCorner` option of `Control.LayerSwitcher` is deprecated, and it now See more detail in the Rico deprecation [pull request](https://github.com/openlayers/openlayers/pull/99). In future releases we intend to move the Rico and `AnchoredBubble` code into deprecated.js. You really should consider stop using Rico-based functionalities in your applications. + +## Changes in Geometry + +The base `OpenLayers.Geometry` class no longer depends on `OpenLayers.Format.WKT` or `OpenLayers.Feature.Vector`. If you want to make use of the `OpenLayers.Geometry.fromWKT` method, you must explicitly include the OpenLayers/Format/WKT.js file in your build. + +Without the WKT format included (by default), the the `OpenLayers.Geometry::toString` method now returns "[object Object]." Previously, it returned the Well-Known Text representation of the geometry. To maintain the previous behavior, include the OpenLayers/Format/WKT.js file in your build. + From 469842012b85bc35df191b8c01d00d98ad2ce627 Mon Sep 17 00:00:00 2001 From: tschaub Date: Sat, 10 Dec 2011 17:09:18 -0700 Subject: [PATCH 3/4] Tests for string methods without WKT. --- tests/Geometry.html | 2 ++ tests/Geometry/Point.html | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/tests/Geometry.html b/tests/Geometry.html index d655d86b83..e61326d34f 100644 --- a/tests/Geometry.html +++ b/tests/Geometry.html @@ -337,8 +337,10 @@ function test_fromWKT_undefined(t) { t.plan(1); + var WKT = OpenLayers.Format.WKT; OpenLayers.Format.WKT = null; + delete OpenLayers.Geometry.fromWKT.format; var geom = OpenLayers.Geometry.fromWKT("POINT(1 1)"); t.eq(geom, undefined, "undefined when OpenLayers.Format.WKT is not available"); diff --git a/tests/Geometry/Point.html b/tests/Geometry/Point.html index 838a587521..e688250b63 100644 --- a/tests/Geometry/Point.html +++ b/tests/Geometry/Point.html @@ -101,6 +101,21 @@ "toString() returns WKT" ); } + + function test_Point_toString_no_wkt(t) { + t.plan(1); + + var WKT = OpenLayers.Format.WKT; + OpenLayers.Format.WKT = null; + + var x = 10; + var y = 20; + point = new OpenLayers.Geometry.Point(x, y); + t.eq(point.toString(), "[object Object]", "default string representation"); + + OpenLayers.Format.WKT = WKT; + + } function test_Point_move(t) { t.plan(3); From f05d770d8be5a2875c45770dcd020df5c3ab4adf Mon Sep 17 00:00:00 2001 From: Peter Robins Date: Wed, 14 Dec 2011 16:53:51 +0000 Subject: [PATCH 4/4] Fix typo in release notes --- notes/2.12.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notes/2.12.md b/notes/2.12.md index b8faf0ad33..e4c004d9fd 100644 --- a/notes/2.12.md +++ b/notes/2.12.md @@ -48,5 +48,5 @@ In future releases we intend to move the Rico and `AnchoredBubble` code into dep The base `OpenLayers.Geometry` class no longer depends on `OpenLayers.Format.WKT` or `OpenLayers.Feature.Vector`. If you want to make use of the `OpenLayers.Geometry.fromWKT` method, you must explicitly include the OpenLayers/Format/WKT.js file in your build. -Without the WKT format included (by default), the the `OpenLayers.Geometry::toString` method now returns "[object Object]." Previously, it returned the Well-Known Text representation of the geometry. To maintain the previous behavior, include the OpenLayers/Format/WKT.js file in your build. +Without the WKT format included (by default), the `OpenLayers.Geometry::toString` method now returns "[object Object]." Previously, it returned the Well-Known Text representation of the geometry. To maintain the previous behavior, include the OpenLayers/Format/WKT.js file in your build.