import type { Query } from 'src/plugins/data/common' ; import { FeatureCollection , GeoJsonProperties , Geometry , Position } from 'geojson' ; import { Filter } from '@kbn/es-query' ; import { TimeRange } from 'src/plugins/data/public' ; import { VECTOR_SHAPE_TYPE } from '../../../../common/constants' ; import { ITooltipProperty , TooltipProperty } from '../../tooltips/tooltip_property' ; import { AbstractSource , ISource } from '../source' ; import { IField } from '../../fields/field' ; import { ESSearchSourceResponseMeta , MapExtent , Timeslice , VectorSourceRequestMeta , } from '../../../../common/descriptor_types' ; import { DataRequest } from '../../util/data_request' ; export interface SourceStatus { tooltipContent : string | null ; areResultsTrimmed : boolean ; isDeprecated ? : boolean ; } export type GeoJsonFetchMeta = ESSearchSourceResponseMeta ; export interface GeoJsonWithMeta { data : FeatureCollection ; meta ? : GeoJsonFetchMeta ; } export interface BoundsRequestMeta { applyGlobalQuery : boolean ; applyGlobalTime : boolean ; filters : Filter [ ] ; query ? : Query ; sourceQuery ? : Query ; timeFilters : TimeRange ; timeslice ? : Timeslice ; } export interface IVectorSource extends ISource { isMvt ( ) : boolean ; getTooltipProperties ( properties ) : Promise < ITooltipProperty [ ] > ; getBoundsForFilters ( layerDataFilters , registerCancelCallback ) : Promise < MapExtent | null > ; getGeoJsonWithMeta ( layerName , searchFilters , registerCancelCallback , isRequestStillActive ) : Promise < GeoJsonWithMeta > ; getFields ( ) : Promise < IField [ ] > ; getFieldByName ( fieldName ) : IField | null ; getLeftJoinFields ( ) : Promise < IField [ ] > ; showJoinEditor ( ) : boolean ; getJoinsDisabledReason ( ) : string | null ; getSyncMeta ( ) : object | null ; getFieldNames ( ) : string [ ] ; createField ( { fieldName } ) : IField ; hasTooltipProperties ( ) : boolean ; getSupportedShapeTypes ( ) : Promise < VECTOR_SHAPE_TYPE [ ] > ; isBoundsAware ( ) : boolean ; getSourceStatus ( sourceDataRequest ? ) : SourceStatus ; getTimesliceMaskFieldName ( ) : Promise < string | null > ; supportsFeatureEditing ( ) : Promise < boolean > ; getDefaultFields ( ) : Promise < Record < string , Record < string , string > > > ; addFeature ( geometry , defaultFields ) : Promise < void > ; deleteFeature ( featureId ) : Promise < void > ; } export class AbstractVectorSource extends AbstractSource implements IVectorSource { getFieldNames ( ) { return [ ] ; } isMvt ( ) { return false ; } createField ( { fieldName } ) { throw new Error ( 'Not implemented' ) ; } getFieldByName ( fieldName ) { return this . createField ( { fieldName } ) ; } isFilterByMapBounds ( ) { return false ; } isBoundsAware ( ) { return false ; } async supportsFitToBounds ( ) { return true ; } async getBoundsForFilters ( boundsFilters , registerCancelCallback ) { return null ; } async getFields ( ) { return [ ] ; } async getLeftJoinFields ( ) { return [ ] ; } getJoinsDisabledReason ( ) { return null ; } async getGeoJsonWithMeta ( layerName , searchFilters , registerCancelCallback , isRequestStillActive ) { throw new Error ( 'Should implement VectorSource#getGeoJson' ) ; } hasTooltipProperties ( ) { return false ; } async getTooltipProperties ( properties ) { const tooltipProperties = [ ] ; for ( const key in properties ) { if ( key . startsWith ( '__kbn' ) ) { continue ; } tooltipProperties . push ( new TooltipProperty ( key , key , properties [ key ] ) ) ; } return tooltipProperties ; } async isTimeAware ( ) { return false ; } showJoinEditor ( ) { return true ; } async getSupportedShapeTypes ( ) { return [ VECTOR_SHAPE_TYPE . POINT , VECTOR_SHAPE_TYPE . LINE , VECTOR_SHAPE_TYPE . POLYGON ] ; } getSourceStatus ( sourceDataRequest ? ) { return { tooltipContent : null , areResultsTrimmed : false } ; } getSyncMeta ( ) { return null ; } async getTimesliceMaskFieldName ( ) { return null ; } async addFeature ( geometry , defaultFields ) { throw new Error ( 'Should implement VectorSource#addFeature' ) ; } async deleteFeature ( featureId ) { throw new Error ( 'Should implement VectorSource#deleteFeature' ) ; } async supportsFeatureEditing ( ) { return false ; } async getDefaultFields ( ) { return { } ; } }