Skip to content

Commit

Permalink
feat: support styling color & show for 3dtiles model (#599)
Browse files Browse the repository at this point in the history
* feat: add color show style for model

* refactor: do not convert boolean
  • Loading branch information
airslice authored Apr 6, 2023
1 parent d557958 commit a82ca24
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/core/engines/Cesium/Feature/Tileset/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,18 @@ type CachedFeature = {

const MAX_NUMBER_OF_CONCURRENT_COMPUTING_FEATURES = 5000;

type StyleProperty<N = string> = { name: N; convert?: "color" | "vec2" | "vec4" };
type StyleProperty<N = string> = {
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" },
];
Expand All @@ -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;
Expand Down Expand Up @@ -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 };
}, {}),
);
Expand Down

0 comments on commit a82ca24

Please sign in to comment.