EncodedPolyline: Added write() method
This commit is contained in:
@@ -130,6 +130,51 @@ OpenLayers.Format.EncodedPolyline = OpenLayers.Class(OpenLayers.Format, {
|
||||
return points;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: write
|
||||
* Serialize a feature or array of features into a WKT string.
|
||||
*
|
||||
* Parameters:
|
||||
* features - {<OpenLayers.Feature.Vector>|Array} A feature or array of
|
||||
* features
|
||||
*
|
||||
* Returns:
|
||||
* {String} The WKT string representation of the input geometries
|
||||
*/
|
||||
write: function(features) {
|
||||
var feature;
|
||||
if (features.constructor == Array)
|
||||
feature = features[0];
|
||||
else
|
||||
feature = features;
|
||||
|
||||
var geometry = feature.geometry;
|
||||
var type = geometry.CLASS_NAME.split('.')[2].toLowerCase();
|
||||
|
||||
var pointGeometries;
|
||||
if (type == "point")
|
||||
pointGeometries = new Array(geometry);
|
||||
else if (type == "linestring" ||
|
||||
type == "linearring" ||
|
||||
type == "multipoint")
|
||||
pointGeometries = geometry.components;
|
||||
else if (type == "polygon")
|
||||
pointGeometries = geometry.components[0].components;
|
||||
else
|
||||
return null;
|
||||
|
||||
var points = new Array();
|
||||
for (var i in pointGeometries) {
|
||||
var pointGeometry = pointGeometries[i];
|
||||
var point = [Math.round(pointGeometry.y * 1e5),
|
||||
Math.round(pointGeometry.x * 1e5)];
|
||||
points.push(point);
|
||||
}
|
||||
|
||||
var result = this.encode(points, 2);
|
||||
return result;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: encode
|
||||
* Serialize an array of n-dimensional points and return an encoded string
|
||||
|
||||
Reference in New Issue
Block a user