Skip to content

Commit

Permalink
implement bounds retrieval for file sources
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Jan 13, 2021
1 parent 37cfeb6 commit a64ad0d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<ISearchSource> {
Expand Down Expand Up @@ -264,7 +264,7 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource
}

async getBoundsForFilters(
boundsFilters: BoundsFilters,
boundsFilters: ESGlobalFilters,
registerCancelCallback: (callback: () => void) => void
): Promise<MapExtent | null> {
const searchSource = await this.makeSearchSource(boundsFilters, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -42,6 +43,18 @@ export class GeojsonFileSource extends AbstractVectorSource {
};
}

isBoundsAware(): boolean {
return true;
}

async getBoundsForFilters(
boundsFilters: ESGlobalFilters,
registerCancelCallback: (callback: () => void) => void
): Promise<MapExtent | null> {
const featureCollection = (this._descriptor as GeojsonFileSourceDescriptor).__featureCollection;
return getFeatureCollectionBounds(featureCollection, false);
}

async getGeoJsonWithMeta(): Promise<GeoJsonWithMeta> {
return {
data: (this._descriptor as GeojsonFileSourceDescriptor).__featureCollection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -179,7 +179,7 @@ export class MVTSingleLayerVectorSource
}

async getBoundsForFilters(
boundsFilters: BoundsFilters,
boundsFilters: ESGlobalFilters,
registerCancelCallback: (callback: () => void) => void
): Promise<MapExtent | null> {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface GeoJsonWithMeta {
meta?: GeoJsonFetchMeta;
}

export interface BoundsFilters {
export interface ESGlobalFilters {
applyGlobalQuery: boolean;
applyGlobalTime: boolean;
filters: Filter[];
Expand All @@ -47,7 +47,7 @@ export interface BoundsFilters {
export interface IVectorSource extends ISource {
getTooltipProperties(properties: GeoJsonProperties): Promise<ITooltipProperty[]>;
getBoundsForFilters(
boundsFilters: BoundsFilters,
boundsFilters: ESGlobalFilters,
registerCancelCallback: (callback: () => void) => void
): Promise<MapExtent | null>;
getGeoJsonWithMeta(
Expand Down Expand Up @@ -147,7 +147,7 @@ export class AbstractVectorSource extends AbstractSource implements IVectorSourc
}

async getBoundsForFilters(
boundsFilters: BoundsFilters,
boundsFilters: ESGlobalFilters,
registerCancelCallback: (callback: () => void) => void
): Promise<MapExtent | null> {
return null;
Expand Down

0 comments on commit a64ad0d

Please sign in to comment.