From a82ca240149ef76ded7be6638dd67f76dcec8a26 Mon Sep 17 00:00:00 2001 From: lby Date: Thu, 6 Apr 2023 14:53:18 +0800 Subject: [PATCH] feat: support styling color & show for 3dtiles model (#599) * feat: add color show style for model * refactor: do not convert boolean --- src/core/engines/Cesium/Feature/Tileset/hooks.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/engines/Cesium/Feature/Tileset/hooks.ts b/src/core/engines/Cesium/Feature/Tileset/hooks.ts index ee443a9b2f..c7b15ac476 100644 --- a/src/core/engines/Cesium/Feature/Tileset/hooks.ts +++ b/src/core/engines/Cesium/Feature/Tileset/hooks.ts @@ -95,13 +95,18 @@ type CachedFeature = { const MAX_NUMBER_OF_CONCURRENT_COMPUTING_FEATURES = 5000; -type StyleProperty = { name: N; convert?: "color" | "vec2" | "vec4" }; +type StyleProperty = { + name: N; + convert?: "color" | "colorFunctionString" | "vec2" | "vec4"; +}; const COMMON_STYLE_PROPERTIES: StyleProperty<"color" | "show">[] = [ { name: "color", convert: "color" }, { name: "show" }, ]; -const MODEL_STYLE_PROPERTIES: StyleProperty<"pointSize" | "meta">[] = [ +const MODEL_STYLE_PROPERTIES: StyleProperty<"color" | "show" | "pointSize" | "meta">[] = [ + { name: "color", convert: "colorFunctionString" }, + { name: "show" }, { name: "pointSize" }, { name: "meta" }, ]; @@ -119,6 +124,8 @@ const TILESET_APPEARANCE_FIELDS: (keyof Cesium3DTilesAppearance)[] = [ const convertStyle = (val: any, convert: StyleProperty["convert"]) => { if (convert === "color") { return toColor(val); + } else if (convert === "colorFunctionString") { + return `color("${val}")`; } return val; @@ -171,7 +178,7 @@ const useFeature = ({ // TODO: Convert value if it's necessary MODEL_STYLE_PROPERTIES.reduce((res, { name, convert }) => { const val = convertStyle(style?.[name as keyof typeof style], convert); - if (!val) return res; + if (val === undefined) return res; return { ...res, [name]: val }; }, {}), );