mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[maps] replace duplicated elasticsearch geo types with types from elasticsearch-specification (#161011)
https://github.com/elastic/elasticsearch-specification/blob/main/output/typescript/types.ts defines elasticsearch API types. This PR removes types defined in maps plugins and replaces them with types from elasticsearch-specification. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
71d96c7b95
commit
b22dd68d39
18 changed files with 130 additions and 144 deletions
|
@ -115,12 +115,6 @@ export enum ES_GEO_FIELD_TYPE {
|
|||
// Using strings instead of ES_GEO_FIELD_TYPE enum to avoid typeing errors where IndexPatternField.type is compared to value
|
||||
export const ES_GEO_FIELD_TYPES = ['geo_point', 'geo_shape'];
|
||||
|
||||
export enum ES_SPATIAL_RELATIONS {
|
||||
INTERSECTS = 'INTERSECTS',
|
||||
DISJOINT = 'DISJOINT',
|
||||
WITHIN = 'WITHIN',
|
||||
}
|
||||
|
||||
export enum GEO_JSON_TYPE {
|
||||
POINT = 'Point',
|
||||
MULTI_POINT = 'MultiPoint',
|
||||
|
|
|
@ -7,10 +7,11 @@
|
|||
|
||||
/* eslint-disable @typescript-eslint/consistent-type-definitions */
|
||||
|
||||
import type { GeoShapeRelation } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { ReactNode } from 'react';
|
||||
import { GeoJsonProperties } from 'geojson';
|
||||
import { Geometry } from 'geojson';
|
||||
import { DRAW_SHAPE, ES_SPATIAL_RELATIONS } from '../constants';
|
||||
import { DRAW_SHAPE } from '../constants';
|
||||
import { CustomIcon } from './style_property_descriptor_types';
|
||||
import { INITIAL_LOCATION } from '../constants';
|
||||
|
||||
|
@ -75,7 +76,7 @@ export type DrawState = {
|
|||
drawShape?: DRAW_SHAPE;
|
||||
filterLabel?: string; // point radius filter alias
|
||||
geometryLabel?: string;
|
||||
relation?: ES_SPATIAL_RELATIONS;
|
||||
relation?: GeoShapeRelation;
|
||||
};
|
||||
|
||||
export type EditState = {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import _ from 'lodash';
|
||||
import type { TopLeftBottomRightGeoBounds } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { Feature, FeatureCollection, Geometry, Polygon, Point, Position } from 'geojson';
|
||||
import { BBox } from '@turf/helpers';
|
||||
|
@ -18,7 +19,16 @@ import {
|
|||
LAT_INDEX,
|
||||
} from '../constants';
|
||||
import { MapExtent } from '../descriptor_types';
|
||||
import { Coordinates, ESBBox, ESGeometry } from './types';
|
||||
|
||||
type Coordinates = Position | Position[] | Position[][] | Position[][][];
|
||||
|
||||
// Elasticsearch stores more then just standarized GeoJSON.
|
||||
// 1) geometry.type as lower case string
|
||||
// 2) circle and envelope types
|
||||
interface ESGeometry {
|
||||
type: string;
|
||||
coordinates: Coordinates;
|
||||
}
|
||||
|
||||
function ensureGeoField(type: string) {
|
||||
const expectedTypes = [ES_GEO_FIELD_TYPE.GEO_POINT, ES_GEO_FIELD_TYPE.GEO_SHAPE];
|
||||
|
@ -199,7 +209,12 @@ export function geoShapeToGeometry(
|
|||
}
|
||||
}
|
||||
|
||||
export function makeESBbox({ maxLat, maxLon, minLat, minLon }: MapExtent): ESBBox {
|
||||
export function makeESBbox({
|
||||
maxLat,
|
||||
maxLon,
|
||||
minLat,
|
||||
minLon,
|
||||
}: MapExtent): TopLeftBottomRightGeoBounds {
|
||||
const bottom = clampToLatBounds(minLat);
|
||||
const top = clampToLatBounds(maxLat);
|
||||
let esBbox;
|
||||
|
|
|
@ -8,6 +8,5 @@
|
|||
export * from './es_agg_utils';
|
||||
export * from './elasticsearch_geo_utils';
|
||||
export * from './spatial_filter_utils';
|
||||
export * from './types';
|
||||
export type { TotalHits } from './total_hits';
|
||||
export { isTotalHitsGreaterThan } from './total_hits';
|
||||
|
|
|
@ -425,7 +425,7 @@ describe('buildGeoShapeFilter', () => {
|
|||
{
|
||||
geo_shape: {
|
||||
'geo.coordinates': {
|
||||
relation: 'INTERSECTS',
|
||||
relation: 'intersects',
|
||||
shape: {
|
||||
coordinates: [
|
||||
[
|
||||
|
@ -487,7 +487,7 @@ describe('buildGeoShapeFilter', () => {
|
|||
{
|
||||
geo_shape: {
|
||||
'geo.coordinates': {
|
||||
relation: 'INTERSECTS',
|
||||
relation: 'intersects',
|
||||
shape: {
|
||||
coordinates: [
|
||||
[
|
||||
|
@ -518,7 +518,7 @@ describe('buildGeoShapeFilter', () => {
|
|||
{
|
||||
geo_shape: {
|
||||
location: {
|
||||
relation: 'INTERSECTS',
|
||||
relation: 'intersects',
|
||||
shape: {
|
||||
coordinates: [
|
||||
[
|
||||
|
|
|
@ -5,19 +5,37 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type {
|
||||
GeoShapeRelation,
|
||||
QueryDslFieldLookup,
|
||||
QueryDslGeoBoundingBoxQuery,
|
||||
QueryDslGeoDistanceQuery,
|
||||
QueryDslGeoShapeFieldQuery,
|
||||
QueryDslGeoShapeQuery,
|
||||
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { Feature, Geometry, MultiPolygon, Polygon, Position } from 'geojson';
|
||||
// @ts-expect-error
|
||||
import turfCircle from '@turf/circle';
|
||||
import { FilterMeta, FILTERS } from '@kbn/es-query';
|
||||
import { Filter, FilterMeta, FILTERS } from '@kbn/es-query';
|
||||
import { MapExtent } from '../descriptor_types';
|
||||
import { ES_SPATIAL_RELATIONS } from '../constants';
|
||||
import { getEsSpatialRelationLabel } from '../i18n_getters';
|
||||
import { GeoFilter, GeoShapeQueryBody, PreIndexedShape } from './types';
|
||||
import { makeESBbox } from './elasticsearch_geo_utils';
|
||||
|
||||
const SPATIAL_FILTER_TYPE = FILTERS.SPATIAL_FILTER;
|
||||
|
||||
type GeoFilter = Filter & {
|
||||
geo_bounding_box?: QueryDslGeoBoundingBoxQuery;
|
||||
geo_distance?: QueryDslGeoDistanceQuery;
|
||||
geo_grid?: {
|
||||
[geoFieldName: string]: {
|
||||
geohex?: string;
|
||||
geotile?: string;
|
||||
};
|
||||
};
|
||||
geo_shape?: QueryDslGeoShapeQuery;
|
||||
};
|
||||
|
||||
// wrapper around boiler plate code for creating bool.should clause with nested bool.must clauses
|
||||
// ensuring geoField exists prior to running geoField query
|
||||
// This allows for writing a single geo filter that spans multiple indices with different geo fields.
|
||||
|
@ -102,13 +120,13 @@ export function buildGeoShapeFilter({
|
|||
geometry,
|
||||
geometryLabel,
|
||||
geoFieldNames,
|
||||
relation = ES_SPATIAL_RELATIONS.INTERSECTS,
|
||||
relation = 'intersects',
|
||||
}: {
|
||||
preIndexedShape?: PreIndexedShape | null;
|
||||
preIndexedShape?: QueryDslFieldLookup | null;
|
||||
geometry?: MultiPolygon | Polygon;
|
||||
geometryLabel: string;
|
||||
geoFieldNames: string[];
|
||||
relation?: ES_SPATIAL_RELATIONS;
|
||||
relation?: GeoShapeRelation;
|
||||
}): GeoFilter {
|
||||
const meta: FilterMeta = {
|
||||
type: SPATIAL_FILTER_TYPE,
|
||||
|
@ -118,7 +136,7 @@ export function buildGeoShapeFilter({
|
|||
};
|
||||
|
||||
function createGeoFilter(geoFieldName: string) {
|
||||
const shapeQuery: GeoShapeQueryBody = {
|
||||
const shapeQuery: QueryDslGeoShapeFieldQuery = {
|
||||
relation,
|
||||
};
|
||||
if (preIndexedShape) {
|
||||
|
@ -137,9 +155,6 @@ export function buildGeoShapeFilter({
|
|||
};
|
||||
}
|
||||
|
||||
// Currently no way to create an object with exclude property from index signature
|
||||
// typescript error for "ignore_unmapped is not assignable to type 'GeoShapeQueryBody'" expected"
|
||||
// @ts-expect-error
|
||||
return createMultiGeoFieldFilter(geoFieldNames, meta, createGeoFilter);
|
||||
}
|
||||
|
||||
|
@ -214,14 +229,19 @@ export function createDistanceFilterWithMeta({
|
|||
|
||||
function extractGeometryFromFilter(geoFieldName: string, filter: GeoFilter): Geometry | undefined {
|
||||
if (filter.geo_distance && filter.geo_distance[geoFieldName]) {
|
||||
// @ts-expect-error QueryDslGeoDistanceQuery incorrectly types distance as optional
|
||||
const distanceSplit = filter.geo_distance.distance.split('km');
|
||||
const distance = parseFloat(distanceSplit[0]);
|
||||
const circleFeature = turfCircle(filter.geo_distance[geoFieldName], distance);
|
||||
return circleFeature.geometry;
|
||||
}
|
||||
|
||||
if (filter.geo_shape && filter.geo_shape[geoFieldName] && filter.geo_shape[geoFieldName].shape) {
|
||||
return filter.geo_shape[geoFieldName].shape;
|
||||
if (
|
||||
filter.geo_shape &&
|
||||
filter.geo_shape[geoFieldName] &&
|
||||
(filter.geo_shape[geoFieldName] as QueryDslGeoShapeFieldQuery).shape
|
||||
) {
|
||||
return (filter.geo_shape[geoFieldName] as QueryDslGeoShapeFieldQuery).shape;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MultiPolygon, Polygon, Position } from 'geojson';
|
||||
import type { Filter } from '@kbn/es-query';
|
||||
import { ES_SPATIAL_RELATIONS } from '../constants';
|
||||
|
||||
export type Coordinates = Position | Position[] | Position[][] | Position[][][];
|
||||
|
||||
// Elasticsearch stores more then just GeoJSON.
|
||||
// 1) geometry.type as lower case string
|
||||
// 2) circle and envelope types
|
||||
export interface ESGeometry {
|
||||
type: string;
|
||||
coordinates: Coordinates;
|
||||
}
|
||||
|
||||
export interface ESBBox {
|
||||
top_left: number[];
|
||||
bottom_right: number[];
|
||||
}
|
||||
|
||||
export interface GeoShapeQueryBody {
|
||||
shape?: MultiPolygon | Polygon;
|
||||
relation?: ES_SPATIAL_RELATIONS;
|
||||
indexed_shape?: PreIndexedShape;
|
||||
}
|
||||
|
||||
// Index signature explicitly states that anything stored in an object using a string conforms to the structure
|
||||
// problem is that Elasticsearch signature also allows for other string keys to conform to other structures, like 'ignore_unmapped'
|
||||
// Use intersection type to exclude certain properties from the index signature
|
||||
// https://basarat.gitbook.io/typescript/type-system/index-signatures#excluding-certain-properties-from-the-index-signature
|
||||
type GeoShapeQuery = { ignore_unmapped: boolean } & { [geoFieldName: string]: GeoShapeQueryBody };
|
||||
|
||||
export type GeoFilter = Filter & {
|
||||
geo_bounding_box?: {
|
||||
[geoFieldName: string]: ESBBox;
|
||||
};
|
||||
geo_distance?: {
|
||||
distance: string;
|
||||
[geoFieldName: string]: Position | { lat: number; lon: number } | string;
|
||||
};
|
||||
geo_grid?: {
|
||||
[geoFieldName: string]: {
|
||||
geohex?: string;
|
||||
geotile?: string;
|
||||
};
|
||||
};
|
||||
geo_shape?: GeoShapeQuery;
|
||||
};
|
||||
|
||||
export interface PreIndexedShape {
|
||||
index: string;
|
||||
id: string | number;
|
||||
path: string;
|
||||
}
|
|
@ -5,10 +5,9 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { GeoShapeRelation } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
import { ES_SPATIAL_RELATIONS } from './constants';
|
||||
|
||||
export function getDataSourceLabel() {
|
||||
return i18n.translate('xpack.maps.source.dataSourceLabel', {
|
||||
defaultMessage: 'Data source',
|
||||
|
@ -21,22 +20,21 @@ export function getUrlLabel() {
|
|||
});
|
||||
}
|
||||
|
||||
export function getEsSpatialRelationLabel(spatialRelation: ES_SPATIAL_RELATIONS) {
|
||||
export function getEsSpatialRelationLabel(spatialRelation: GeoShapeRelation) {
|
||||
switch (spatialRelation) {
|
||||
case ES_SPATIAL_RELATIONS.INTERSECTS:
|
||||
case 'intersects':
|
||||
return i18n.translate('xpack.maps.common.esSpatialRelation.intersectsLabel', {
|
||||
defaultMessage: 'intersects',
|
||||
});
|
||||
case ES_SPATIAL_RELATIONS.DISJOINT:
|
||||
case 'disjoint':
|
||||
return i18n.translate('xpack.maps.common.esSpatialRelation.disjointLabel', {
|
||||
defaultMessage: 'disjoint',
|
||||
});
|
||||
case ES_SPATIAL_RELATIONS.WITHIN:
|
||||
case 'within':
|
||||
return i18n.translate('xpack.maps.common.esSpatialRelation.withinLabel', {
|
||||
defaultMessage: 'within',
|
||||
});
|
||||
// @ts-ignore
|
||||
case ES_SPATIAL_RELATIONS.CONTAINS:
|
||||
case 'contains':
|
||||
return i18n.translate('xpack.maps.common.esSpatialRelation.containsLabel', {
|
||||
defaultMessage: 'contains',
|
||||
});
|
||||
|
|
|
@ -6,7 +6,10 @@
|
|||
*/
|
||||
|
||||
import rison from '@kbn/rison';
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type {
|
||||
SearchMvtRequest,
|
||||
SearchRequest,
|
||||
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { RENDER_AS } from './constants';
|
||||
|
||||
export function getAggsTileRequest({
|
||||
|
@ -32,7 +35,7 @@ export function getAggsTileRequest({
|
|||
y: number;
|
||||
z: number;
|
||||
}) {
|
||||
const requestBody = rison.decode(risonRequestBody) as estypes.SearchRequest['body'];
|
||||
const requestBody = rison.decode(risonRequestBody) as SearchRequest['body'];
|
||||
if (!requestBody) {
|
||||
throw new Error('Required requestBody parameter not provided');
|
||||
}
|
||||
|
@ -53,7 +56,7 @@ export function getAggsTileRequest({
|
|||
fields: requestBody.fields ? requestBody.fields : [],
|
||||
runtime_mappings: requestBody.runtime_mappings,
|
||||
with_labels: hasLabels,
|
||||
} as estypes.SearchMvtRequest['body'],
|
||||
} as SearchMvtRequest['body'],
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -76,7 +79,7 @@ export function getHitsTileRequest({
|
|||
y: number;
|
||||
z: number;
|
||||
}) {
|
||||
const requestBody = rison.decode(risonRequestBody) as estypes.SearchRequest['body'];
|
||||
const requestBody = rison.decode(risonRequestBody) as SearchRequest['body'];
|
||||
if (!requestBody) {
|
||||
throw new Error('Required requestBody parameter not provided');
|
||||
}
|
||||
|
@ -89,7 +92,7 @@ export function getHitsTileRequest({
|
|||
runtime_mappings: requestBody.runtime_mappings,
|
||||
track_total_hits: typeof requestBody.size === 'number' ? requestBody.size + 1 : false,
|
||||
with_labels: hasLabels,
|
||||
} as estypes.SearchMvtRequest['body'];
|
||||
} as SearchMvtRequest['body'];
|
||||
if (requestBody.fields) {
|
||||
// @ts-expect-error SearchRequest['body'].fields and SearchMvtRequest['body'].fields types do not allign, even though they do in implemenation
|
||||
tileRequestBody.fields = requestBody.fields;
|
||||
|
|
|
@ -10,7 +10,10 @@ import React, { ReactElement } from 'react';
|
|||
import _ from 'lodash';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { Feature } from 'geojson';
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type {
|
||||
AggregationsCompositeAggregate,
|
||||
SearchResponse,
|
||||
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { KibanaExecutionContext } from '@kbn/core/public';
|
||||
import { ISearchSource } from '@kbn/data-plugin/common/search/search_source';
|
||||
import { DataView } from '@kbn/data-plugin/common';
|
||||
|
@ -347,7 +350,7 @@ export class ESGeoGridSource extends AbstractESAggSource implements IMvtVectorSo
|
|||
const requestId: string = afterKey
|
||||
? `${this.getId()} afterKey ${afterKey.geoSplit}`
|
||||
: this.getId();
|
||||
const esResponse: estypes.SearchResponse<unknown> = await this._runEsQuery({
|
||||
const esResponse: SearchResponse<unknown> = await this._runEsQuery({
|
||||
requestId,
|
||||
requestName: i18n.translate('xpack.maps.source.esGrid.compositeInspector.requestName', {
|
||||
defaultMessage: '{layerName} {bucketsName} composite request ({requestCount})',
|
||||
|
@ -381,8 +384,7 @@ export class ESGeoGridSource extends AbstractESAggSource implements IMvtVectorSo
|
|||
|
||||
features.push(...convertCompositeRespToGeoJson(esResponse, this._descriptor.requestType));
|
||||
|
||||
const aggr = esResponse.aggregations
|
||||
?.compositeSplit as estypes.AggregationsCompositeAggregate;
|
||||
const aggr = esResponse.aggregations?.compositeSplit as AggregationsCompositeAggregate;
|
||||
afterKey = aggr.after_key;
|
||||
if (aggr.buckets.length < gridsPerRequest) {
|
||||
// Finished because request did not get full resultset back
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
import _ from 'lodash';
|
||||
import React, { ReactElement } from 'react';
|
||||
import type { QueryDslFieldLookup } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { GeoJsonProperties, Geometry, Position } from 'geojson';
|
||||
import type { KibanaExecutionContext } from '@kbn/core/public';
|
||||
|
@ -28,7 +29,6 @@ import {
|
|||
getField,
|
||||
hitsToGeoJson,
|
||||
isTotalHitsGreaterThan,
|
||||
PreIndexedShape,
|
||||
TotalHits,
|
||||
} from '../../../../common/elasticsearch_util';
|
||||
import { UpdateSourceEditor } from './update_source_editor';
|
||||
|
@ -800,7 +800,7 @@ export class ESSearchSource extends AbstractESSource implements IMvtVectorSource
|
|||
}
|
||||
|
||||
// Returns geo_shape indexed_shape context for spatial quering by pre-indexed shapes
|
||||
async _getPreIndexedShape(properties: GeoJsonProperties): Promise<PreIndexedShape | null> {
|
||||
async _getPreIndexedShape(properties: GeoJsonProperties): Promise<QueryDslFieldLookup | null> {
|
||||
if (properties === null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -31,19 +31,19 @@ exports[`render 1`] = `
|
|||
Array [
|
||||
Object {
|
||||
"text": "intersects",
|
||||
"value": "INTERSECTS",
|
||||
"value": "intersects",
|
||||
},
|
||||
Object {
|
||||
"text": "disjoint",
|
||||
"value": "DISJOINT",
|
||||
"value": "disjoint",
|
||||
},
|
||||
Object {
|
||||
"text": "within",
|
||||
"value": "WITHIN",
|
||||
"value": "within",
|
||||
},
|
||||
]
|
||||
}
|
||||
value="INTERSECTS"
|
||||
value="intersects"
|
||||
/>
|
||||
</EuiFormRow>
|
||||
<ActionSelect
|
||||
|
@ -100,19 +100,19 @@ exports[`should render error message 1`] = `
|
|||
Array [
|
||||
Object {
|
||||
"text": "intersects",
|
||||
"value": "INTERSECTS",
|
||||
"value": "intersects",
|
||||
},
|
||||
Object {
|
||||
"text": "disjoint",
|
||||
"value": "DISJOINT",
|
||||
"value": "disjoint",
|
||||
},
|
||||
Object {
|
||||
"text": "within",
|
||||
"value": "WITHIN",
|
||||
"value": "within",
|
||||
},
|
||||
]
|
||||
}
|
||||
value="INTERSECTS"
|
||||
value="intersects"
|
||||
/>
|
||||
</EuiFormRow>
|
||||
<ActionSelect
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import React, { ChangeEvent, Component } from 'react';
|
||||
import type { GeoShapeRelation } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import {
|
||||
EuiForm,
|
||||
EuiFormRow,
|
||||
|
@ -19,10 +20,24 @@ import {
|
|||
import { i18n } from '@kbn/i18n';
|
||||
import { ACTION_GLOBAL_APPLY_FILTER } from '@kbn/unified-search-plugin/public';
|
||||
import { Action, ActionExecutionContext } from '@kbn/ui-actions-plugin/public';
|
||||
import { ES_SPATIAL_RELATIONS } from '../../../../common/constants';
|
||||
import { getEsSpatialRelationLabel } from '../../../../common/i18n_getters';
|
||||
import { ActionSelect } from '../../action_select';
|
||||
|
||||
const RELATION_OPTIONS = [
|
||||
{
|
||||
value: 'intersects',
|
||||
text: getEsSpatialRelationLabel('intersects'),
|
||||
},
|
||||
{
|
||||
value: 'disjoint',
|
||||
text: getEsSpatialRelationLabel('disjoint'),
|
||||
},
|
||||
{
|
||||
value: 'within',
|
||||
text: getEsSpatialRelationLabel('within'),
|
||||
},
|
||||
];
|
||||
|
||||
interface Props {
|
||||
buttonLabel: string;
|
||||
getFilterActions?: () => Promise<Action[]>;
|
||||
|
@ -35,18 +50,24 @@ interface Props {
|
|||
}: {
|
||||
actionId: string;
|
||||
geometryLabel: string;
|
||||
relation: ES_SPATIAL_RELATIONS;
|
||||
relation: GeoShapeRelation;
|
||||
}) => void;
|
||||
errorMsg?: string;
|
||||
className?: string;
|
||||
isLoading?: boolean;
|
||||
}
|
||||
|
||||
export class GeometryFilterForm extends Component<Props> {
|
||||
state = {
|
||||
interface State {
|
||||
actionId: string;
|
||||
geometryLabel: string;
|
||||
relation: GeoShapeRelation;
|
||||
}
|
||||
|
||||
export class GeometryFilterForm extends Component<Props, State> {
|
||||
state: State = {
|
||||
actionId: ACTION_GLOBAL_APPLY_FILTER,
|
||||
geometryLabel: this.props.intitialGeometryLabel,
|
||||
relation: ES_SPATIAL_RELATIONS.INTERSECTS,
|
||||
relation: 'intersects',
|
||||
};
|
||||
|
||||
_onGeometryLabelChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
|
@ -57,7 +78,7 @@ export class GeometryFilterForm extends Component<Props> {
|
|||
|
||||
_onRelationChange = (e: ChangeEvent<HTMLSelectElement>) => {
|
||||
this.setState({
|
||||
relation: e.target.value,
|
||||
relation: e.target.value as GeoShapeRelation,
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -74,13 +95,6 @@ export class GeometryFilterForm extends Component<Props> {
|
|||
};
|
||||
|
||||
_renderRelationInput() {
|
||||
const options = Object.values(ES_SPATIAL_RELATIONS).map((relation) => {
|
||||
return {
|
||||
value: relation,
|
||||
text: getEsSpatialRelationLabel(relation),
|
||||
};
|
||||
});
|
||||
|
||||
return (
|
||||
<EuiFormRow
|
||||
label={i18n.translate('xpack.maps.geometryFilterForm.relationLabel', {
|
||||
|
@ -90,7 +104,7 @@ export class GeometryFilterForm extends Component<Props> {
|
|||
>
|
||||
<EuiSelect
|
||||
compressed
|
||||
options={options}
|
||||
options={RELATION_OPTIONS}
|
||||
value={this.state.relation}
|
||||
onChange={this._onRelationChange}
|
||||
/>
|
||||
|
|
|
@ -11,7 +11,7 @@ import type { Map as MbMap } from '@kbn/mapbox-gl';
|
|||
import { i18n } from '@kbn/i18n';
|
||||
import { Filter } from '@kbn/es-query';
|
||||
import { Feature, Polygon } from 'geojson';
|
||||
import { DRAW_SHAPE, ES_SPATIAL_RELATIONS } from '../../../../../common/constants';
|
||||
import { DRAW_SHAPE } from '../../../../../common/constants';
|
||||
import { DrawState } from '../../../../../common/descriptor_types';
|
||||
import {
|
||||
createDistanceFilterWithMeta,
|
||||
|
@ -75,9 +75,7 @@ export class DrawFilterControl extends Component<Props, {}> {
|
|||
: geometry,
|
||||
geoFieldNames: this.props.geoFieldNames,
|
||||
geometryLabel: this.props.drawState.geometryLabel ? this.props.drawState.geometryLabel : '',
|
||||
relation: this.props.drawState.relation
|
||||
? this.props.drawState.relation
|
||||
: ES_SPATIAL_RELATIONS.INTERSECTS,
|
||||
relation: this.props.drawState.relation ? this.props.drawState.relation : 'intersects',
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -6,16 +6,18 @@
|
|||
*/
|
||||
|
||||
import React, { Component } from 'react';
|
||||
import type {
|
||||
GeoShapeRelation,
|
||||
QueryDslFieldLookup,
|
||||
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
import { Filter } from '@kbn/es-query';
|
||||
import { ActionExecutionContext, Action } from '@kbn/ui-actions-plugin/public';
|
||||
import { MultiPolygon, Polygon } from 'geojson';
|
||||
import rison from '@kbn/rison';
|
||||
import { URL_MAX_LENGTH } from '@kbn/core/public';
|
||||
import { ACTION_GLOBAL_APPLY_FILTER } from '@kbn/unified-search-plugin/public';
|
||||
import { buildGeoShapeFilter, PreIndexedShape } from '../../../../../common/elasticsearch_util';
|
||||
import { ES_SPATIAL_RELATIONS } from '../../../../../common/constants';
|
||||
import { buildGeoShapeFilter } from '../../../../../common/elasticsearch_util';
|
||||
import { GeometryFilterForm } from '../../../../components/draw_forms/geometry_filter_form/geometry_filter_form';
|
||||
|
||||
// over estimated and imprecise value to ensure filter has additional room for any meta keys added when filter is mapped.
|
||||
|
@ -27,7 +29,7 @@ interface Props {
|
|||
addFilters: (filters: Filter[], actionId: string) => Promise<void>;
|
||||
getFilterActions?: () => Promise<Action[]>;
|
||||
getActionContext?: () => ActionExecutionContext;
|
||||
loadPreIndexedShape?: () => Promise<PreIndexedShape | null>;
|
||||
loadPreIndexedShape?: () => Promise<QueryDslFieldLookup | null>;
|
||||
geoFieldNames: string[];
|
||||
}
|
||||
|
||||
|
@ -79,7 +81,7 @@ export class FeatureGeometryFilterForm extends Component<Props, State> {
|
|||
relation,
|
||||
}: {
|
||||
geometryLabel: string;
|
||||
relation: ES_SPATIAL_RELATIONS;
|
||||
relation: GeoShapeRelation;
|
||||
}) => {
|
||||
this.setState({ errorMsg: undefined });
|
||||
const preIndexedShape = await this._loadPreIndexedShape();
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import React, { Component } from 'react';
|
||||
import type { GeoShapeRelation } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import {
|
||||
EuiButtonIcon,
|
||||
EuiPopover,
|
||||
|
@ -18,7 +19,7 @@ import {
|
|||
import { i18n } from '@kbn/i18n';
|
||||
import { FormattedMessage } from '@kbn/i18n-react';
|
||||
import { ActionExecutionContext, Action } from '@kbn/ui-actions-plugin/public';
|
||||
import { DRAW_SHAPE, ES_GEO_FIELD_TYPE, ES_SPATIAL_RELATIONS } from '../../../../common/constants';
|
||||
import { DRAW_SHAPE, ES_GEO_FIELD_TYPE } from '../../../../common/constants';
|
||||
import { GeometryFilterForm } from '../../../components/draw_forms/geometry_filter_form/geometry_filter_form';
|
||||
import { DistanceFilterForm } from '../../../components/draw_forms/distance_filter_form';
|
||||
import { DrawState } from '../../../../common/descriptor_types';
|
||||
|
@ -87,7 +88,7 @@ export class ToolsControl extends Component<Props, State> {
|
|||
indexPatternId?: string;
|
||||
geoFieldName?: string;
|
||||
geoFieldType?: ES_GEO_FIELD_TYPE;
|
||||
relation?: ES_SPATIAL_RELATIONS;
|
||||
relation?: GeoShapeRelation;
|
||||
}) => {
|
||||
this.props.initiateDraw({
|
||||
drawShape: DRAW_SHAPE.POLYGON,
|
||||
|
@ -102,7 +103,7 @@ export class ToolsControl extends Component<Props, State> {
|
|||
indexPatternId?: string;
|
||||
geoFieldName?: string;
|
||||
geoFieldType?: ES_GEO_FIELD_TYPE;
|
||||
relation?: ES_SPATIAL_RELATIONS;
|
||||
relation?: GeoShapeRelation;
|
||||
}) => {
|
||||
this.props.initiateDraw({
|
||||
drawShape: DRAW_SHAPE.BOUNDS,
|
||||
|
|
|
@ -19,7 +19,6 @@ export const plugin: PluginInitializer<MapsPluginSetup, MapsPluginStart> = (
|
|||
|
||||
export { GEOJSON_FEATURE_ID_PROPERTY_NAME, MAP_SAVED_OBJECT_TYPE } from '../common/constants';
|
||||
export { MAPS_APP_LOCATOR } from './locators/map_locator/locator_definition';
|
||||
export type { PreIndexedShape } from '../common/elasticsearch_util';
|
||||
|
||||
export type {
|
||||
ITooltipProperty,
|
||||
|
|
|
@ -13,7 +13,7 @@ import { CoreStart, KibanaRequest, KibanaResponseFactory, Logger } from '@kbn/co
|
|||
import { IRouter } from '@kbn/core/server';
|
||||
import type { DataRequestHandlerContext } from '@kbn/data-plugin/server';
|
||||
import { errors } from '@elastic/elasticsearch';
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { SearchMvtRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import {
|
||||
APP_ID,
|
||||
MVT_GETTILE_API_PATH,
|
||||
|
@ -70,7 +70,7 @@ export function initMVTRoutes({
|
|||
const y = parseInt((params as any).y, 10) as number;
|
||||
const z = parseInt((params as any).z, 10) as number;
|
||||
|
||||
let tileRequest: { path: string; body: estypes.SearchMvtRequest['body'] } = {
|
||||
let tileRequest: { path: string; body: SearchMvtRequest['body'] } = {
|
||||
path: '',
|
||||
body: {},
|
||||
};
|
||||
|
@ -148,7 +148,7 @@ export function initMVTRoutes({
|
|||
const y = parseInt((params as any).y, 10) as number;
|
||||
const z = parseInt((params as any).z, 10) as number;
|
||||
|
||||
let tileRequest: { path: string; body: estypes.SearchMvtRequest['body'] } = {
|
||||
let tileRequest: { path: string; body: SearchMvtRequest['body'] } = {
|
||||
path: '',
|
||||
body: {},
|
||||
};
|
||||
|
@ -200,7 +200,7 @@ async function getTile({
|
|||
path,
|
||||
}: {
|
||||
abortController: AbortController;
|
||||
body: estypes.SearchMvtRequest['body'];
|
||||
body: SearchMvtRequest['body'];
|
||||
context: DataRequestHandlerContext;
|
||||
core: CoreStart;
|
||||
executionContext: KibanaExecutionContext;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue