Skip to content
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

[Maps] Update Map extent queries to use bounding box logic for both point and shape queries #93156

Merged
merged 5 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ export interface ESPolygonFilter {

export function createExtentFilter(
mapExtent: MapExtent,
geoFieldName: string,
geoFieldType: ES_GEO_FIELD_TYPE
geoFieldName: string
): ESPolygonFilter | ESGeoBoundingBoxFilter;

export function makeESBbox({ maxLat, maxLon, minLat, minLon }: MapExtent): ESBBox;
Original file line number Diff line number Diff line change
Expand Up @@ -280,33 +280,16 @@ export function makeESBbox({ maxLat, maxLon, minLat, minLon }) {
return esBbox;
}

function createGeoBoundBoxFilter({ maxLat, maxLon, minLat, minLon }, geoFieldName) {
const boundingBox = makeESBbox({ maxLat, maxLon, minLat, minLon });
return {
geo_bounding_box: {
[geoFieldName]: boundingBox,
},
};
}

export function createExtentFilter(mapExtent, geoFieldName, geoFieldType) {
ensureGeoField(geoFieldType);

export function createExtentFilter(mapExtent, geoFieldName) {
// Extent filters are used to dynamically filter data for the current map view port.
kindsun marked this conversation as resolved.
Show resolved Hide resolved
// Continue to use geo_bounding_box queries for extent filters
// 1) geo_bounding_box queries are faster than polygon queries
// 2) geo_shape benefits of pre-indexed shapes and
// compatability across multi-indices with geo_point and geo_shape do not apply to this use case.
if (geoFieldType === ES_GEO_FIELD_TYPE.GEO_POINT) {
return createGeoBoundBoxFilter(mapExtent, geoFieldName);
}

// compatibility across multi-indices with geo_point and geo_shape do not apply to this use case.
const boundingBox = makeESBbox(mapExtent);
return {
geo_shape: {
[geoFieldName]: {
shape: formatEnvelopeAsPolygon(mapExtent),
relation: ES_SPATIAL_RELATIONS.INTERSECTS,
},
geo_bounding_box: {
[geoFieldName]: boundingBox,
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ describe('createExtentFilter', () => {
minLat: 35,
minLon: -89,
};
const filter = createExtentFilter(mapExtent, geoFieldName, 'geo_point');
const filter = createExtentFilter(mapExtent, geoFieldName);
kindsun marked this conversation as resolved.
Show resolved Hide resolved
expect(filter).toEqual({
geo_bounding_box: {
location: {
Expand All @@ -415,7 +415,7 @@ describe('createExtentFilter', () => {
minLat: -100,
minLon: -190,
};
const filter = createExtentFilter(mapExtent, geoFieldName, 'geo_point');
const filter = createExtentFilter(mapExtent, geoFieldName);
expect(filter).toEqual({
geo_bounding_box: {
location: {
Expand All @@ -433,7 +433,7 @@ describe('createExtentFilter', () => {
minLat: 35,
minLon: 100,
};
const filter = createExtentFilter(mapExtent, geoFieldName, 'geo_point');
const filter = createExtentFilter(mapExtent, geoFieldName);
const leftLon = filter.geo_bounding_box.location.top_left[0];
const rightLon = filter.geo_bounding_box.location.bottom_right[0];
expect(leftLon).toBeGreaterThan(rightLon);
Expand All @@ -454,7 +454,7 @@ describe('createExtentFilter', () => {
minLat: 35,
minLon: -200,
};
const filter = createExtentFilter(mapExtent, geoFieldName, 'geo_point');
const filter = createExtentFilter(mapExtent, geoFieldName);
const leftLon = filter.geo_bounding_box.location.top_left[0];
const rightLon = filter.geo_bounding_box.location.bottom_right[0];
expect(leftLon).toBeGreaterThan(rightLon);
Expand All @@ -477,52 +477,30 @@ describe('createExtentFilter', () => {
minLat: 35,
minLon: -89,
};
const filter = createExtentFilter(mapExtent, geoFieldName, 'geo_shape');
const filter = createExtentFilter(mapExtent, geoFieldName);
kindsun marked this conversation as resolved.
Show resolved Hide resolved
expect(filter).toEqual({
geo_shape: {
geo_bounding_box: {
location: {
relation: 'INTERSECTS',
shape: {
coordinates: [
[
[-89, 39],
[-89, 35],
[-83, 35],
[-83, 39],
[-89, 39],
],
],
type: 'Polygon',
},
top_left: [-89, 39],
bottom_right: [-83, 35],
},
},
});
});

it('should clamp longitudes to -180 to 180 when lonitude wraps globe', () => {
it('should clamp longitudes to -180 to 180 when longitude wraps globe', () => {
const mapExtent = {
maxLat: 39,
maxLon: 209,
minLat: 35,
minLon: -191,
};
const filter = createExtentFilter(mapExtent, geoFieldName, 'geo_shape');
const filter = createExtentFilter(mapExtent, geoFieldName);
expect(filter).toEqual({
geo_shape: {
geo_bounding_box: {
location: {
relation: 'INTERSECTS',
shape: {
coordinates: [
[
[-180, 39],
[-180, 35],
[180, 35],
[180, 39],
[-180, 39],
],
],
type: 'Polygon',
},
top_left: [-180, 39],
bottom_right: [180, 35],
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,7 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource
typeof searchFilters.geogridPrecision === 'number'
? expandToTileBoundaries(searchFilters.buffer, searchFilters.geogridPrecision)
: searchFilters.buffer;
const extentFilter = createExtentFilter(
buffer,
geoField.name,
geoField.type as ES_GEO_FIELD_TYPE
);
const extentFilter = createExtentFilter(buffer, geoField.name);

// @ts-expect-error
allFilters.push(extentFilter);
Expand Down