-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
fixing maps #56706
fixing maps #56706
Changes from 5 commits
dcaa1e4
75731fc
5e7d1bd
55ac9d7
e454d09
4a0d77b
b0934e0
09fd301
06becac
d7641d5
a351ad7
8aad5c8
14e2761
a1595c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,69 +18,22 @@ | |
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { geohashColumns } from 'ui/vis/map/decode_geo_hash'; | ||
import chrome from 'ui/chrome'; | ||
import { BucketAggType, IBucketAggConfig } from './_bucket_agg_type'; | ||
import { KBN_FIELD_TYPES } from '../../../../../../../plugins/data/public'; | ||
|
||
import { geoContains, scaleBounds, GeoBoundingBox } from './lib/geo_utils'; | ||
import { BUCKET_TYPES } from './bucket_agg_types'; | ||
import { AggGroupNames } from '../agg_groups'; | ||
|
||
const config = chrome.getUiSettingsClient(); | ||
const defaultBoundingBox = { | ||
top_left: { lat: 1, lon: 1 }, | ||
bottom_right: { lat: 0, lon: 0 }, | ||
}; | ||
|
||
const defaultPrecision = 2; | ||
const maxPrecision = parseInt(config.get('visualization:tileMap:maxPrecision'), 10) || 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. | ||
*/ | ||
const zoomPrecision: any = {}; | ||
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 <= maxPrecision; precision += 1) { | ||
const columns = geohashColumns(precision); | ||
if (worldPixels / columns >= minGeohashPixels) { | ||
zoomPrecision[zoom] = precision; | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
function getPrecision(val: string) { | ||
let precision = parseInt(val, 10); | ||
|
||
if (Number.isNaN(precision)) { | ||
precision = defaultPrecision; | ||
} | ||
|
||
if (precision > maxPrecision) { | ||
return maxPrecision; | ||
} | ||
|
||
return precision; | ||
} | ||
|
||
const isOutsideCollar = (bounds: GeoBoundingBox, collar: MapCollar) => | ||
bounds && collar && !geoContains(collar, bounds); | ||
|
||
const geohashGridTitle = i18n.translate('data.search.aggs.buckets.geohashGridTitle', { | ||
defaultMessage: 'Geohash', | ||
}); | ||
|
||
interface MapCollar extends GeoBoundingBox { | ||
zoom?: unknown; | ||
} | ||
|
||
export interface IBucketGeoHashGridAggConfig extends IBucketAggConfig { | ||
lastMapCollar: MapCollar; | ||
} | ||
|
||
export const geoHashBucketAgg = new BucketAggType<IBucketGeoHashGridAggConfig>({ | ||
export const geoHashBucketAgg = new BucketAggType<IBucketAggConfig>({ | ||
name: BUCKET_TYPES.GEOHASH_GRID, | ||
title: geohashGridTitle, | ||
params: [ | ||
|
@@ -97,13 +50,8 @@ export const geoHashBucketAgg = new BucketAggType<IBucketGeoHashGridAggConfig>({ | |
{ | ||
name: 'precision', | ||
default: defaultPrecision, | ||
deserialize: getPrecision, | ||
write(aggConfig, output) { | ||
const currZoom = aggConfig.params.mapZoom; | ||
const autoPrecisionVal = zoomPrecision[currZoom]; | ||
output.params.precision = aggConfig.params.autoPrecision | ||
? autoPrecisionVal | ||
: getPrecision(aggConfig.params.precision); | ||
output.params.precision = aggConfig.params.precision; | ||
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. correct precision is calculated in tile_map_vis |
||
}, | ||
}, | ||
{ | ||
|
@@ -117,17 +65,7 @@ export const geoHashBucketAgg = new BucketAggType<IBucketGeoHashGridAggConfig>({ | |
write: () => {}, | ||
}, | ||
{ | ||
name: '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. mapZoom and mapCenter are no longer stored on the agg config |
||
default: 2, | ||
write: () => {}, | ||
}, | ||
{ | ||
name: 'mapCenter', | ||
default: [0, 0], | ||
write: () => {}, | ||
}, | ||
{ | ||
name: 'mapBounds', | ||
name: 'boundingBox', | ||
default: null, | ||
write: () => {}, | ||
}, | ||
|
@@ -137,46 +75,22 @@ export const geoHashBucketAgg = new BucketAggType<IBucketGeoHashGridAggConfig>({ | |
const params = agg.params; | ||
|
||
if (params.isFilteredByCollar && agg.getField()) { | ||
const { mapBounds, mapZoom } = params; | ||
if (mapBounds) { | ||
let mapCollar: MapCollar; | ||
|
||
if ( | ||
mapBounds && | ||
(!agg.lastMapCollar || | ||
agg.lastMapCollar.zoom !== mapZoom || | ||
isOutsideCollar(mapBounds, agg.lastMapCollar)) | ||
) { | ||
mapCollar = scaleBounds(mapBounds); | ||
mapCollar.zoom = mapZoom; | ||
agg.lastMapCollar = mapCollar; | ||
} else { | ||
mapCollar = agg.lastMapCollar; | ||
} | ||
const boundingBox = { | ||
ignore_unmapped: true, | ||
[agg.getField().name]: { | ||
top_left: mapCollar.top_left, | ||
bottom_right: mapCollar.bottom_right, | ||
}, | ||
}; | ||
aggs.push( | ||
agg.aggConfigs.createAggConfig( | ||
{ | ||
type: 'filter', | ||
id: 'filter_agg', | ||
enabled: true, | ||
params: { | ||
geo_bounding_box: boundingBox, | ||
}, | ||
schema: { | ||
group: AggGroupNames.Buckets, | ||
aggs.push( | ||
agg.aggConfigs.createAggConfig( | ||
{ | ||
type: 'filter', | ||
id: 'filter_agg', | ||
enabled: true, | ||
params: { | ||
geo_bounding_box: { | ||
ignore_unmapped: true, | ||
[agg.getField().name]: params.boundingBox || defaultBoundingBox, | ||
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. if bounding box is not set we use default (which should exclude all data) |
||
}, | ||
} as any, | ||
{ addToAggConfigs: false } | ||
) | ||
); | ||
} | ||
}, | ||
} as any, | ||
{ addToAggConfigs: false } | ||
) | ||
); | ||
} | ||
|
||
aggs.push(agg); | ||
|
@@ -196,6 +110,6 @@ export const geoHashBucketAgg = new BucketAggType<IBucketGeoHashGridAggConfig>({ | |
); | ||
} | ||
|
||
return aggs as IBucketGeoHashGridAggConfig[]; | ||
return aggs; | ||
}, | ||
}); |
This file was deleted.
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.
all this logic was moved inside tile_map_vis (it needs to set correct precision based on zoom level)