import { BaseTechniqueParams , PointTechniqueParams , PolygonalTechniqueParams } from "./TechniqueParams" ; import { CirclesTechnique , ExtrudedPolygonTechnique , FillTechnique , IndexedTechnique , LineMarkerTechnique , LineTechnique , ShaderTechnique , SolidLineTechnique , SquaresTechnique , StandardTechnique , Technique , TextTechnique } from "./Techniques" ; export enum AttrScope { remarks FeatureGeometry , remarks TechniqueGeometry , remarks TechniqueRendering } /**
 * Extract  property names from `Technique`-like interface (excluding `name`) as union of string
 * literals.
 *
 * TechniquePropName<Base
 *
 */ type TechniquePropNames < T > = T extends { name : any ; } ? keyof Omit < T , "name" > : keyof T ; interface AttrDescriptor { /**
     * The evaluation scope of this attribute.
     */ scope ? : AttrScope ; remarks automatic ? : boolean ; } type TechniqueAttrDescriptors < T > = { [ P in TechniquePropNames < T > ] ? : AttrScope | AttrDescriptor ; } ; export interface TechniqueDescriptor < T = Technique > { attrTransparencyColor ? : string ; attrDescriptors : TechniqueAttrDescriptors < T > ; } type OneThatMatches < T , P > = T extends P ? T : never ; type TechniqueByName < K extends Technique [ "name" ] > = OneThatMatches < Technique , { name : K ; } > ; type TechniqueDescriptorRegistry = { [ P in Technique [ "name" ] ] ? : TechniqueDescriptor < TechniqueByName < P > > ; } ; internal function mergeTechniqueDescriptor < T > ( ... descriptors ) { const result = { attrDescriptors : { } } ; for ( const descriptor of descriptors ) { if ( descriptor . attrTransparencyColor !== undefined ) { result . attrTransparencyColor = descriptor . attrTransparencyColor ; } if ( descriptor . attrDescriptors !== undefined ) { result . attrDescriptors = { ... result . attrDescriptors , ... descriptor . attrDescriptors } ; } } return result ; } const baseTechniqueParamsDescriptor = { attrTransparencyColor : "color" , attrDescriptors : { constantHeight : AttrScope . FeatureGeometry , enabled : AttrScope . FeatureGeometry , fadeFar : AttrScope . TechniqueRendering , fadeNear : AttrScope . TechniqueRendering , transparent : { scope : AttrScope . TechniqueRendering , automatic : true } , side : { scope : AttrScope . TechniqueRendering , automatic : true } } } ; const pointTechniquePropTypes = mergeTechniqueDescriptor < PointTechniqueParams > ( baseTechniqueParamsDescriptor , { attrDescriptors : { color : { scope : AttrScope . TechniqueRendering , automatic : true } , size : { scope : AttrScope . TechniqueRendering , automatic : true } , opacity : { scope : AttrScope . TechniqueRendering , automatic : true } } } ) ; const squaresTechniquePropTypes = mergeTechniqueDescriptor < SquaresTechnique > ( baseTechniqueParamsDescriptor , pointTechniquePropTypes ) ; const circlesTechniquePropTypes = mergeTechniqueDescriptor < CirclesTechnique > ( baseTechniqueParamsDescriptor , pointTechniquePropTypes ) ; const lineMarkerTechniquePropTypes = mergeTechniqueDescriptor < LineMarkerTechnique > ( baseTechniqueParamsDescriptor , { attrDescriptors : { text : AttrScope . FeatureGeometry , label : AttrScope . FeatureGeometry , useAbbreviation : AttrScope . FeatureGeometry , useIsoCode : AttrScope . FeatureGeometry , poiName : AttrScope . FeatureGeometry , imageTexture : AttrScope . FeatureGeometry , iconColor : AttrScope . TechniqueRendering , iconBrightness : AttrScope . TechniqueRendering , backgroundColor : AttrScope . TechniqueRendering , backgroundSize : AttrScope . TechniqueRendering , backgroundOpacity : AttrScope . TechniqueRendering , color : AttrScope . TechniqueRendering , opacity : AttrScope . TechniqueRendering , size : AttrScope . TechniqueRendering } } ) ; const polygonalTechniqueDescriptor = { attrDescriptors : { polygonOffset : { scope : AttrScope . TechniqueRendering , automatic : true } , polygonOffsetFactor : { scope : AttrScope . TechniqueRendering , automatic : true } , polygonOffsetUnits : { scope : AttrScope . TechniqueRendering , automatic : true } , depthTest : { scope : AttrScope . TechniqueRendering , automatic : true } , transparent : { scope : AttrScope . TechniqueRendering , automatic : true } , opacity : { scope : AttrScope . TechniqueRendering , automatic : true } , color : { scope : AttrScope . TechniqueRendering , automatic : true } , lineColor : AttrScope . TechniqueRendering , lineFadeFar : AttrScope . TechniqueRendering , lineFadeNear : AttrScope . TechniqueRendering } } ; const solidLineTechniqueDescriptor = mergeTechniqueDescriptor < SolidLineTechnique > ( baseTechniqueParamsDescriptor , polygonalTechniqueDescriptor , { attrDescriptors : { lineWidth : AttrScope . TechniqueRendering , secondaryWidth : AttrScope . TechniqueRendering , secondaryColor : AttrScope . TechniqueRendering , dashSize : AttrScope . TechniqueRendering , gapSize : AttrScope . TechniqueRendering , outlineColor : { scope : AttrScope . TechniqueRendering , automatic : true } , caps : { scope : AttrScope . TechniqueRendering , automatic : true } , drawRangeStart : { scope : AttrScope . TechniqueRendering , automatic : true } , drawRangeEnd : { scope : AttrScope . TechniqueRendering , automatic : true } , dashes : { scope : AttrScope . TechniqueRendering , automatic : true } , dashColor : { scope : AttrScope . TechniqueRendering , automatic : true } } } ) ; const lineTechniqueDescriptor = mergeTechniqueDescriptor < LineTechnique > ( baseTechniqueParamsDescriptor , { attrDescriptors : { color : { scope : AttrScope . TechniqueRendering , automatic : true } , opacity : { scope : AttrScope . TechniqueRendering , automatic : true } , lineWidth : AttrScope . FeatureGeometry } } ) ; const fillTechniqueDescriptor = mergeTechniqueDescriptor < FillTechnique > ( baseTechniqueParamsDescriptor , polygonalTechniqueDescriptor , { attrDescriptors : { wireframe : { scope : AttrScope . TechniqueRendering , automatic : true } , color : { scope : AttrScope . TechniqueRendering , automatic : true } , opacity : { scope : AttrScope . TechniqueRendering , automatic : true } , transparent : { scope : AttrScope . TechniqueRendering , automatic : true } , lineWidth : AttrScope . TechniqueRendering , map : { scope : AttrScope . TechniqueRendering , automatic : true } } } ) ; const standardTechniqueDescriptor = mergeTechniqueDescriptor < StandardTechnique > ( baseTechniqueParamsDescriptor , { attrDescriptors : { color : { scope : AttrScope . TechniqueRendering , automatic : true } , vertexColors : { scope : AttrScope . TechniqueRendering , automatic : true } , wireframe : { scope : AttrScope . TechniqueRendering , automatic : true } , roughness : { scope : AttrScope . TechniqueRendering , automatic : true } , metalness : { scope : AttrScope . TechniqueRendering , automatic : true } , alphaTest : { scope : AttrScope . TechniqueRendering , automatic : true } , depthTest : { scope : AttrScope . TechniqueRendering , automatic : true } , transparent : { scope : AttrScope . TechniqueRendering , automatic : true } , opacity : { scope : AttrScope . TechniqueRendering , automatic : true } , emissive : { scope : AttrScope . TechniqueRendering , automatic : true } , emissiveIntensity : { scope : AttrScope . TechniqueRendering , automatic : true } , refractionRatio : { scope : AttrScope . TechniqueRendering , automatic : true } , normalMapType : { scope : AttrScope . TechniqueRendering , automatic : true } , map : { scope : AttrScope . TechniqueRendering , automatic : true } , normalMap : { scope : AttrScope . TechniqueRendering , automatic : true } , displacementMap : { scope : AttrScope . TechniqueRendering , automatic : true } , roughnessMap : { scope : AttrScope . TechniqueRendering , automatic : true } , emissiveMap : { scope : AttrScope . TechniqueRendering , automatic : true } , bumpMap : { scope : AttrScope . TechniqueRendering , automatic : true } , metalnessMap : { scope : AttrScope . TechniqueRendering , automatic : true } , alphaMap : { scope : AttrScope . TechniqueRendering , automatic : true } } } ) ; const extrudedPolygonTechniqueDescriptor = mergeTechniqueDescriptor < ExtrudedPolygonTechnique > ( baseTechniqueParamsDescriptor , standardTechniqueDescriptor , { attrDescriptors : { height : AttrScope . FeatureGeometry , floorHeight : AttrScope . FeatureGeometry , color : AttrScope . FeatureGeometry , defaultColor : AttrScope . FeatureGeometry , defaultHeight : AttrScope . FeatureGeometry , boundaryWalls : AttrScope . FeatureGeometry , footprint : AttrScope . FeatureGeometry , maxSlope : AttrScope . FeatureGeometry , animateExtrusion : AttrScope . TechniqueRendering , lineWidth : AttrScope . TechniqueRendering , lineFadeNear : AttrScope . TechniqueRendering , lineFadeFar : AttrScope . TechniqueRendering , lineColor : AttrScope . TechniqueRendering } } ) ; const textTechniqueDescriptor = mergeTechniqueDescriptor < TextTechnique > ( baseTechniqueParamsDescriptor , { attrDescriptors : { text : AttrScope . FeatureGeometry , label : AttrScope . FeatureGeometry , useAbbreviation : AttrScope . FeatureGeometry , useIsoCode : AttrScope . FeatureGeometry , backgroundColor : AttrScope . TechniqueRendering , backgroundSize : AttrScope . TechniqueRendering , backgroundOpacity : AttrScope . TechniqueRendering , color : AttrScope . TechniqueRendering , opacity : AttrScope . TechniqueRendering , priority : AttrScope . TechniqueRendering , size : AttrScope . TechniqueRendering } } ) ; const shaderTechniqueDescriptor = mergeTechniqueDescriptor < ShaderTechnique > ( baseTechniqueParamsDescriptor , { attrDescriptors : { params : AttrScope . TechniqueRendering } } ) ; const techniqueDescriptors = { "extruded-polygon" : extrudedPolygonTechniqueDescriptor , "line-marker" : lineMarkerTechniquePropTypes , "labeled-icon" : lineMarkerTechniquePropTypes , "solid-line" : solidLineTechniqueDescriptor , "dashed-line" : solidLineTechniqueDescriptor , terrain : standardTechniqueDescriptor , standard : standardTechniqueDescriptor , squares : squaresTechniquePropTypes , circles : circlesTechniquePropTypes , line : lineTechniqueDescriptor , segments : lineTechniqueDescriptor , fill : fillTechniqueDescriptor , text : textTechniqueDescriptor , shader : shaderTechniqueDescriptor } ; export function getTechniqueDescriptor ( technique ) { if ( typeof technique !== "string" ) { technique = technique . name ; } return ( techniqueDescriptors as any ) [ technique ] ; } export function getTechniqueAttributeDescriptor ( technique , attrName ) { const techniqueDescriptor = getTechniqueDescriptor ( technique ) ; const attrDescriptors = techniqueDescriptor ?. attrDescriptors ; const descriptor = attrDescriptors ?. [ attrName ] ; if ( typeof descriptor === undefined ) { return undefined ; } else if ( typeof descriptor === "object" ) { return descriptor ; } return { scope : descriptor } ; } const automaticAttributeCache = new Map ( ) ; export function getTechniqueAutomaticAttrs ( technique ) { if ( typeof technique !== "string" ) { technique = technique . name ; } if ( automaticAttributeCache . has ( technique ) ) { return automaticAttributeCache . get ( technique ) ! ; } const descriptors = [ ] ; const attrDescriptors = getTechniqueDescriptor ( technique ) ?. attrDescriptors ; if ( attrDescriptors === undefined ) { return descriptors ; } for ( const attrName in attrDescriptors ) { if ( ! attrDescriptors . hasOwnProperty ( attrName ) ) { continue ; } const descr = attrDescriptors [ attrName ] ; if ( descr === undefined || typeof descr === "number" ) { continue ; } if ( descr . automatic === true ) { descriptors . push ( attrName ) ; } } automaticAttributeCache . set ( technique , descriptors ) ; return descriptors ; }