EncodedPolyline: Merged duplicate code in read() method
This patch also prepares the code for making it possible to read encoded strings with multi-dimensional points.
This commit is contained in:
@@ -62,35 +62,25 @@ OpenLayers.Format.EncodedPolyline = OpenLayers.Class(OpenLayers.Format, {
|
||||
return null;
|
||||
|
||||
var points = new Array();
|
||||
|
||||
var lat = 0;
|
||||
var lon = 0;
|
||||
var point = new Array(0, 0);
|
||||
|
||||
for (var i = 0; i < encoded.length;) {
|
||||
var b;
|
||||
var result = 0;
|
||||
var shift = 0;
|
||||
for (var dim = 0; dim < 2; ++dim) {
|
||||
var result = 0;
|
||||
var shift = 0;
|
||||
|
||||
do {
|
||||
b = encoded.charCodeAt(i++) - 63;
|
||||
result |= (b & 0x1f) << shift;
|
||||
shift += 5;
|
||||
} while (b >= 0x20);
|
||||
var b;
|
||||
do {
|
||||
b = encoded.charCodeAt(i++) - 63;
|
||||
result |= (b & 0x1f) << shift;
|
||||
shift += 5;
|
||||
} while (b >= 0x20);
|
||||
|
||||
lat += ((result & 1) ? ~(result >> 1) : (result >> 1));
|
||||
point[dim] += ((result & 1) ? ~(result >> 1) : (result >> 1));
|
||||
}
|
||||
|
||||
result = 0;
|
||||
shift = 0;
|
||||
|
||||
do {
|
||||
b = encoded.charCodeAt(i++) - 63;
|
||||
result |= (b & 0x1f) << shift;
|
||||
shift += 5;
|
||||
} while (b >= 0x20);
|
||||
|
||||
lon += ((result & 1) ? ~(result >> 1) : (result >> 1));
|
||||
|
||||
points.push(new OpenLayers.Geometry.Point(lon * 1e-5, lat * 1e-5));
|
||||
points.push(new OpenLayers.Geometry.Point(point[1] * 1e-5,
|
||||
point[0] * 1e-5));
|
||||
}
|
||||
|
||||
if (this.geometryType == "polygon")
|
||||
|
||||
Reference in New Issue
Block a user