import { GEO_JSON_TYPE , FEATURE_VISIBLE_PROPERTY_NAME , KBN_IS_CENTROID_FEATURE , } from '../../../common/constants' ; import { Timeslice } from '../../../common/descriptor_types' ; export interface TimesliceMaskConfig { timesliceMaskField : string ; timeslice : Timeslice ; } export const EXCLUDE_CENTROID_FEATURES = [ '!=' , [ 'get' , KBN_IS_CENTROID_FEATURE ] , true ] ; function getFilterExpression ( filters , hasJoins , timesliceMaskConfig ? ) { const allFilters = [ ... filters ] ; if ( hasJoins ) { allFilters . push ( [ '==' , [ 'get' , FEATURE_VISIBLE_PROPERTY_NAME ] , true ] ) ; } if ( timesliceMaskConfig ) { allFilters . push ( [ 'has' , timesliceMaskConfig . timesliceMaskField ] ) ; allFilters . push ( [ '>=' , [ 'get' , timesliceMaskConfig . timesliceMaskField ] , timesliceMaskConfig . timeslice . from , ] ) ; allFilters . push ( [ '<' , [ 'get' , timesliceMaskConfig . timesliceMaskField ] , timesliceMaskConfig . timeslice . to , ] ) ; } return [ 'all' , ... allFilters ] ; } export function getFillFilterExpression ( hasJoins , timesliceMaskConfig ? ) { return getFilterExpression ( [ [ 'any' , [ '==' , [ 'geometry-type' ] , GEO_JSON_TYPE . POLYGON ] , [ '==' , [ 'geometry-type' ] , GEO_JSON_TYPE . MULTI_POLYGON ] , ] , ] , hasJoins , timesliceMaskConfig ) ; } export function getLineFilterExpression ( hasJoins , timesliceMaskConfig ? ) { return getFilterExpression ( [ [ 'any' , [ '==' , [ 'geometry-type' ] , GEO_JSON_TYPE . POLYGON ] , [ '==' , [ 'geometry-type' ] , GEO_JSON_TYPE . MULTI_POLYGON ] , [ '==' , [ 'geometry-type' ] , GEO_JSON_TYPE . LINE_STRING ] , [ '==' , [ 'geometry-type' ] , GEO_JSON_TYPE . MULTI_LINE_STRING ] , ] , ] , hasJoins , timesliceMaskConfig ) ; } const IS_POINT_FEATURE = [ 'any' , [ '==' , [ 'geometry-type' ] , GEO_JSON_TYPE . POINT ] , [ '==' , [ 'geometry-type' ] , GEO_JSON_TYPE . MULTI_POINT ] , ] ; export function getPointFilterExpression ( hasJoins , timesliceMaskConfig ? ) { return getFilterExpression ( [ EXCLUDE_CENTROID_FEATURES , IS_POINT_FEATURE ] , hasJoins , timesliceMaskConfig ) ; } export function getLabelFilterExpression ( hasJoins , isSourceGeoJson , timesliceMaskConfig ? ) { const filters = [ ] ; if ( isSourceGeoJson ) { filters . push ( IS_POINT_FEATURE ) ; } return getFilterExpression ( filters , hasJoins , timesliceMaskConfig ) ; }