Tag RC4 release.
git-svn-id: http://svn.openlayers.org/tags/openlayers/release-2.4-rc4@3178 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
|
||||
* See http://svn.openlayers.org/trunk/openlayers/repository-license.txt
|
||||
/* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
|
||||
* See http://svn.openlayers.org/trunk/openlayers/release-license.txt
|
||||
* for the full text of the license. */
|
||||
|
||||
/**
|
||||
@@ -25,38 +25,41 @@ OpenLayers.Format.WKT.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* Deserialize a WKT string and return an OpenLayers.Geometry or an array
|
||||
* of OpenLayers.Geometry. Supports WKT for POINT, MULTIPOINT, LINESTRING,
|
||||
* MULTILINESTRING, POLYGON, MULTIPOLYGON, and GEOMETRYCOLLECTION.
|
||||
* Deserialize a WKT string and return an OpenLayers.Feature.Vector or an
|
||||
* array of OpenLayers.Feature.Vector. Supports WKT for POINT, MULTIPOINT,
|
||||
* LINESTRING, MULTILINESTRING, POLYGON, MULTIPOLYGON, and
|
||||
* GEOMETRYCOLLECTION.
|
||||
* @param {String} wkt A WKT string
|
||||
* @returns {OpenLayers.Geometry|Array} A geometry or array of geometries
|
||||
* for GEOMETRYCOLLECTION WKT.
|
||||
* @returns {OpenLayers.Feature.Vector|Array} A feature or array of
|
||||
* features for
|
||||
* GEOMETRYCOLLECTION WKT.
|
||||
*/
|
||||
read: function(wkt) {
|
||||
var geometry, type, str;
|
||||
var features, type, str;
|
||||
var matches = this.regExes.typeStr.exec(wkt);
|
||||
if(matches) {
|
||||
type = matches[1].toLowerCase();
|
||||
str = matches[2];
|
||||
if(this.parse[type]) {
|
||||
geometry = this.parse[type].apply(this, [str]);
|
||||
features = this.parse[type].apply(this, [str]);
|
||||
}
|
||||
}
|
||||
return geometry;
|
||||
return features;
|
||||
},
|
||||
|
||||
/**
|
||||
* Serialize a geometry or array of geometries into a WKT string.
|
||||
* @param {OpenLayers.Geometry|Array} geom A geometry or array of geometries
|
||||
* Serialize a feature or array of features into a WKT string.
|
||||
* @param {OpenLayers.Feature.Vector|Array} features A feature or array of
|
||||
* features
|
||||
* @returns {String} The WKT string representation of the input geometries
|
||||
*/
|
||||
write: function(geom) {
|
||||
write: function(features) {
|
||||
var collection, geometry, type, data, isCollection;
|
||||
if(geom.constructor == Array) {
|
||||
collection = geom;
|
||||
if(features.constructor == Array) {
|
||||
collection = features;
|
||||
isCollection = true;
|
||||
} else {
|
||||
collection = [geom];
|
||||
collection = [features];
|
||||
isCollection = false;
|
||||
}
|
||||
var pieces = [];
|
||||
@@ -67,7 +70,7 @@ OpenLayers.Format.WKT.prototype =
|
||||
if(isCollection && i>0) {
|
||||
pieces.push(',');
|
||||
}
|
||||
geometry = collection[i];
|
||||
geometry = collection[i].geometry;
|
||||
type = geometry.CLASS_NAME.split('.')[2].toLowerCase();
|
||||
if(!this.extract[type]) {
|
||||
return null;
|
||||
@@ -178,47 +181,57 @@ OpenLayers.Format.WKT.prototype =
|
||||
*/
|
||||
parse: {
|
||||
/**
|
||||
* Return point geometry given a point WKT fragment.
|
||||
* Return point feature given a point WKT fragment.
|
||||
* @param {String} str A WKT fragment representing the point
|
||||
* @returns {OpenLayers.Geometry.Point} A point geometry
|
||||
* @returns {OpenLayers.Feature.Vector} A point feature
|
||||
* @private
|
||||
*/
|
||||
'point': function(str) {
|
||||
var coords = str.trim().split(this.regExes.spaces);
|
||||
return new OpenLayers.Geometry.Point(coords[0], coords[1]);
|
||||
return new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.Point(coords[0], coords[1])
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Return a multipoint geometry given a multipoint WKT fragment.
|
||||
* Return a multipoint feature given a multipoint WKT fragment.
|
||||
* @param {String} A WKT fragment representing the multipoint
|
||||
* @returns {OpenLayers.Geometry.MultiPoint} A multipoint geometry
|
||||
* @returns {OpenLayers.Feature.Vector} A multipoint feature
|
||||
* @private
|
||||
*/
|
||||
'multipoint': function(str) {
|
||||
var points = str.trim().split(',');
|
||||
var components = [];
|
||||
for(var i=0; i<points.length; ++i) {
|
||||
components.push(this.parse.point.apply(this, [points[i]]));
|
||||
components.push(this.parse.point.apply(this, [points[i]]).geometry);
|
||||
}
|
||||
return new OpenLayers.Geometry.MultiPoint(components);
|
||||
return new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.MultiPoint(components)
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Return a linestring geometry given a linestring WKT fragment.
|
||||
* Return a linestring feature given a linestring WKT fragment.
|
||||
* @param {String} A WKT fragment representing the linestring
|
||||
* @returns {OpenLayers.Geometry.LineString} A linestring geometry
|
||||
* @returns {OpenLayers.Feature.Vector} A linestring feature
|
||||
* @private
|
||||
*/
|
||||
'linestring': function(str) {
|
||||
var points = str.trim().split(',');
|
||||
var components = [];
|
||||
for(var i=0; i<points.length; ++i) {
|
||||
components.push(this.parse.point.apply(this, [points[i]]));
|
||||
components.push(this.parse.point.apply(this, [points[i]]).geometry);
|
||||
}
|
||||
return new OpenLayers.Geometry.LineString(components);
|
||||
return new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.LineString(components)
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Return a multilinestring geometry given a multilinestring WKT fragment.
|
||||
* Return a multilinestring feature given a multilinestring WKT fragment.
|
||||
* @param {String} A WKT fragment representing the multilinestring
|
||||
* @returns {OpenLayers.Geometry.LineString} A multilinestring geometry
|
||||
* @returns {OpenLayers.Feature.Vector} A multilinestring feature
|
||||
* @private
|
||||
*/
|
||||
'multilinestring': function(str) {
|
||||
var line;
|
||||
@@ -226,15 +239,18 @@ OpenLayers.Format.WKT.prototype =
|
||||
var components = [];
|
||||
for(var i=0; i<lines.length; ++i) {
|
||||
line = lines[i].replace(this.regExes.trimParens, '$1');
|
||||
components.push(this.parse.linestring.apply(this, [line]));
|
||||
components.push(this.parse.linestring.apply(this, [line]).geometry);
|
||||
}
|
||||
return new OpenLayers.Geometry.MultiLineString(components);
|
||||
return new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.MultiLineString(components)
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Return a polygon geometry given a polygon WKT fragment.
|
||||
* Return a polygon feature given a polygon WKT fragment.
|
||||
* @param {String} A WKT fragment representing the polygon
|
||||
* @returns {OpenLayers.Geometry.Polygon} A polygon geometry
|
||||
* @returns {OpenLayers.Feature.Vector} A polygon feature
|
||||
* @private
|
||||
*/
|
||||
'polygon': function(str) {
|
||||
var ring, linestring, linearring;
|
||||
@@ -242,17 +258,20 @@ OpenLayers.Format.WKT.prototype =
|
||||
var components = [];
|
||||
for(var i=0; i<rings.length; ++i) {
|
||||
ring = rings[i].replace(this.regExes.trimParens, '$1');
|
||||
linestring = this.parse.linestring.apply(this, [ring]);
|
||||
linearring = new OpenLayers.Geometry.LinearRing(linestring.components);
|
||||
linestring = this.parse.linestring.apply(this, [ring]).geometry;
|
||||
linearring = new OpenLayers.Geometry.LinearRing(linestring.components)
|
||||
components.push(linearring);
|
||||
}
|
||||
return new OpenLayers.Geometry.Polygon(components);
|
||||
return new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.Polygon(components)
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Return a multipolygon geometry given a multipolygon WKT fragment.
|
||||
* Return a multipolygon feature given a multipolygon WKT fragment.
|
||||
* @param {String} A WKT fragment representing the multipolygon
|
||||
* @returns {OpenLayers.Geometry.MultiPolygon} A multipolygon geometry
|
||||
* @returns {OpenLayers.Feature.Vector} A multipolygon feature
|
||||
* @private
|
||||
*/
|
||||
'multipolygon': function(str) {
|
||||
var polygon;
|
||||
@@ -260,15 +279,18 @@ OpenLayers.Format.WKT.prototype =
|
||||
var components = [];
|
||||
for(var i=0; i<polygons.length; ++i) {
|
||||
polygon = polygons[i].replace(this.regExes.trimParens, '$1');
|
||||
components.push(this.parse.polygon.apply(this, [polygon]));
|
||||
components.push(this.parse.polygon.apply(this, [polygon]).geometry);
|
||||
}
|
||||
return new OpenLayers.Geometry.MultiPolygon(components);
|
||||
return new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.MultiPolygon(components)
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Return an array of geometries given a geometrycollection WKT fragment.
|
||||
* Return an array of features given a geometrycollection WKT fragment.
|
||||
* @param {String} A WKT fragment representing the geometrycollection
|
||||
* @returns {Array} An array of OpenLayers.Geometry
|
||||
* @returns {Array} An array of OpenLayers.Feature.Vector
|
||||
* @private
|
||||
*/
|
||||
'geometrycollection': function(str) {
|
||||
// separate components of the collection with |
|
||||
|
||||
Reference in New Issue
Block a user