import { GeometryKind , GeometryKindSet } from "@here/harp-datasource-protocol" ; import { MapEnv } from "@here/harp-datasource-protocol/index-decoder" ; import { OmvFeatureFilterDescription , OmvFilterDescription , OmvFilterFeatureAttribute , OmvFilterString , OmvGeometryType , OmvLayerFilterDescription } from "./OmvDecoderDefs" ; remarks export interface OmvFeatureFilter { deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      hasKindFilter : boolean ; param layer param level wantsLayer ( layer , level ) : boolean ; param layer param feature param level wantsPointFeature ( layer , geometryType , level ) : boolean ; param layer param feature param level wantsLineFeature ( layer , geometryType , level ) : boolean ; param layer param feature param level wantsPolygonFeature ( layer , geometryType , level ) : boolean ; param { ( string | string [ ] ) } kind returns { boolean } deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      wantsKind ( kind ) : boolean ; } remarks export interface OmvFeatureModifier { param layer param env param level returns doProcessPointFeature ( layer , env , level ) : boolean ; param layer param env param level returns doProcessLineFeature ( layer , env , level ) : boolean ; param layer param env param level returns doProcessPolygonFeature ( layer , env , level ) : boolean ; } /**
 * Builds an `OmvFilterDescription` (internal type) that specifies an [[OmvFeatureFilter]] as well
 * as an [[OmvFeatureModifier]].
 *
 */ export class OmvFeatureFilterDescriptionBuilder { private readonly m_processLayersDefault : boolean = true ; private readonly m_processPointsDefault : boolean = true ; private readonly m_processLinesDefault : boolean = true ; private readonly m_processPolygonsDefault : boolean = true ; private readonly m_layersToProcess = new Array < OmvLayerFilterDescription > ( ) ; private readonly m_layersToIgnore = new Array < OmvLayerFilterDescription > ( ) ; private readonly m_pointsToProcess = new Array < OmvFilterDescription > ( ) ; private readonly m_ignoredPoints = new Array < OmvFilterDescription > ( ) ; private readonly m_linesToProcess = new Array < OmvFilterDescription > ( ) ; private readonly m_linesToIgnore = new Array < OmvFilterDescription > ( ) ; private readonly m_polygonsToProcess = new Array < OmvFilterDescription > ( ) ; private readonly m_polygonsToIgnore = new Array < OmvFilterDescription > ( ) ; private m_kindsToProcess : string [ ] = [ ] ; private m_kindsToIgnore : string [ ] = [ ] ; param processLayersDefault param processPointsDefault param processLinesDefault param processPolygonsDefault constructor ( options ? ) { if ( options ) { this . m_processLayersDefault = options . processLayersDefault !== undefined ? options . processLayersDefault : true ; this . m_processPointsDefault = options . processPointsDefault !== undefined ? options . processPointsDefault : true ; this . m_processLinesDefault = options . processLinesDefault !== undefined ? options . processLinesDefault : true ; this . m_processPolygonsDefault = options . processPolygonsDefault !== undefined ? options . processPolygonsDefault : true ; } } param layer param match processLayer ( layer , match = OmvFilterString . StringMatch . Match , minLevel = 0 , maxLevel = Infinity ) { this . m_layersToProcess . push ( { name : { value : layer , match } , minLevel , maxLevel } ) ; } param layer param match ignoreLayer ( layer , match = OmvFilterString . StringMatch . Match , minLevel = 0 , maxLevel = Infinity ) { this . m_layersToIgnore . push ( { name : { value : layer , match } , minLevel , maxLevel } ) ; } param options processPoint ( options ) { this . addItem ( this . m_pointsToProcess , options ) ; } param options processPoints ( options ) { this . addItems ( this . m_pointsToProcess , options ) ; } param options ignorePoint ( options ) { this . addItem ( this . m_ignoredPoints , options ) ; } param options ignorePoints ( options ) { this . addItems ( this . m_ignoredPoints , options ) ; } param options processLine ( options ) { this . addItem ( this . m_linesToProcess , options ) ; } param options processLines ( options ) { this . addItems ( this . m_linesToProcess , options ) ; } param options ignoreLine ( options ) { this . addItem ( this . m_linesToIgnore , options ) ; } param options ignoreLines ( options ) { this . addItems ( this . m_linesToIgnore , options ) ; } param options processPolygon ( options ) { this . addItem ( this . m_polygonsToProcess , options ) ; } param options processPolygons ( options ) { this . addItems ( this . m_polygonsToProcess , options ) ; } param options ignorePolygon ( options ) { this . addItem ( this . m_polygonsToIgnore , options ) ; } param options ignorePolygons ( options ) { this . addItems ( this . m_polygonsToIgnore , options ) ; } param { string [ ] } enabledKinds deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      processKinds ( enabledKinds ) { this . m_kindsToProcess = this . m_kindsToProcess . concat ( enabledKinds ) ; } param { string [ ] } disabledKinds deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      ignoreKinds ( disabledKinds ) { this . m_kindsToIgnore = this . m_kindsToIgnore . concat ( disabledKinds ) ; } /**
     * Create a filter description that can be passed as an option to the [[OmvDataSource]].
     */ createDescription ( ) { return { processLayersDefault : this . m_processLayersDefault , processPointsDefault : this . m_processPointsDefault , processLinesDefault : this . m_processLinesDefault , processPolygonsDefault : this . m_processPolygonsDefault , layersToProcess : this . m_layersToProcess , layersToIgnore : this . m_layersToIgnore , pointsToProcess : this . m_pointsToProcess , pointsToIgnore : this . m_ignoredPoints , linesToProcess : this . m_linesToProcess , linesToIgnore : this . m_linesToIgnore , polygonsToProcess : this . m_polygonsToProcess , polygonsToIgnore : this . m_polygonsToIgnore , kindsToProcess : this . m_kindsToProcess , kindsToIgnore : this . m_kindsToIgnore } ; } private addItem ( items , options ) { if ( options . minLevel === undefined || isNaN ( options . minLevel ) ) { options . minLevel = 0 ; } if ( options . maxLevel === undefined || isNaN ( options . maxLevel ) ) { options . maxLevel = Infinity ; } const item = { layerName : { value : options . layer , match : options . matchLayer === undefined ? OmvFilterString . StringMatch . Match : options . matchLayer } , geometryTypes : options . geomType !== undefined ? Array . isArray ( options . geomType ) ? options . geomType : [ options . geomType ] : undefined , classes : [ { value : options . featureClass , match : options . matchClass === undefined ? OmvFilterString . StringMatch . Match : options . matchClass } ] , minLevel : options . minLevel , maxLevel : options . maxLevel , featureAttribute : options . featureAttribute } ; items . push ( item ) ; } private addItems ( items , options ) { if ( options . minLevel === undefined || isNaN ( options . minLevel ) ) { options . minLevel = 0 ; } if ( options . maxLevel === undefined || isNaN ( options . maxLevel ) ) { options . maxLevel = Infinity ; } const item = { layerName : { value : options . layer , match : options . matchLayer === undefined ? OmvFilterString . StringMatch . Match : options . matchLayer } , geometryTypes : options . geomTypes !== undefined ? Array . isArray ( options . geomTypes ) ? options . geomTypes : [ options . geomTypes ] : undefined , classes : options . featureClasses , minLevel : options . minLevel , maxLevel : options . maxLevel , featureAttribute : options . featureAttribute } ; items . push ( item ) ; } } export namespace OmvFeatureFilterDescriptionBuilder { /**
     * Options for `OmvFeatureFilterDescriptionBuilder`.
     */ export interface OmvFeatureFilterDescriptionBuilderOptions { /**
         * If `true`, all unspecified layers will be processed. If `false`, all unspecified layers
         * will be ignored.
         */ processLayersDefault ? : boolean ; /**
         * If `true`, all unspecified point features will be processed. If `false`, all unspecified
         * point features will be ignored.
         */ processPointsDefault ? : boolean ; /**
         * If `true`, all unspecified line features will be processed. If `false`, all unspecified
         * line
         * features will be ignored.
         */ processLinesDefault ? : boolean ; /**
         * If `true`, all unspecified polygon features will be processed. If `false`, all
         * unspecified polygon features will be ignored.
         */ processPolygonsDefault ? : boolean ; } /**
     * Description of a single feature.
     */ export interface FeatureOption { /**
         * Layer name to be matched.
         */ layer : string ; /**
         * Optional geometry type to be limited to. If specified, but does not match, the feature is
         * ignored.
         */ geomType : OmvGeometryType | OmvGeometryType [ ] | undefined ; /**
         * Optional class to match. If specified, but does not match, the feature is ignored.
         */ featureClass : string ; /**
         * Match condition for the layer name.
         */ matchLayer ? : OmvFilterString . StringMatch ; /**
         * Match condition for `featureClass`.
         */ matchClass ? : OmvFilterString . StringMatch ; /**
         * Minimum tile level to match.
         */ minLevel ? : number ; /**
         * Maximum tile level to match.
         */ maxLevel ? : number ; /**
         * Feature attribute to match.
         */ featureAttribute ? : OmvFilterFeatureAttribute ; } /**
     * Description for multiple features.
     */ export interface MultiFeatureOption { /**
         * Layer name to be matched.
         */ layer : string ; /**
         * Optional geometry type to be limited to. If specified, but does not match, the feature is
         * ignored.
         */ geomTypes ? : OmvGeometryType | OmvGeometryType [ ] | undefined ; /**
         * Optional classes to match. If specified, but does not match, the feature is ignored.
         */ featureClasses ? : OmvFilterString [ ] ; /**
         * Match condition for the layer name.
         */ matchLayer ? : OmvFilterString . StringMatch ; /**
         * Minimum tile level to match.
         */ minLevel ? : number ; /**
         * Maximum tile level to match.
         */ maxLevel ? : number ; /**
         * Feature attribute to match.
         */ featureAttribute ? : OmvFilterFeatureAttribute ; } } internal export class OmvGenericFeatureFilter implements OmvFeatureFilter { private static matchLayer ( layer , layerItems , level ) { for ( const layerItem of layerItems ) { if ( level < layerItem . minLevel || level > layerItem . maxLevel ) { continue ; } if ( OmvFilterString . matchString ( layer , layerItem . name ) ) { return true ; } } return false ; } private readonly disabledKinds : GeometryKindSet | undefined ; private readonly enabledKinds : GeometryKindSet | undefined ; constructor ( private readonly description ) { if ( this . description . kindsToProcess . length > 0 ) { this . enabledKinds = new GeometryKindSet ( this . description . kindsToProcess as GeometryKind [ ] ) ; } if ( this . description . kindsToIgnore . length > 0 ) { this . disabledKinds = new GeometryKindSet ( this . description . kindsToIgnore as GeometryKind [ ] ) ; } } wantsLayer ( layer , level ) { if ( OmvGenericFeatureFilter . matchLayer ( layer , this . description . layersToProcess , level ) ) { return true ; } if ( OmvGenericFeatureFilter . matchLayer ( layer , this . description . layersToIgnore , level ) ) { return false ; } return this . description . processLayersDefault ; } wantsPointFeature ( layer , geometryType , level ) { return this . wantsFeature ( this . description . pointsToProcess , this . description . pointsToIgnore , layer , geometryType , level , this . description . processPointsDefault ) ; } wantsLineFeature ( layer , geometryType , level ) { return this . wantsFeature ( this . description . linesToProcess , this . description . linesToIgnore , layer , geometryType , level , this . description . processLinesDefault ) ; } wantsPolygonFeature ( layer , geometryType , level ) { return this . wantsFeature ( this . description . polygonsToProcess , this . description . polygonsToIgnore , layer , geometryType , level , this . description . processPolygonsDefault ) ; } deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      wantsKind ( kind ) { if ( kind === undefined ) { return true ; } return ( ! ( this . disabledKinds !== undefined && this . disabledKinds . hasOrIntersects ( kind as GeometryKind ) ) || ( this . enabledKinds !== undefined && this . enabledKinds . hasOrIntersects ( kind as GeometryKind ) ) ) ; } deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      get hasKindFilter ( ) : boolean { return this . enabledKinds !== undefined || this . disabledKinds !== undefined ; } private wantsFeature ( itemsToProcess , itemsToIgnore , layer , geometryType , level , defaultResult ) { for ( const item of itemsToProcess ) { if ( level < item . minLevel || level > item . maxLevel ) { continue ; } if ( ! OmvFilterString . matchString ( layer , item . layerName ) ) { continue ; } if ( item . geometryTypes !== undefined && item . geometryTypes . includes ( geometryType ) ) { return true ; } } for ( const item of itemsToIgnore ) { if ( ! OmvFilterString . matchString ( layer , item . layerName ) ) { continue ; } if ( item . geometryTypes !== undefined && item . geometryTypes . includes ( geometryType ) ) { return false ; } } return defaultResult ; } } internal export class ComposedDataFilter implements OmvFeatureFilter { constructor ( readonly filters ) { } deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      get hasKindFilter ( ) { return this . filters . reduce < boolean > ( ( result , filter ) => result || filter . hasKindFilter , true ) ; } wantsLayer ( layer , level ) { return this . filters . reduce < boolean > ( ( result , filter ) => result && filter . wantsLayer ( layer , level ) , true ) ; } wantsPointFeature ( layer , geometryType , level ) { return this . filters . reduce < boolean > ( ( result , filter ) => result && filter . wantsPointFeature ( layer , geometryType , level ) , true ) ; } wantsLineFeature ( layer , geometryType , level ) { return this . filters . reduce < boolean > ( ( result , filter ) => result && filter . wantsLineFeature ( layer , geometryType , level ) , true ) ; } wantsPolygonFeature ( layer , geometryType , level ) { return this . filters . reduce < boolean > ( ( result , filter ) => result && filter . wantsPolygonFeature ( layer , geometryType , level ) , true ) ; } deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      wantsKind ( kind ) { return this . filters . reduce < boolean > ( ( result , filter ) => result && filter . wantsKind ( kind ) , true ) ; } } internal export class OmvGenericFeatureModifier implements OmvFeatureModifier { static matchItems ( layerName , featureClass , items ) { for ( const item of items ) { if ( item . classes !== undefined ) { if ( ! OmvFilterString . matchString ( layerName , item . layerName ) ) { continue ; } for ( const matchClass of item . classes ) { if ( OmvFilterString . matchString ( featureClass , matchClass ) ) { return true ; } } } } return false ; } static matchAttribute ( layerName , env , items ) { for ( const item of items ) { if ( item . featureAttribute !== undefined ) { if ( OmvFilterString . matchString ( layerName , item . layerName ) && env . lookup ( item . featureAttribute . key ) === item . featureAttribute . value ) { return true ; } } } return false ; } constructor ( private readonly description ) { } doProcessPointFeature ( layer , env ) { return this . doProcessFeature ( this . description . pointsToProcess , this . description . pointsToIgnore , layer , env , this . description . processPointsDefault ) ; } doProcessLineFeature ( layer , env ) { return this . doProcessFeature ( this . description . linesToProcess , this . description . linesToIgnore , layer , env , this . description . processLinesDefault ) ; } doProcessPolygonFeature ( layer , env ) { return this . doProcessFeature ( this . description . polygonsToProcess , this . description . polygonsToIgnore , layer , env , this . description . processPolygonsDefault ) ; } protected doProcessFeature ( itemsToProcess , itemsToIgnore , layer , env , defaultResult ) { if ( layer === undefined || ( itemsToProcess . length === 0 && itemsToIgnore . length === 0 ) ) { return defaultResult ; } let featureClass ; const featureClassThing = env . lookup ( "class" ) ; if ( featureClassThing !== undefined && featureClassThing !== null ) { featureClass = featureClassThing . toString ( ) ; } if ( featureClass && OmvGenericFeatureModifier . matchItems ( layer , featureClass , itemsToProcess ) ) { return true ; } if ( featureClass && OmvGenericFeatureModifier . matchItems ( layer , featureClass , itemsToIgnore ) ) { return false ; } if ( OmvGenericFeatureModifier . matchAttribute ( layer , env , itemsToProcess ) ) { return true ; } if ( OmvGenericFeatureModifier . matchAttribute ( layer , env , itemsToIgnore ) ) { return false ; } return defaultResult ; } }