Adding a convenience method for creating a WKT format and creating geometries with WKT strings. r=crschmidt (closes #1908)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@8696 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2009-01-17 01:32:17 +00:00
parent cb62d883dc
commit 89431424fb
2 changed files with 84 additions and 0 deletions

View File

@@ -203,6 +203,36 @@ OpenLayers.Geometry = OpenLayers.Class({
CLASS_NAME: "OpenLayers.Geometry"
});
/**
* Function: OpenLayers.Geometry.fromWKT
* Generate a geometry given a Well-Known Text string.
*
* Parameters:
* wkt - {String} A string representing the geometry in Well-Known Text.
*
* Returns:
* {<OpenLayers.Geometry>} 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(result instanceof Array) {
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);
}
return geom;
};
/**
* Method: OpenLayers.Geometry.segmentsIntersect