Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback for Color.fromCssColorString #5174

Merged
merged 2 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Change Log
### MobX Development

#### next release (8.0.0-alpha.66)
* Add fallback colours when Color.fromCssColorString is used.
* Allow nullable `timeColumn` in table styles. Useful for turning off auto-detection of time columns.
* Added tool for searching inside catalog items. Initial implementation works for indexed 3d tilesets.
* Added support for shapefile with `ShapefileCatalogItem`
Expand Down
4 changes: 2 additions & 2 deletions lib/ModelMixins/GeojsonMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ export default function GeoJsonMixin<
color.alpha = 1;
return color;
} else {
return Color.fromCssColorString(colorString);
return Color.fromCssColorString(colorString) ?? Color.GRAY;
}
}

function getColor(color: String | string | Color): Color {
if (typeof color === "string" || color instanceof String) {
return Color.fromCssColorString(color.toString());
return Color.fromCssColorString(color.toString()) ?? Color.GRAY;
} else {
return color;
}
Expand Down
27 changes: 16 additions & 11 deletions lib/Models/GlobeOrMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export default abstract class GlobeOrMap {

if (isDefined(feature._cesium3DTileFeature)) {
const originalColor = feature._cesium3DTileFeature.color;
const defaultColor = Color.fromCssColorString("#fffffe");

// Get the highlight color from the catalogItem trait or default to baseMapContrastColor
const catalogItem = feature._catalogItem;
Expand All @@ -178,11 +179,13 @@ export default abstract class GlobeOrMap {
catalogItem instanceof Cesium3DTilesCatalogItem &&
catalogItem.highlightColor
) {
highlightColor = Color.fromCssColorString(catalogItem.highlightColor);
highlightColor =
Color.fromCssColorString(catalogItem.highlightColor) ??
defaultColor;
} else {
highlightColor = Color.fromCssColorString(
this.terria.baseMapContrastColor
);
highlightColor =
Color.fromCssColorString(this.terria.baseMapContrastColor) ??
defaultColor;
}

// highlighting doesn't work if the highlight colour is full white
Expand All @@ -191,7 +194,7 @@ export default abstract class GlobeOrMap {
highlightColor,
Color.WHITE
)
? Color.fromCssColorString("#fffffe")
? defaultColor
: highlightColor;

this._removeHighlightCallback = function() {
Expand All @@ -213,12 +216,14 @@ export default abstract class GlobeOrMap {

cesiumPolygon.polygon!.outline = new ConstantProperty(true);
cesiumPolygon.polygon!.outlineColor = new ConstantProperty(
Color.fromCssColorString(this.terria.baseMapContrastColor)
Color.fromCssColorString(this.terria.baseMapContrastColor) ??
Color.GRAY
);
cesiumPolygon.polygon!.material = new ColorMaterialProperty(
new ConstantProperty(
Color.fromCssColorString(
this.terria.baseMapContrastColor
(
Color.fromCssColorString(this.terria.baseMapContrastColor) ??
Color.LIGHTGRAY
).withAlpha(0.75)
)
);
Expand All @@ -238,9 +243,9 @@ export default abstract class GlobeOrMap {
const polylineMaterial = cesiumPolyline.polyline!.material;
const polylineWidth = cesiumPolyline.polyline!.width;

(<any>cesiumPolyline).polyline.material = Color.fromCssColorString(
this.terria.baseMapContrastColor
);
(<any>cesiumPolyline).polyline.material =
Color.fromCssColorString(this.terria.baseMapContrastColor) ??
Color.LIGHTGRAY;
cesiumPolyline.polyline!.width = new ConstantProperty(2);

this._removeHighlightCallback = function() {
Expand Down
Loading