Skip to content

Commit

Permalink
fix: czml style for marker on reearth/core (#523)
Browse files Browse the repository at this point in the history
* fix: czml style for marker on reearth/core

* fix: default
  • Loading branch information
keiya01 authored Mar 9, 2023
1 parent ecd09aa commit 67dccbd
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 17 deletions.
7 changes: 7 additions & 0 deletions src/core/engines/Cesium/Feature/Resource/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ test("attachProperties()", () => {
fillColor: "red",
shadows: "enabled",
heightReference: "clamp",
outlineColor: "red",
},
};

Expand All @@ -36,13 +37,18 @@ test("attachProperties()", () => {
name: "heightReference",
type: "heightReference",
},
outlineColor: {
name: "strokeColor",
override: "blue",
},
});

expect(mockEntity.polygon).toEqual({
material: toColor("red"),
shadows: shadowMode("enabled"),
heightReference: heightReference("clamp"),
outlineWidth: 100,
outlineColor: "blue",
});
expect(mockEntity.properties.reearth_originalProperties).toEqual({
polygon: {
Expand All @@ -57,6 +63,7 @@ test("attachProperties()", () => {
fillColor: "red",
shadows: "enabled",
heightReference: "clamp",
outlineColor: "red",
},
});
});
30 changes: 26 additions & 4 deletions src/core/engines/Cesium/Feature/Resource/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ export function attachProperties<
[K in keyof Exclude<Entity[PName], undefined>]?: {
name: keyof AppearanceTypes[AName];
type?: AppearancePropertyKeyType;
override?: any;
default?: any;
};
},
) {
const [appearanceName, propertyName] = namePair;
const property = entity[propertyName];
if (!property) {
return;
const property = entity[propertyName] ?? {};
if (!entity[propertyName]) {
entity[propertyName] = {} as any;
}

const tag = getTag(entity);
Expand Down Expand Up @@ -83,7 +85,11 @@ export function attachProperties<
value = heightReference(value);
}

(property as any)[entityPropertyKey] = value ?? (property as any)[entityPropertyKey];
(entity[propertyName] as any)[entityPropertyKey] =
appearancePropertyKey.override ??
value ??
appearancePropertyKey.default ??
(property as any)[entityPropertyKey];
});
}

Expand Down Expand Up @@ -133,10 +139,17 @@ export const attachStyle = (
if (!computedFeature) {
return;
}
const simpleLayer = extractSimpleLayer(layer);
if (point) {
attachProperties(entity, computedFeature, ["marker", "point"], {
show: {
name: "show",
...(simpleLayer?.marker?.style
? {
override:
simpleLayer?.marker?.style === "point" && (simpleLayer?.marker.show ?? true),
}
: {}),
},
pixelSize: {
name: "pointSize",
Expand All @@ -163,6 +176,12 @@ export const attachStyle = (
attachProperties(entity, computedFeature, ["marker", "billboard"], {
show: {
name: "show",
...(simpleLayer?.marker?.style
? {
override:
simpleLayer?.marker?.style === "image" && (simpleLayer?.marker.show ?? true),
}
: {}),
},
image: {
name: "image",
Expand Down Expand Up @@ -193,6 +212,7 @@ export const attachStyle = (
attachProperties(entity, computedFeature, ["marker", "label"], {
show: {
name: "show",
default: true,
},
text: {
name: "labelText",
Expand Down Expand Up @@ -240,6 +260,7 @@ export const attachStyle = (
attachProperties(entity, computedFeature, ["polyline", "polyline"], {
show: {
name: "show",
default: true,
},
width: {
name: "strokeWidth",
Expand Down Expand Up @@ -286,6 +307,7 @@ export const attachStyle = (
attachProperties(entity, computedFeature, ["polygon", "polygon"], {
show: {
name: "show",
default: true,
},
fill: {
name: "fill",
Expand Down
35 changes: 22 additions & 13 deletions src/core/mantle/evaluator/simple/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,30 @@ function hasExpression(e: any): e is ExpressionContainer {
return typeof e === "object" && e && "expression" in e;
}

function evalExpression(expressionContainer: any, layer: LayerSimple, feature?: Feature): unknown {
if (hasExpression(expressionContainer)) {
const styleExpression = expressionContainer.expression;
if (!defined(styleExpression)) {
return undefined;
} else if (typeof styleExpression === "object" && styleExpression.conditions) {
return new ConditionalExpression(styleExpression, feature, layer.defines).evaluate();
} else if (typeof styleExpression === "boolean" || typeof styleExpression === "number") {
return new Expression(String(styleExpression), feature, layer.defines).evaluate();
} else if (typeof styleExpression === "string") {
return new Expression(styleExpression, feature, layer.defines).evaluate();
function evalExpression(
expressionContainer: any,
layer: LayerSimple,
feature?: Feature,
): unknown | undefined {
try {
if (hasExpression(expressionContainer)) {
const styleExpression = expressionContainer.expression;
if (!defined(styleExpression)) {
return undefined;
} else if (typeof styleExpression === "object" && styleExpression.conditions) {
return new ConditionalExpression(styleExpression, feature, layer.defines).evaluate();
} else if (typeof styleExpression === "boolean" || typeof styleExpression === "number") {
return new Expression(String(styleExpression), feature, layer.defines).evaluate();
} else if (typeof styleExpression === "string") {
return new Expression(styleExpression, feature, layer.defines).evaluate();
}
return styleExpression;
}
return styleExpression;
return expressionContainer;
} catch (e) {
console.error(e);
return;
}
return expressionContainer;
}

function evalJsonProperties(layer: LayerSimple, feature: Feature): Feature {
Expand Down

0 comments on commit 67dccbd

Please sign in to comment.