Skip to content

Commit dd93ea5

Browse files
Merge branch '7.x' into backport/7.x/pr-54408
2 parents aff708f + 7556436 commit dd93ea5

8 files changed

Lines changed: 73 additions & 22 deletions

File tree

x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/geo_tile_utils.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ const ZOOM_TILE_KEY_INDEX = 0;
1111
const X_TILE_KEY_INDEX = 1;
1212
const Y_TILE_KEY_INDEX = 2;
1313

14+
function getTileCount(zoom) {
15+
return Math.pow(2, zoom);
16+
}
17+
1418
export function parseTileKey(tileKey) {
1519
const tileKeyParts = tileKey.split('/');
1620

@@ -21,7 +25,7 @@ export function parseTileKey(tileKey) {
2125
const zoom = parseInt(tileKeyParts[ZOOM_TILE_KEY_INDEX], 10);
2226
const x = parseInt(tileKeyParts[X_TILE_KEY_INDEX], 10);
2327
const y = parseInt(tileKeyParts[Y_TILE_KEY_INDEX], 10);
24-
const tileCount = Math.pow(2, zoom);
28+
const tileCount = getTileCount(zoom);
2529

2630
if (x >= tileCount) {
2731
throw new Error(
@@ -77,3 +81,34 @@ export function getTileBoundingBox(tileKey) {
7781
right: tileToLongitude(x + 1, tileCount),
7882
};
7983
}
84+
85+
function sec(value) {
86+
return 1 / Math.cos(value);
87+
}
88+
89+
function latitudeToTile(lat, tileCount) {
90+
const radians = (lat * Math.PI) / 180;
91+
const y = ((1 - Math.log(Math.tan(radians) + sec(radians)) / Math.PI) / 2) * tileCount;
92+
return Math.floor(y);
93+
}
94+
95+
function longitudeToTile(lon, tileCount) {
96+
const x = ((lon + 180) / 360) * tileCount;
97+
return Math.floor(x);
98+
}
99+
100+
export function expandToTileBoundaries(extent, zoom) {
101+
const tileCount = getTileCount(zoom);
102+
103+
const upperLeftX = longitudeToTile(extent.minLon, tileCount);
104+
const upperLeftY = latitudeToTile(Math.min(extent.maxLat, 90), tileCount);
105+
const lowerRightX = longitudeToTile(extent.maxLon, tileCount);
106+
const lowerRightY = latitudeToTile(Math.max(extent.minLat, -90), tileCount);
107+
108+
return {
109+
minLon: tileToLongitude(upperLeftX, tileCount),
110+
minLat: tileToLatitude(lowerRightY + 1, tileCount),
111+
maxLon: tileToLongitude(lowerRightX + 1, tileCount),
112+
maxLat: tileToLatitude(upperLeftY, tileCount),
113+
};
114+
}

x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/geo_tile_utils.test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { parseTileKey, getTileBoundingBox } from './geo_tile_utils';
7+
import { parseTileKey, getTileBoundingBox, expandToTileBoundaries } from './geo_tile_utils';
88

99
it('Should parse tile key', () => {
1010
expect(parseTileKey('15/23423/1867')).toEqual({
@@ -34,3 +34,19 @@ it('Should convert tile key to geojson Polygon with extra precision', () => {
3434
left: -73.9839292,
3535
});
3636
});
37+
38+
it('Should expand extent to align boundaries with tile boundaries', () => {
39+
const extent = {
40+
maxLat: 12.5,
41+
maxLon: 102.5,
42+
minLat: 2.5,
43+
minLon: 92.5,
44+
};
45+
const tileAlignedExtent = expandToTileBoundaries(extent, 7);
46+
expect(tileAlignedExtent).toEqual({
47+
maxLat: 13.9234,
48+
maxLon: 104.0625,
49+
minLat: 0,
50+
minLon: 90,
51+
});
52+
});

x-pack/legacy/plugins/maps/public/layers/sources/es_source.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import uuid from 'uuid/v4';
1919
import { copyPersistentState } from '../../reducers/util';
2020
import { ES_GEO_FIELD_TYPE, METRIC_TYPE } from '../../../common/constants';
2121
import { DataRequestAbortError } from '../util/data_request';
22+
import { expandToTileBoundaries } from './es_geo_grid_source/geo_tile_utils';
2223

2324
export class AbstractESSource extends AbstractVectorSource {
2425
static icon = 'logoElasticsearch';
@@ -117,7 +118,10 @@ export class AbstractESSource extends AbstractVectorSource {
117118
if (this.isFilterByMapBounds() && searchFilters.buffer) {
118119
//buffer can be empty
119120
const geoField = await this._getGeoField();
120-
allFilters.push(createExtentFilter(searchFilters.buffer, geoField.name, geoField.type));
121+
const buffer = this.isGeoGridPrecisionAware()
122+
? expandToTileBoundaries(searchFilters.buffer, searchFilters.geogridPrecision)
123+
: searchFilters.buffer;
124+
allFilters.push(createExtentFilter(buffer, geoField.name, geoField.type));
121125
}
122126
if (isTimeAware) {
123127
allFilters.push(timefilter.createFilter(indexPattern, searchFilters.timeFilters));

x-pack/legacy/plugins/uptime/public/components/functional/location_map/__tests__/__snapshots__/location_status_tags.test.tsx.snap

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/legacy/plugins/uptime/public/components/functional/location_map/__tests__/location_status_tags.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { MonitorLocation } from '../../../../../common/runtime_types/monitor';
1111
import { LocationStatusTags } from '../';
1212

1313
// Failing: https://github.com/elastic/kibana/issues/54818
14-
describe.skip('LocationStatusTags component', () => {
14+
describe('LocationStatusTags component', () => {
1515
let monitorLocations: MonitorLocation[];
1616

1717
it('renders when there are many location', () => {

x-pack/legacy/plugins/uptime/public/components/functional/location_map/location_status_tags.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ export const LocationStatusTags = ({ locations }: Props) => {
6060
}
6161
});
6262

63-
// Sort by recent timestamp
63+
// Sort lexicographically by label
6464
upLocations.sort((a, b) => {
65-
return a.timestamp < b.timestamp ? 1 : b.timestamp < a.timestamp ? -1 : 0;
65+
return a.label > b.label ? 1 : b.label > a.label ? -1 : 0;
6666
});
6767

6868
moment.locale('en', {

x-pack/legacy/plugins/uptime/public/components/functional/ping_list/__tests__/__snapshots__/ping_list.test.tsx.snap

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/test/functional/page_objects/gis_page.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,16 @@ export function GisPageProvider({ getService, getPageObjects }) {
213213
return links.length;
214214
}
215215

216+
async isSetViewPopoverOpen() {
217+
return await testSubjects.exists('mapSetViewForm', { timeout: 500 });
218+
}
219+
216220
async openSetViewPopover() {
217-
const isOpen = await testSubjects.exists('mapSetViewForm');
221+
const isOpen = await this.isSetViewPopoverOpen();
218222
if (!isOpen) {
219223
await retry.try(async () => {
220224
await testSubjects.click('toggleSetViewVisibilityButton');
221-
const isOpenAfterClick = await testSubjects.exists('mapSetViewForm');
225+
const isOpenAfterClick = await this.isSetViewPopoverOpen();
222226
if (!isOpenAfterClick) {
223227
throw new Error('set view popover not opened');
224228
}
@@ -227,11 +231,11 @@ export function GisPageProvider({ getService, getPageObjects }) {
227231
}
228232

229233
async closeSetViewPopover() {
230-
const isOpen = await testSubjects.exists('mapSetViewForm');
234+
const isOpen = await this.isSetViewPopoverOpen();
231235
if (isOpen) {
232236
await retry.try(async () => {
233237
await testSubjects.click('toggleSetViewVisibilityButton');
234-
const isOpenAfterClick = await testSubjects.exists('mapSetViewForm');
238+
const isOpenAfterClick = await this.isSetViewPopoverOpen();
235239
if (isOpenAfterClick) {
236240
throw new Error('set view popover not closed');
237241
}

0 commit comments

Comments
 (0)