如何将Mapbox的Expression.get()结果转换为适合fillColor()的颜色?

时间:2019-02-21 22:57:38

标签: mapbox-android

以下代码似乎未应用我的JSON文件中的fillColorProp的值

JSON内容

"fillColorProp": "#FF0000"

Java

import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillColor;
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
// ...
FillLayer fillLayer = new FillLayer("abc123", source.getId()).withProperties(
                fillColor(get("fillColorProp"))
        );

我试图通过几种不同的方法来转换属性的类型,但是找不到可以编译的语法:

fillColor(color(literal(get("fillColorProp"))));
fillColor(Color.parseColor(literal(get("fillColorProp"))));

如何正确将Mapbox的Android Expression.get()的结果转换为适合作为参数传递给PropertyFactory.fillColor()PropertyFactory.lineColor()等的颜色?

1 个答案:

答案 0 :(得分:0)

Expression.toColor()似乎有效:

import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillColor;
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
import static com.mapbox.mapboxsdk.style.expressions.Expression.toColor;
// ...
fillColor(toColor(get("fillColor")))