import { GeometryKind , GeometryKindSet } from "@here/harp-datasource-protocol" ; import { MapObjectAdapter } from "../MapObjectAdapter" ; import { MapView } from "../MapView" ; import { Tile } from "../Tile" ; type TileUpdateCallback = ( tile : Tile ) => void ; internal export class TileGeometryManager { deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      get enabledGeometryKinds ( ) : GeometryKindSet { return this . enabledKinds ; } deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      set enabledGeometryKinds ( kinds ) { this . enabledKinds = kinds ; } deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      get disabledGeometryKinds ( ) : GeometryKindSet { return this . disabledKinds ; } deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      set disabledGeometryKinds ( kinds ) { this . disabledKinds = kinds ; } deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      get hiddenGeometryKinds ( ) : GeometryKindSet { return this . hiddenKinds ; } deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      set hiddenGeometryKinds ( kinds ) { this . hiddenKinds = kinds ; this . incrementVisibilityCounter ( ) ; } deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      enableFilterByKind : boolean = true ; protected get visibilityCounter ( ) : number { return this . m_visibilityCounter ; } protected enabledKinds : GeometryKindSet = new GeometryKindSet ( ) ; protected disabledKinds : GeometryKindSet = new GeometryKindSet ( ) ; protected hiddenKinds : GeometryKindSet = new GeometryKindSet ( ) ; protected m_tileUpdateCallback : TileUpdateCallback | undefined ; /**
     * Optimization for evaluation in `update()` method. Only if a kind is hidden/unhidden, the
     * visibility of the kinds is applied to their geometries.
     */ private m_visibilityCounter : number = 1 ; /**
     * Creates an instance of `TileGeometryManager` with a reference to the  MapView .
      constructor ( protected mapView ) { } /**
     * Process the  Tile s for rendering. May alter the content of the tile per frame.
      updateTiles ( tiles ) { let prio = 0 ; for ( const tile of tiles ) { const tilePriority = prio ++ ; const updateDone = tile . updateGeometry ( tilePriority , this . enableFilterByKind ? this . enabledGeometryKinds : undefined , this . enableFilterByKind ? this . disabledGeometryKinds : undefined ) ; if ( updateDone && this . m_tileUpdateCallback ) { this . m_tileUpdateCallback ( tile ) ; } } if ( this . updateTileObjectVisibility ( tiles ) ) { this . mapView . update ( ) ; } } /**
     * Clear the enabled, disabled and hidden sets.
     */ clear ( ) { this . enabledKinds . clear ( ) ; this . disabledKinds . clear ( ) ; this . hiddenKinds . clear ( ) ; } param { ( GeometryKind | GeometryKind [ ] | GeometryKindSet ) } kind param { boolean } addOrRemoveToEnabledSet deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      enableKind ( kind , addOrRemoveToEnabledSet = true ) { this . enableDisableKinds ( this . enabledKinds , kind , addOrRemoveToEnabledSet ) ; } param { ( GeometryKind | GeometryKind [ ] | GeometryKindSet ) } kind param { boolean } addOrRemoveToHiddenSet deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      disableKind ( kind , addOrRemoveToDisabledSet = true ) { this . enableDisableKinds ( this . disabledKinds , kind , addOrRemoveToDisabledSet ) ; } param { ( GeometryKind | GeometryKind [ ] | GeometryKindSet ) } kind param { boolean } addOrRemoveToHiddenSet deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      hideKind ( kind , addOrRemoveToHiddenSet = true ) { let visibilityHasChanged = false ; if ( Array . isArray ( kind ) || kind instanceof Set ) { for ( const oneKind of kind ) { const visibilityChange = this . addRemove ( this . hiddenKinds , oneKind , addOrRemoveToHiddenSet ) ; visibilityHasChanged = visibilityHasChanged || visibilityChange ; } } else { visibilityHasChanged = this . addRemove ( this . hiddenKinds , kind , addOrRemoveToHiddenSet ) ; } if ( visibilityHasChanged ) { this . incrementVisibilityCounter ( ) ; } } param { IterableIterator < Tile > } tiles returns { GeometryKindSet } deprecated See  {@link @here/here-datasource-protocol/BaseTechniqueParams.kind} .
      getAvailableKinds ( tiles ) { const visibleKinds = new GeometryKindSet ( ) ; for ( const tile of tiles ) { const tileKinds = tile . loadedGeometryKinds ; if ( tileKinds !== undefined ) { for ( const kind of tileKinds ) { visibleKinds . add ( kind ) ; } } } return visibleKinds ; } param { Tile [ ] } tiles updateTileObjectVisibility ( tiles ) { let needUpdate = false ; for ( const tile of tiles ) { if ( tile . objects . length === 0 || tile . visibilityCounter === this . visibilityCounter ) { continue ; } tile . visibilityCounter = this . visibilityCounter ; for ( const object of tile . objects ) { const objectAdapter = MapObjectAdapter . get ( object ) ; const geometryKind = objectAdapter ?. kind ; if ( geometryKind !== undefined ) { const nowVisible = ! geometryKind . some ( kind => this . hiddenKinds . has ( kind ) ) ; needUpdate = needUpdate || object . visible !== nowVisible ; object . visible = nowVisible ; } } } return needUpdate ; } param { TileUpdateCallback } callback setTileUpdateCallback ( callback ? ) { this . m_tileUpdateCallback = callback ; } protected incrementVisibilityCounter ( ) { return ++ this . m_visibilityCounter ; } hidden param { GeometryKindSet } set param { ( GeometryKind | GeometryKind [ ] | GeometryKindSet ) } kind param { boolean } addToSet private enableDisableKinds ( set , kind , addToSet ) { if ( Array . isArray ( kind ) ) { for ( const oneKind of kind as GeometryKind [ ] ) { this . addRemove ( set , oneKind , addToSet ) ; } } else if ( kind instanceof Set ) { const kindSet = kind as GeometryKindSet ; for ( const oneKind of kindSet ) { this . addRemove ( set , oneKind , addToSet ) ; } } else if ( kind !== undefined ) { this . addRemove ( set , kind , addToSet ) ; } } hidden param { GeometryKindSet } set param { ( GeometryKind | GeometryKind [ ] | GeometryKindSet ) } kind param { boolean } addToSet private addRemove ( kindsSet , kind , addToSet ) { if ( addToSet ) { if ( ! kindsSet . has ( kind ) ) { kindsSet . add ( kind ) ; return true ; } } else { if ( kindsSet . has ( kind ) ) { kindsSet . delete ( kind ) ; return true ; } } return false ; } }