-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change mapping from zoom levels to geohash precision #8000
Merged
thomasneirynck
merged 3 commits into
elastic:master
from
thomasneirynck:fix/7882_zoom_precision
Aug 17, 2016
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import expect from 'expect.js'; | ||
import AggTypesBucketsGeoHashProvider from 'ui/agg_types/buckets/geo_hash'; | ||
|
||
describe('Geohash Agg', function () { | ||
|
||
|
||
describe('write', function () { | ||
|
||
let paramWriter = new AggTypesBucketsGeoHashProvider(function PrivateMock() { | ||
return function BucketMock(geohashProvider) { | ||
return geohashProvider.params[4]; | ||
}; | ||
}, {}); | ||
|
||
describe('interval', function () { | ||
|
||
const zoomToGeoHashPrecision = { | ||
0: 1, | ||
1: 2, | ||
2: 2, | ||
3: 2, | ||
4: 3, | ||
5: 3, | ||
6: 4, | ||
7: 4, | ||
8: 4, | ||
9: 5, | ||
10: 5, | ||
11: 6, | ||
12: 6, | ||
13: 6, | ||
14: 7, | ||
15: 7, | ||
16: 8, | ||
17: 8, | ||
18: 8, | ||
19: 9, | ||
20: 9, | ||
21: 10 | ||
}; | ||
|
||
Object.keys(zoomToGeoHashPrecision).forEach((zoomLevel) => { | ||
it(`zoom level ${zoomLevel} should correspond to correct geohash-precision`, () => { | ||
const output = {params: {}}; | ||
paramWriter.write({ | ||
vis: { | ||
hasUiState: () => true, | ||
uiStateVal: () => zoomLevel | ||
}, | ||
params: { | ||
autoPrecision: true | ||
} | ||
}, output); | ||
expect(output.params.precision).to.equal(zoomToGeoHashPrecision[zoomLevel]); | ||
}); | ||
}); | ||
}); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,30 @@ | ||
import _ from 'lodash'; | ||
import moment from 'moment'; | ||
import AggTypesBucketsBucketAggTypeProvider from 'ui/agg_types/buckets/_bucket_agg_type'; | ||
import precisionTemplate from 'ui/agg_types/controls/precision.html'; | ||
import {geohashColumns} from 'ui/utils/decode_geo_hash'; | ||
|
||
export default function GeoHashAggDefinition(Private, config) { | ||
let BucketAggType = Private(AggTypesBucketsBucketAggTypeProvider); | ||
let defaultPrecision = 2; | ||
|
||
// zoomPrecision maps event.zoom to a geohash precision value | ||
// event.limit is the configurable max geohash precision | ||
// default max precision is 7, configurable up to 12 | ||
const zoomPrecision = { | ||
1: 2, | ||
2: 2, | ||
3: 2, | ||
4: 3, | ||
5: 3, | ||
6: 4, | ||
7: 4, | ||
8: 5, | ||
9: 5, | ||
10: 6, | ||
11: 6, | ||
12: 7, | ||
13: 7, | ||
14: 8, | ||
15: 9, | ||
16: 10, | ||
17: 11, | ||
18: 12 | ||
}; | ||
/** | ||
* Map Leaflet zoom levels to geohash precision levels. | ||
* The size of a geohash column-width on the map should be at least `minGeohashPixels` pixels wide. | ||
*/ | ||
let zoomPrecision = {}; | ||
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) { | ||
zoomPrecision[zoom] = precision; | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
function getPrecision(precision) { | ||
let maxPrecision = _.parseInt(config.get('visualization:tileMap:maxPrecision')); | ||
|
@@ -75,8 +71,11 @@ export default function GeoHashAggDefinition(Private, config) { | |
}, | ||
write: function (aggConfig, output) { | ||
const vis = aggConfig.vis; | ||
const currZoom = vis.hasUiState() && vis.uiStateVal('mapZoom'); | ||
const autoPrecisionVal = zoomPrecision[(currZoom || vis.params.mapZoom)]; | ||
let currZoom; | ||
if (vis.hasUiState()) { | ||
currZoom = parseInt(vis.uiStateVal('mapZoom')); | ||
} | ||
const autoPrecisionVal = zoomPrecision[currZoom >= 0 ? currZoom : parseInt(vis.params.mapZoom)]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should give |
||
output.params.precision = aggConfig.params.autoPrecision ? autoPrecisionVal : getPrecision(aggConfig.params.precision); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import expect from 'expect.js'; | ||
import {geohashColumns} from 'ui/utils/decode_geo_hash'; | ||
|
||
describe('decode_geo_hash', function () { | ||
it('geohashColumns', function () { | ||
expect(geohashColumns(1)).to.equal(8); | ||
expect(geohashColumns(2)).to.equal(8 * 4); | ||
expect(geohashColumns(3)).to.equal(8 * 4 * 8); | ||
expect(geohashColumns(4)).to.equal(8 * 4 * 8 * 4); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it make sense to use config.get('visualization:tileMap:maxPrecision') here instead of 12?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, it does. I missed that setting, thx!