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:
35
src/ol/parser/polyline.js
Normal file
35
src/ol/parser/polyline.js
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user