import { GeometryKind , GeometryKindSet , ImageTexture , LineMarkerTechnique , PoiStackMode , PoiTechnique } from "@here/harp-datasource-protocol" ; import { GlyphData , TextBufferObject , TextLayoutParameters , TextLayoutStyle , TextRenderParameters , TextRenderStyle } from "@here/harp-text-canvas" ; import { Math2D } from "@here/harp-utils" ; import * as THREE from "three" ; import { ImageItem } from "../image/Image" ; import { PickResult } from "../PickHandler" ; import { PoiBuffer } from "../poi/PoiRenderer" ; import { TextElementType } from "./TextElementType" ; /**
 * Additional information for an icon that is to be rendered along with a  TextElement .
 *  internal export interface PoiInfo { /**
     * Technique defining the POI or LineMarker
     */ technique : PoiTechnique | LineMarkerTechnique ; /**
     * Name of the  {@link @here/harp-datasource-protocol#ImageTexture} or image in
     *  {@link @here/harp-mapview#userImageCache} .
      imageTextureName ? : string ; see {@link @here/harp-datasource-protocol#MarkerTechniqueParams.iconColor} ;
      iconColor ? : THREE . Color ; see {@link @here/harp-datasource-protocol#MarkerTechniqueParams.iconBrightness} ;
      iconBrightness ? : number ; /**
     * Name of the POI table  PoiTable .
      poiTableName ? : string ; /**
     * Name of the POI description in the  PoiTable .
      poiName ? : string ; /**
     * Specify stack mode. Defaults to `ShowInStack`.
     */ stackMode ? : PoiStackMode ; /**
     * Minimum zoomLevel at which to display the label icon. No default.
     */ iconMinZoomLevel ? : number ; /**
     * Maximum zoomLevel at which to display the label icon. No default.
     */ iconMaxZoomLevel ? : number ; /**
     * Minimum zoomLevel at which to display the label text. No default.
     */ textMinZoomLevel ? : number ; /**
     * Maximum zoomLevel at which to display the label text. No default.
     */ textMaxZoomLevel ? : number ; /**
     * If true, the text icon will appear even if the text part is blocked by other labels. Defaults
     * to `false`.
     */ textIsOptional ? : boolean ; /**
     * If true, the text will appear even if the icon is blocked by other labels or if it cannot be
     * rendered because of missing icon graphics. Defaults to `false`.
     */ iconIsOptional ? : boolean ; /**
     * If `true`, icon is allowed to overlap other labels or icons of lower priority.
     */ mayOverlap ? : boolean ; /**
     * If `true`, icon will reserve screen space, other markers of lower priority will not be
     * able to overlap.
     */ reserveSpace ? : boolean ; /**
     * If isValid is `false`, the icon will no longer be placed or rendered. The reason may be a
     * missing resource. Defaults to `false`.
     */ isValid ? : boolean ; /**
     * Reference back to owning  TextElement .
      textElement : TextElement ; hidden renderTextDuringMovements ? : boolean ; hidden Direct access to  ImageItem once it is resolved or `null` if not resolvable.
      imageItem ? : ImageItem | null ; hidden Direct access to  {@link @here/harp-datasource-protocol#ImageTexture} once it is resolved.
      imageTexture ? : ImageTexture ; hidden shieldGroupIndex ? : number ; hidden buffer ? : PoiBuffer ; hidden computedWidth ? : number ; hidden computedHeight ? : number ; hidden uvBox ? : Math2D . UvBox ; hidden Computed from owning  TextElement . Value is set when `PoiInfo` is assigned to
     *  TextElement .
      renderOrder ? : number ; } param poiInfo internal export function poiIsRenderable ( poiInfo ) { return poiInfo . buffer !== undefined ; } export interface TextPickResult extends PickResult { /**
     * Text of the picked  TextElement text ? : string ; } /**
 * State of loading.
 */ export enum LoadingState { Requested , Loaded , Initialized } internal export class TextElement { /**
     * Text elements with this priority are placed on screen before any others.
     */ static readonly HIGHEST_PRIORITY = Number . MAX_SAFE_INTEGER ; /**
     * Determines visibility. If set to `false`, it will not be rendered.
     */ visible : boolean = true ; /**
     * Determines minimum zoom level for visibility. Can be used to reduce the number of visible
     * `TextElement`s based on zoom level.
     */ minZoomLevel ? : number ; /**
     * Determines maximum zoom level for visibility. Can be used to reduce the number of visible
     * `TextElement`s based on zoom level.
     */ maxZoomLevel ? : number ; default mayOverlap ? : boolean ; default reserveSpace ? : boolean ; default alwaysOnTop ? : boolean ; /**
     * Ignore distance limit. Used for label in labeled-icons.
     */ ignoreDistance ? : boolean ; /**
     * Scaling factor of text. Defaults to 0.5, reducing the size ot 50% in the distance.
     */ distanceScale : number = 0.5 ; /**
     * Optional user data. Will be retrieved during picking.
     */ userData ? : any ; /**
     * If specified, determines the render order between `TextElement`s. The number different
     * renderOrders should be as small as possible, because every specific `renderOrder` may result
     * in one or more draw calls.
     *
     * TextElements with the same integer `renderOrder` will be rendered in the same batch.
     *
     * The `renderOrder` of `TextElement`s are only relative to other `TextElement`s, and not other
     * map elements.
     *
     * A `TextElement` with a higher `renderOrder` will be rendered after a `TextElement` with a
     * lower `renderOrder`.
     */ renderOrder : number = 0 ; /**
     * Specified kind of geometry. One kind is set as default in the technique, and can be
     * overridden in the style.
     */ kind ? : GeometryKind | GeometryKindSet ; hidden loadingState ? : LoadingState ; /**
     * If set to `true` the geometry has been already overlaid on elevation.
     */ elevated : boolean = false ; hidden Array storing the style  {@link @here/harp-text-canvas#GlyphData} for
     * this `TextElement` to speed up label placement in
     *  TextElementsRenderer . Valid after `loadingState` is `Initialized`.
      glyphs ? : GlyphData [ ] ; hidden Array storing the casing (`true`: uppercase, `false`: lowercase)
     * for this `TextElement`.
     * Used by labels in  TextElementsRenderer to support
     * `SmallCaps`. Valid after `loadingState`
     * is `Initialized`.
      glyphCaseArray ? : boolean [ ] ; remarks Used by point labels in  TextElementsRenderer .
     * Valid after `loadingState` is `Initialized`.
      bounds ? : THREE . Box2 ; hidden Pre-computed text vertex buffer. Used by point labels in  TextElementsRenderer . Valid
     * after label becomes visible for the first time.
      textBufferObject ? : TextBufferObject ; hidden dbgPathTooSmall ? : boolean ; pathLengthSqr ? : number ; default textFadeTime ? : number ; type : TextElementType ; private m_poiInfo ? : PoiInfo ; private m_renderStyle ? : TextRenderStyle ; private m_layoutStyle ? : TextLayoutStyle ; param text param points param renderParams param layoutParams param priority param xOffset param yOffset param featureId - Optional string to identify feature (originated from  DataSource ).
     *                  Number ids are deprecated in favor of strings.
     *  param fadeNear param fadeFar param offsetDirection constructor ( readonly text , readonly points , readonly renderParams , readonly layoutParams , public priority = 0 , public xOffset = 0 , public yOffset = 0 , public featureId ? , public style ? , public fadeNear ? , public fadeFar ? , readonly tileOffset ? , readonly offsetDirection ? , readonly dataSourceName ? , readonly dataSourceOrder ? ) { if ( renderParams instanceof TextRenderStyle ) { this . renderStyle = renderParams ; } if ( layoutParams instanceof TextLayoutStyle ) { this . layoutStyle = layoutParams ; } this . type = points instanceof THREE . Vector3 ? TextElementType . PoiLabel : TextElementType . PathLabel ; } /**
     * The text element position or the first point of the path used to render a curved text, both
     * in world space.
     */ get position ( ) : THREE . Vector3 { if ( this . points instanceof Array ) { const p = this . points [ 0 ] ; return p ; } return this . points as THREE . Vector3 ; } /**
     * The list of points in world space used to render the text along a path or `undefined`.
     */ get path ( ) : THREE . Vector3 [ ] | undefined { if ( this . points instanceof Array ) { return this . points ; } return undefined ; } default get textMayOverlap ( ) : boolean { return this . mayOverlap === true ; } set textMayOverlap ( mayOverlap ) { this . mayOverlap = mayOverlap ; } default get textReservesSpace ( ) : boolean { return this . reserveSpace !== false ; } set textReservesSpace ( reserveSpace ) { this . reserveSpace = reserveSpace ; } /**
     * Contains additional information about icon to be rendered along with text.
     */ get poiInfo ( ) : PoiInfo | undefined { return this . m_poiInfo ; } set poiInfo ( poiInfo ) { this . m_poiInfo = poiInfo ; if ( poiInfo !== undefined ) { if ( this . path !== undefined ) { this . type = TextElementType . LineMarker ; } const poiRenderOrder = this . renderOrder !== undefined ? this . renderOrder : 0 ; poiInfo . renderOrder = poiRenderOrder ; } } returns get renderStyle ( ) : TextRenderStyle | undefined { return this . m_renderStyle ; } param style set renderStyle ( style ) { this . m_renderStyle = style ; } returns get layoutStyle ( ) : TextLayoutStyle | undefined { return this . m_layoutStyle ; } param style set layoutStyle ( style ) { this . m_layoutStyle = style ; } returns hasFeatureId ( ) { if ( this . featureId === undefined ) { return false ; } if ( typeof this . featureId === "number" ) { return this . featureId !== 0 ; } return this . featureId . length > 0 ; } /**
     * Disposes of any allocated resources.
     */ dispose ( ) { const poiBuffer = this . poiInfo ?. buffer ; if ( poiBuffer ) { poiBuffer . decreaseRefCount ( ) ; } } }