From a64ad0d2c2f472cd0c00bbcd4ee301451eee3df6 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 13 Jan 2021 17:46:15 -0500 Subject: [PATCH] implement bounds retrieval for file sources --- .../classes/sources/es_source/es_source.ts | 6 +++--- .../geojson_file_source/geojson_file_source.ts | 17 +++++++++++++++-- .../mvt_single_layer_vector_source.tsx | 4 ++-- .../sources/vector_source/vector_source.tsx | 6 +++--- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts b/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts index 967131e900fc6..f4f79e899b0d8 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts +++ b/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts @@ -7,7 +7,7 @@ import { i18n } from '@kbn/i18n'; import uuid from 'uuid/v4'; import { Filter, IFieldType, IndexPattern, ISearchSource } from 'src/plugins/data/public'; -import { AbstractVectorSource, BoundsFilters } from '../vector_source'; +import { AbstractVectorSource, ESGlobalFilters } from '../vector_source'; import { getAutocompleteService, getIndexPatternService, @@ -211,7 +211,7 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource } async makeSearchSource( - searchFilters: VectorSourceRequestMeta | VectorJoinSourceRequestMeta | BoundsFilters, + searchFilters: VectorSourceRequestMeta | VectorJoinSourceRequestMeta | ESGlobalFilters, limit: number, initialSearchContext?: object ): Promise { @@ -264,7 +264,7 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource } async getBoundsForFilters( - boundsFilters: BoundsFilters, + boundsFilters: ESGlobalFilters, registerCancelCallback: (callback: () => void) => void ): Promise { const searchSource = await this.makeSearchSource(boundsFilters, 0); diff --git a/x-pack/plugins/maps/public/classes/sources/geojson_file_source/geojson_file_source.ts b/x-pack/plugins/maps/public/classes/sources/geojson_file_source/geojson_file_source.ts index 6172405152739..a6ae38546daab 100644 --- a/x-pack/plugins/maps/public/classes/sources/geojson_file_source/geojson_file_source.ts +++ b/x-pack/plugins/maps/public/classes/sources/geojson_file_source/geojson_file_source.ts @@ -5,11 +5,12 @@ */ import { Feature, FeatureCollection } from 'geojson'; -import { AbstractVectorSource, GeoJsonWithMeta } from '../vector_source'; +import { AbstractVectorSource, ESGlobalFilters, GeoJsonWithMeta } from '../vector_source'; import { EMPTY_FEATURE_COLLECTION, SOURCE_TYPES } from '../../../../common/constants'; -import { GeojsonFileSourceDescriptor } from '../../../../common/descriptor_types'; +import { GeojsonFileSourceDescriptor, MapExtent } from '../../../../common/descriptor_types'; import { registerSource } from '../source_registry'; import { IField } from '../../fields/field'; +import { getFeatureCollectionBounds } from '../../util/get_feature_collection_bounds'; function getFeatureCollection(geoJson: Feature | FeatureCollection | null): FeatureCollection { if (!geoJson) { @@ -42,6 +43,18 @@ export class GeojsonFileSource extends AbstractVectorSource { }; } + isBoundsAware(): boolean { + return true; + } + + async getBoundsForFilters( + boundsFilters: ESGlobalFilters, + registerCancelCallback: (callback: () => void) => void + ): Promise { + const featureCollection = (this._descriptor as GeojsonFileSourceDescriptor).__featureCollection; + return getFeatureCollectionBounds(featureCollection, false); + } + async getGeoJsonWithMeta(): Promise { return { data: (this._descriptor as GeojsonFileSourceDescriptor).__featureCollection, diff --git a/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx index adc478c1f45d3..0fb739528d2a5 100644 --- a/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx @@ -9,7 +9,7 @@ import uuid from 'uuid/v4'; import React from 'react'; import { GeoJsonProperties } from 'geojson'; import { AbstractSource, ImmutableSourceProperty, SourceEditorArgs } from '../source'; -import { BoundsFilters, GeoJsonWithMeta, ITiledSingleLayerVectorSource } from '../vector_source'; +import { ESGlobalFilters, GeoJsonWithMeta, ITiledSingleLayerVectorSource } from '../vector_source'; import { FIELD_ORIGIN, MAX_ZOOM, @@ -179,7 +179,7 @@ export class MVTSingleLayerVectorSource } async getBoundsForFilters( - boundsFilters: BoundsFilters, + boundsFilters: ESGlobalFilters, registerCancelCallback: (callback: () => void) => void ): Promise { return null; diff --git a/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.tsx b/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.tsx index 32db97708e397..6f73413067622 100644 --- a/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.tsx @@ -35,7 +35,7 @@ export interface GeoJsonWithMeta { meta?: GeoJsonFetchMeta; } -export interface BoundsFilters { +export interface ESGlobalFilters { applyGlobalQuery: boolean; applyGlobalTime: boolean; filters: Filter[]; @@ -47,7 +47,7 @@ export interface BoundsFilters { export interface IVectorSource extends ISource { getTooltipProperties(properties: GeoJsonProperties): Promise; getBoundsForFilters( - boundsFilters: BoundsFilters, + boundsFilters: ESGlobalFilters, registerCancelCallback: (callback: () => void) => void ): Promise; getGeoJsonWithMeta( @@ -147,7 +147,7 @@ export class AbstractVectorSource extends AbstractSource implements IVectorSourc } async getBoundsForFilters( - boundsFilters: BoundsFilters, + boundsFilters: ESGlobalFilters, registerCancelCallback: (callback: () => void) => void ): Promise { return null;