polyline: Added encode/decodeFloat() functions

This commit is contained in:
Tobias Bieniek
2013-03-09 23:17:29 +01:00
parent e802cc3d56
commit 04d764f4f3
2 changed files with 67 additions and 0 deletions

View File

@@ -1,6 +1,33 @@
goog.provide('ol.parser.polyline');
/**
* Encode one single floating point number and return an encoded string
*
* @param {number} num Floating point number that should be encoded.
* @param {number=} opt_factor The factor by which num will be multiplied.
* The remaining decimal places will get rounded away.
* @return {string} The encoded string.
*/
ol.parser.polyline.encodeFloat = function(num, opt_factor) {
num = Math.round(num * (opt_factor || 1e5));
return ol.parser.polyline.encodeSignedInteger(num);
};
/**
* Decode one single floating point number from an encoded string
*
* @param {string} encoded An encoded string.
* @param {number=} opt_factor The factor by which the result will be divided.
* @return {number} The decoded floating point number.
*/
ol.parser.polyline.decodeFloat = function(encoded, opt_factor) {
var result = ol.parser.polyline.decodeSignedInteger(encoded);
return result / (opt_factor || 1e5);
};
/**
* Encode one single signed integer and return an encoded string
*