diff --git a/lib/OpenLayers/Format/EncodedPolyline.js b/lib/OpenLayers/Format/EncodedPolyline.js
index a71b0a449b..5c7b68c221 100644
--- a/lib/OpenLayers/Format/EncodedPolyline.js
+++ b/lib/OpenLayers/Format/EncodedPolyline.js
@@ -61,11 +61,50 @@ OpenLayers.Format.EncodedPolyline = OpenLayers.Class(OpenLayers.Format, {
else if (this.geometryType != "polygon")
return null;
+ var points = this.decode(encoded, 2);
+ var pointGeometries = new Array();
+ for (i in points) {
+ var point = points[i];
+ pointGeometries.push(
+ new OpenLayers.Geometry.Point(point[1] * 1e-5, point[0] * 1e-5)
+ );
+ }
+
+ if (this.geometryType == "polygon")
+ return new OpenLayers.Feature.Vector(
+ new OpenLayers.Geometry.Polygon([
+ new OpenLayers.Geometry.LinearRing(pointGeometries)
+ ])
+ );
+
+ return new OpenLayers.Feature.Vector(
+ new geomType(pointGeometries)
+ );
+ },
+
+ /**
+ * Method: decode
+ * Deserialize an encoded string and return an array of n-dimensional
+ * points.
+ *
+ * Parameters:
+ * encoded - {String} An encoded string
+ * dims - {int} The dimension of the points that are returned
+ *
+ * Returns:
+ * {Array(Array(int))} An array containing n-dimensional arrays of
+ * coordinates.
+ */
+ decode: function(encoded, dims) {
var points = new Array();
- var point = new Array(0, 0);
+ var point = new Array(dims);
+
+ // Reset the point array
+ for (var i = 0; i < point.length; ++i)
+ point[i] = 0;
for (var i = 0; i < encoded.length;) {
- for (var dim = 0; dim < 2; ++dim) {
+ for (var dim = 0; dim < dims; ++dim) {
var result = 0;
var shift = 0;
@@ -79,20 +118,10 @@ OpenLayers.Format.EncodedPolyline = OpenLayers.Class(OpenLayers.Format, {
point[dim] += ((result & 1) ? ~(result >> 1) : (result >> 1));
}
- points.push(new OpenLayers.Geometry.Point(point[1] * 1e-5,
- point[0] * 1e-5));
+ points.push(point.slice(0));
}
- if (this.geometryType == "polygon")
- return new OpenLayers.Feature.Vector(
- new OpenLayers.Geometry.Polygon([
- new OpenLayers.Geometry.LinearRing(points)
- ])
- );
-
- return new OpenLayers.Feature.Vector(
- new geomType(points)
- );
+ return points;
},
CLASS_NAME: "OpenLayers.Format.EncodedPolyline"
diff --git a/tests/Format/EncodedPolyline.html b/tests/Format/EncodedPolyline.html
index 10f2487347..9ad7dbd726 100644
--- a/tests/Format/EncodedPolyline.html
+++ b/tests/Format/EncodedPolyline.html
@@ -3,10 +3,19 @@