import { Expr , JsonExpr } from "./Expr" ; import { InterpolatedPropertyDefinition } from "./InterpolatedPropertyDefs" ; import { BaseTechniqueParams , BasicExtrudedLineTechniqueParams , ExtrudedPolygonTechniqueParams , FillTechniqueParams , isTextureBuffer , LineTechniqueParams , MarkerTechniqueParams , PointTechniqueParams , SegmentsTechniqueParams , ShaderTechniqueParams , SolidLineTechniqueParams , StandardExtrudedLineTechniqueParams , StandardTechniqueParams , TerrainTechniqueParams , TextTechniqueParams , TextureCoordinateType } from "./TechniqueParams" ; import { StylePriority } from "./Theme" ; internal export const TEXTURE_PROPERTY_KEYS = [ "map" , "normalMap" , "displacementMap" , "roughnessMap" , "emissiveMap" , "alphaMap" , "metalnessMap" , "bumpMap" ] ; type RemoveInterpolatedPropDef < T > = T | InterpolatedPropertyDefinition < any > extends T ? Exclude < T , InterpolatedPropertyDefinition < any > > : T ; type RemoveJsonExpr < T > = T | JsonExpr extends T ? Exclude < T , JsonExpr > : T ; /**
 * Make runtime representation of technique attributes from JSON-compatible typings.
 *
 * Translates
 *  - InterpolatedPropertyDefinition -> InterpolatedProperty
 *  - JsonExpr -> Expr
 */ export type MakeTechniqueAttrs < T > = { [ P in keyof T ] : T [ P ] | JsonExpr extends T [ P ] ? RemoveInterpolatedPropDef < RemoveJsonExpr < T [ P ] > > | Expr : T [ P ] ; } ; /**
 * Possible techniques that can be used to draw a geometry on the map.
 */ export type Technique = SquaresTechnique | CirclesTechnique | PoiTechnique | LineMarkerTechnique | LineTechnique | SegmentsTechnique | SolidLineTechnique | FillTechnique | StandardTechnique | TerrainTechnique | BasicExtrudedLineTechnique | StandardExtrudedLineTechnique | ExtrudedPolygonTechnique | ShaderTechnique | TextTechnique | LabelRejectionLineTechnique ; /**
 * Runtime representation of `SquaresStyle` as parsed by `StyleSetEvaluator`.
 * For technique parameters see `PointTechniqueParams`.
 */ export interface SquaresTechnique extends MakeTechniqueAttrs < PointTechniqueParams > { name : "squares" ; } /**
 * Runtime representation of `CirclesStyle` as parsed by `StyleSetEvaluator`.
 * For technique parameters see `PointTechniqueParams`.
 */ export interface CirclesTechnique extends MakeTechniqueAttrs < PointTechniqueParams > { name : "circles" ; } /**
 * Runtime representation of `PoiStyle` as parsed by `StyleSetEvaluator`.
 * For technique parameters see `MarkerTechniqueParams`.
 */ export interface PoiTechnique extends MakeTechniqueAttrs < MarkerTechniqueParams > { name : "labeled-icon" ; } /**
 * Runtime representation of `LineMarkerStyle` as parsed by `StyleSetEvaluator`.
 * For technique parameters see `MarkerTechniqueParams`.
 */ export interface LineMarkerTechnique extends MakeTechniqueAttrs < MarkerTechniqueParams > { name : "line-marker" ; } /**
 * Runtime representation of `SegmentsStyle` as parsed by `StyleSetEvaluator`.
 * For technique parameters see `SegmentsTechniqueParams`.
 */ export interface SegmentsTechnique extends MakeTechniqueAttrs < SegmentsTechniqueParams > { name : "segments" ; } /**
 * Runtime representation of `BasicExtrudedLineStyle` as parsed by `StyleSetEvaluator`.
 * For technique parameters see `BasicExtrudedLineTechniqueParams`.
 */ export interface BasicExtrudedLineTechnique extends MakeTechniqueAttrs < BasicExtrudedLineTechniqueParams > { name : "extruded-line" ; } /**
 * Runtime representation of `StandardExtrudedLineStyle` as parsed by `StyleSetEvaluator`.
 * For technique parameters see `StandardExtrudedLineTechniqueParams`.
 */ export interface StandardExtrudedLineTechnique extends MakeTechniqueAttrs < StandardExtrudedLineTechniqueParams > { name : "extruded-line" ; } /**
 * Runtime representation of `SolidLineStyle` as parsed by `StyleSetEvaluator`.
 * For technique parameters see `SolidLineTechniqueParams`.
 */ export interface SolidLineTechnique extends MakeTechniqueAttrs < SolidLineTechniqueParams > { name : "solid-line" | "dashed-line" ; } /**
 * Runtime representation of `LineStyle` as parsed by `StyleSetEvaluator`.
 * For technique parameters see `LineTechniqueParams`.
 */ export interface LineTechnique extends MakeTechniqueAttrs < LineTechniqueParams > { name : "line" ; } /**
 * Runtime representation of `FillStyle` as parsed by `StyleSetEvaluator`.
 * For technique parameters see `FillTechniqueParams`.
 */ export interface FillTechnique extends MakeTechniqueAttrs < FillTechniqueParams > { name : "fill" ; } /**
 * Technique used to render a mesh geometry.
 * For technique parameters see `StandardTechniqueParams`.
 */ export interface StandardTechnique extends MakeTechniqueAttrs < StandardTechniqueParams > { name : "standard" ; } /**
 * Runtime representation of `ExtrudedPolygonStyle` as parsed by `StyleSetEvaluator`.
 * For technique parameters see `ExtrudedPolygonTechniqueParams`.
 */ export interface ExtrudedPolygonTechnique extends MakeTechniqueAttrs < ExtrudedPolygonTechniqueParams > { name : "extruded-polygon" ; } /**
 * Runtime representation of `TextStyle` as parsed by `StyleSetEvaluator`.
 * For technique parameters see `TextTechniqueParams`.
 */ export interface TextTechnique extends MakeTechniqueAttrs < TextTechniqueParams > { name : "text" ; } /**
 * Special technique for user-defined shaders.
 * For technique parameters see `ShaderTechniqueParams`.
 */ export interface ShaderTechnique extends MakeTechniqueAttrs < ShaderTechniqueParams > { name : "shader" ; } /**
 * Technique used to render a terrain geometry with textures.
 * For technique parameters see `TerrainTechniqueParams`.
 */ export interface TerrainTechnique extends MakeTechniqueAttrs < TerrainTechniqueParams > { name : "terrain" ; } /**
 * Technique to avoid label rendering on top of certain line geometries.
 * For technique parameters see `BaseTechniqueParams`.
 */ export interface LabelRejectionLineTechnique extends MakeTechniqueAttrs < BaseTechniqueParams > { name : "label-rejection-line" ; } internal export const TRANSPARENCY_PROPERTY_KEYS = [ "opacity" , "transparent" ] ; /**
 * Additional params used for optimized usage of `Techniques`.
 */ export interface IndexedTechniqueParams { hidden _index : number ; hidden _styleSetIndex : number ; hidden _styleSet ? : string ; hidden _category ? : string ; hidden _secondaryCategory ? : string ; hidden _usesFeatureState ? : boolean ; /**
     * Last computed state derived from [[Technique.kind]].
     */ _kindState ? : boolean ; } /**
 * For efficiency, `StyleSetEvaluator` returns `Techniques` additional params as defined in
 * `IndexedTechniqueParams`.
 */ export type IndexedTechnique = Technique & IndexedTechniqueParams ; /**
 * Type guard to check if an object is an instance of `CirclesTechnique`.
 */ export function isCirclesTechnique ( technique ) { return technique . name === "circles" ; } /**
 * Type guard to check if an object is an instance of `SquaresTechnique`.
 */ export function isSquaresTechnique ( technique ) { return technique . name === "squares" ; } /**
 * Type guard to check if an object is an instance of `PoiTechnique`.
 */ export function isPoiTechnique ( technique ) { return technique . name === "labeled-icon" ; } /**
 * Type guard to check if an object is an instance of `LineMarkerTechnique`.
 */ export function isLineMarkerTechnique ( technique ) { return technique . name === "line-marker" ; } /**
 * Type guard to check if an object is an instance of `LineTechnique`.
 */ export function isLineTechnique ( technique ) { return technique . name === "line" ; } /**
 * Type guard to check if an object is an instance of `SolidLineTechnique`.
 */ export function isSolidLineTechnique ( technique ) { return technique . name === "solid-line" || technique . name === "dashed-line" ; } note export function isSpecialDashesLineTechnique ( technique ) { return ( ( technique . name === "solid-line" || technique . name === "dashed-line" ) && technique . dashes !== undefined && technique . dashes !== "Square" ) ; } /**
 * Type guard to check if an object is an instance of `SegmentsTechnique`.
 */ export function isSegmentsTechnique ( technique ) { return technique . name === "segments" ; } /**
 * Type guard to check if an object is an instance of `BasicExtrudedLineTechnique`
 * or `StandardExtrudedLineTechnique`.
 */ export function isExtrudedLineTechnique ( technique ) { return technique . name === "extruded-line" ; } /**
 * Type guard to check if an object is an instance of `BasicExtrudedLineTechnique`.
 */ export function isBasicExtrudedLineTechnique ( technique ) { return isExtrudedLineTechnique ( technique ) && technique . shading === "basic" ; } /**
 * Type guard to check if an object is an instance of `StandardExtrudedLineTechnique`.
 */ export function isStandardExtrudedLineTechnique ( technique ) { return isExtrudedLineTechnique ( technique ) && technique . shading === "standard" ; } /**
 * Type guard to check if an object is an instance of `FillTechnique`.
 */ export function isFillTechnique ( technique ) { return technique . name === "fill" ; } /**
 * Type guard to check if an object is an instance of `ExtrudedPolygonTechnique`.
 */ export function isExtrudedPolygonTechnique ( technique ) { return technique . name === "extruded-polygon" ; } /**
 * Type guard to check if an object is an instance of `StandardTechnique`.
 */ export function isStandardTechnique ( technique ) { return technique . name === "standard" ; } /**
 * Type guard to check if an object is an instance of `TerrainTechnique`.
 */ export function isTerrainTechnique ( technique ) { return technique . name === "terrain" ; } /**
 * Type guard to check if an object is an instance of `TextTechnique`.
 */ export function isTextTechnique ( technique ) { return technique . name === "text" ; } /**
 * Type guard to check if an object is an instance of `ShaderTechnique`.
 */ export function isShaderTechnique ( technique ) { return technique . name === "shader" ; } export function isLabelRejectionLineTechnique ( technique ) { return technique . name === "label-rejection-line" ; } param technique export function needsVertexNormals ( technique ) { return ( isExtrudedPolygonTechnique ( technique ) || isFillTechnique ( technique ) || isStandardTechnique ( technique ) || isTerrainTechnique ( technique ) || isStandardExtrudedLineTechnique ( technique ) ) ; } /**
 * Type guard to check if an object is an instance of a technique with textures.
 */ export function supportsTextures ( technique ) { return ( isFillTechnique ( technique ) || isStandardTechnique ( technique ) || isExtrudedPolygonTechnique ( technique ) || isTerrainTechnique ( technique ) ) ; } /**
 * Get the texture coordinate type if the technique supports it.
 */ export function textureCoordinateType ( technique ) { return supportsTextures ( technique ) || isShaderTechnique ( technique ) ? technique . textureCoordinateType : undefined ; } /**
 * Add all the buffers of the technique to the transfer list.
 */ export function addBuffersToTransferList ( technique , transferList ) { if ( isStandardTechnique ( technique ) || isExtrudedPolygonTechnique ( technique ) || isTerrainTechnique ( technique ) ) { for ( const texturePropertyKey of TEXTURE_PROPERTY_KEYS ) { const textureProperty = ( technique as any ) [ texturePropertyKey ] ; if ( isTextureBuffer ( textureProperty ) ) { if ( textureProperty . buffer instanceof ArrayBuffer ) { transferList . push ( textureProperty . buffer ) ; } } } } } param imageName param technique returns export function composeTechniqueTextureName ( imageName , technique ) { let textureName = imageName ; if ( typeof technique . imageTexturePrefix === "string" ) { textureName = technique . imageTexturePrefix + textureName ; } if ( typeof technique . imageTexturePostfix === "string" ) { textureName = textureName + technique . imageTexturePostfix ; } return textureName ; } param technique- param theme export function setTechniqueRenderOrderOrPriority ( technique , priorities , labelPriorities ) { if ( isTextTechnique ( technique ) || isPoiTechnique ( technique ) || isLineMarkerTechnique ( technique ) ) { if ( labelPriorities && typeof technique . _category === "string" ) { const priority = labelPriorities . indexOf ( technique . _category ) ; if ( priority !== - 1 ) { technique . priority = labelPriorities . length - priority ; } } } else if ( priorities && technique . _styleSet !== undefined ) { const computeRenderOrder = ( category ) : number | undefined => { const priority = priorities ?. findIndex ( entry => entry . group === technique . _styleSet && entry . category === category ) ; return priority !== undefined && priority !== - 1 ? ( priority + 1 ) * 10 : undefined ; } ; if ( typeof technique . _category === "string" ) { const renderOrder = computeRenderOrder ( technique . _category ) ; if ( renderOrder !== undefined ) { technique . renderOrder = renderOrder ; } } if ( typeof technique . _secondaryCategory === "string" ) { const secondaryRenderOrder = computeRenderOrder ( technique . _secondaryCategory ) ; if ( secondaryRenderOrder !== undefined ) { ( technique as any ) . secondaryRenderOrder = secondaryRenderOrder ; } } } }