Added basic ol.parser.polyline module

This module will contain the low-level functions for Google's "Encoded
Polyline" algorithm.
This commit is contained in:
Tobias Bieniek
2013-03-09 21:57:35 +01:00
parent a138b5a5a3
commit 36923d6688
2 changed files with 76 additions and 0 deletions

35
src/ol/parser/polyline.js Normal file
View File

@@ -0,0 +1,35 @@
goog.provide('ol.parser.polyline');
/**
* Encode one single signed integer and return an encoded string
*
* @param {number} num Signed integer that should be encoded.
* @return {string} The encoded string.
*/
ol.parser.polyline.encodeSignedInteger = function(num) {
var sgn_num = num << 1;
if (num < 0)
sgn_num = ~(sgn_num);
return ol.parser.polyline.encodeUnsignedInteger(sgn_num);
};
/**
* Encode one single unsigned integer and return an encoded string
*
* @param {number} num Unsigned integer that should be encoded.
* @return {string} The encoded string.
*/
ol.parser.polyline.encodeUnsignedInteger = function(num) {
var value, encodeString = '';
while (num >= 0x20) {
value = (0x20 | (num & 0x1f)) + 63;
encodeString += (String.fromCharCode(value));
num >>= 5;
}
value = num + 63;
encodeString += (String.fromCharCode(value));
return encodeString;
};