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;
|
return null;
|
||||||
|
|
||||||
var points = new Array();
|
var points = new Array();
|
||||||
|
var point = new Array(0, 0);
|
||||||
var lat = 0;
|
|
||||||
var lon = 0;
|
|
||||||
|
|
||||||
for (var i = 0; i < encoded.length;) {
|
for (var i = 0; i < encoded.length;) {
|
||||||
var b;
|
for (var dim = 0; dim < 2; ++dim) {
|
||||||
var result = 0;
|
var result = 0;
|
||||||
var shift = 0;
|
var shift = 0;
|
||||||
|
|
||||||
do {
|
var b;
|
||||||
b = encoded.charCodeAt(i++) - 63;
|
do {
|
||||||
result |= (b & 0x1f) << shift;
|
b = encoded.charCodeAt(i++) - 63;
|
||||||
shift += 5;
|
result |= (b & 0x1f) << shift;
|
||||||
} while (b >= 0x20);
|
shift += 5;
|
||||||
|
} while (b >= 0x20);
|
||||||
|
|
||||||
lat += ((result & 1) ? ~(result >> 1) : (result >> 1));
|
point[dim] += ((result & 1) ? ~(result >> 1) : (result >> 1));
|
||||||
|
}
|
||||||
|
|
||||||
result = 0;
|
points.push(new OpenLayers.Geometry.Point(point[1] * 1e-5,
|
||||||
shift = 0;
|
point[0] * 1e-5));
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.geometryType == "polygon")
|
if (this.geometryType == "polygon")
|
||||||
|
|||||||
Reference in New Issue
Block a user