import { Env } from "../Env" ; import { CallExpr , ExprScope } from "../Expr" ; import { ExprEvaluatorContext , OperatorDescriptorMap } from "../ExprEvaluator" ; const operators = { "geometry-type" : { call : ( context , call ) => { const geometryType = context . env . lookup ( "$geometryType" ) ; switch ( geometryType ) { case "point" : return "Point" ; case "line" : return "LineString" ; case "polygon" : return "Polygon" ; default : return null ; } } } , "feature-state" : { isDynamicOperator : ( ) => true , call : ( context , call ) => { if ( context . scope !== ExprScope . Dynamic ) { throw new Error ( "feature-state cannot be used in this context" ) ; } const property = context . evaluate ( call . args [ 0 ] ) ; if ( typeof property !== "string" ) { throw new Error ( `expected the name of the property of the feature state` ) ; } const state = context . env . lookup ( "$state" ) ; if ( Env . isEnv ( state ) ) { return state . lookup ( property ) ?? null ; } else if ( state instanceof Map ) { return state . get ( property ) ?? null ; } return null ; } } , id : { call : ( context , call ) => { return context . env . lookup ( "$id" ) ?? null ; } } } ; export const FeatureOperators = operators ; export type FeatureOperatorNames = keyof typeof operators ;