From 66de55ef9b12b435c6488873f59f3863b9635b65 Mon Sep 17 00:00:00 2001 From: tschaub Date: Sat, 10 Dec 2011 16:36:53 -0700 Subject: [PATCH] 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