Merge pull request #102 from tschaub/nowkt
Allow for builds without WKT format
This commit is contained in:
+35
-22
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @requires OpenLayers/BaseTypes/Class.js
|
* @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
|
* A Geometry is a description of a geographic object. Create an instance of
|
||||||
* this class with the <OpenLayers.Geometry> constructor. This is a base class,
|
* this class with the <OpenLayers.Geometry> constructor. This is a base class,
|
||||||
* typical geometry types are described by subclasses of this class.
|
* typical geometry types are described by subclasses of this class.
|
||||||
|
*
|
||||||
|
* Note that if you use the <OpenLayers.Geometry.fromWKT> method, you must
|
||||||
|
* explicitly include the OpenLayers.Format.WKT in your build.
|
||||||
*/
|
*/
|
||||||
OpenLayers.Geometry = OpenLayers.Class({
|
OpenLayers.Geometry = OpenLayers.Class({
|
||||||
|
|
||||||
@@ -240,15 +241,23 @@ OpenLayers.Geometry = OpenLayers.Class({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: toString
|
* 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:
|
* Returns:
|
||||||
* {String} Well-Known Text
|
* {String} String representation of this geometry.
|
||||||
*/
|
*/
|
||||||
toString: function() {
|
toString: function() {
|
||||||
return OpenLayers.Format.WKT.prototype.write(
|
var string;
|
||||||
new OpenLayers.Feature.Vector(this)
|
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"
|
CLASS_NAME: "OpenLayers.Geometry"
|
||||||
@@ -256,7 +265,9 @@ OpenLayers.Geometry = OpenLayers.Class({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Function: OpenLayers.Geometry.fromWKT
|
* 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:
|
* Parameters:
|
||||||
* wkt - {String} A string representing the geometry in Well-Known Text.
|
* wkt - {String} A string representing the geometry in Well-Known Text.
|
||||||
@@ -265,22 +276,24 @@ OpenLayers.Geometry = OpenLayers.Class({
|
|||||||
* {<OpenLayers.Geometry>} A geometry of the appropriate class.
|
* {<OpenLayers.Geometry>} A geometry of the appropriate class.
|
||||||
*/
|
*/
|
||||||
OpenLayers.Geometry.fromWKT = function(wkt) {
|
OpenLayers.Geometry.fromWKT = function(wkt) {
|
||||||
var format = arguments.callee.format;
|
|
||||||
if(!format) {
|
|
||||||
format = new OpenLayers.Format.WKT();
|
|
||||||
arguments.callee.format = format;
|
|
||||||
}
|
|
||||||
var geom;
|
var geom;
|
||||||
var result = format.read(wkt);
|
if (OpenLayers.Format && OpenLayers.Format.WKT) {
|
||||||
if(result instanceof OpenLayers.Feature.Vector) {
|
var format = OpenLayers.Geometry.fromWKT.format;
|
||||||
geom = result.geometry;
|
if (!format) {
|
||||||
} else if(OpenLayers.Util.isArray(result)) {
|
format = new OpenLayers.Format.WKT();
|
||||||
var len = result.length;
|
OpenLayers.Geometry.fromWKT.format = format;
|
||||||
var components = new Array(len);
|
}
|
||||||
for(var i=0; i<len; ++i) {
|
var result = format.read(wkt);
|
||||||
components[i] = result[i].geometry;
|
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<len; ++i) {
|
||||||
|
components[i] = result[i].geometry;
|
||||||
|
}
|
||||||
|
geom = new OpenLayers.Geometry.Collection(components);
|
||||||
}
|
}
|
||||||
geom = new OpenLayers.Geometry.Collection(components);
|
|
||||||
}
|
}
|
||||||
return geom;
|
return geom;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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).
|
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.
|
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 `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.
|
||||||
|
|
||||||
|
|||||||
@@ -334,6 +334,19 @@
|
|||||||
t.geom_eq(wkt(cases[i].wkt), cases[i].geom, "case " + i);
|
t.geom_eq(wkt(cases[i].wkt), cases[i].geom, "case " + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
OpenLayers.Format.WKT = WKT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -101,6 +101,21 @@
|
|||||||
"toString() returns WKT" );
|
"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) {
|
function test_Point_move(t) {
|
||||||
t.plan(3);
|
t.plan(3);
|
||||||
|
|||||||
Reference in New Issue
Block a user