Skip to content

Commit

Permalink
Ensure precision does not exceed maxPrecision
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Aug 15, 2016
1 parent 273b228 commit 75c347b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
20 changes: 12 additions & 8 deletions src/ui/public/agg_types/__tests__/buckets/_geo_hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ describe('Geohash Agg', function () {
return function BucketMock(geohashProvider) {
return geohashProvider.params[4];
};
}, {});
}, {
get: function () {
return 7;//"visualization:tileMap:maxPrecision"
}
});

describe('interval', function () {
describe('geohash', function () {

const zoomToGeoHashPrecision = {
0: 1,
Expand All @@ -31,12 +35,12 @@ describe('Geohash Agg', function () {
13: 6,
14: 7,
15: 7,
16: 8,
17: 8,
18: 8,
19: 9,
20: 9,
21: 10
16: 7,
17: 7,
18: 7,
19: 7,
20: 7,
21: 7
};

Object.keys(zoomToGeoHashPrecision).forEach((zoomLevel) => {
Expand Down
7 changes: 4 additions & 3 deletions src/ui/public/agg_types/buckets/geo_hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ export default function GeoHashAggDefinition(Private, config) {
* The size of a geohash column-width on the map should be at least `minGeohashPixels` pixels wide.
*/
let zoomPrecision = {};
const maxPrecision = _.parseInt(config.get('visualization:tileMap:maxPrecision')) || 12;
const minGeohashPixels = 16;
for (let zoom = 0; zoom <= 21; zoom += 1) {
const worldPixels = 256 * Math.pow(2, zoom);
zoomPrecision[zoom] = 1;
for (let precision = 2; precision <= 12; precision += 1) {
const columns = geohashColumns(precision, 0);
if (worldPixels / columns >= minGeohashPixels) {
for (let precision = 2; precision <= maxPrecision; precision += 1) {
const columns = geohashColumns(precision);
if ((worldPixels / columns) >= minGeohashPixels) {
zoomPrecision[zoom] = precision;
} else {
break;
Expand Down

0 comments on commit 75c347b

Please sign in to comment.