我是Mapbox的新手,想更改所选地图项的颜色。我通过添加新字段“ SELECTED”的Mapbox示例实现了这一点:
//For deselect all
for (Feature feature : featureCollection.features()) {
feature.properties().addProperty("SELECTED", false);
}
Feature feature = featureCollection.features().get(index);
feature.properties().addProperty("SELECTED", true);
现在存在特定字段“ SELETCED”。但是我不能说:如果它是“ true”,则将此颜色用于fillExtrusionColor
,否则使用另一种颜色。
style.addLayer(new FillExtrusionLayer(
activeLayerId, sourceId).withProperties(
fillExtrusionHeight(20f),
fillExtrusionColor(get("FILL_COLOR")),
fillExtrusionOpacity(0.7f)
));
我搜索了一下,发现我应该为此目的使用表达式,但找不到方法!
答案 0 :(得分:0)
有两种方法可以完成您要问的事情:
fillExtrusionColor(match(get("SELECTED"),
true, get("FILL_COLOR"), // if true use this color
false, rgba(0, 0, 255.0f, 1.0f),
get("FILL_COLOR"))) // default color to use
或:
fillExtrusionColor(switchCase(
eq(get("SELECTED"), true), get("FILL_COLOR"), // if SELECTED == true use this color
eq(get("SELECTED"), false), rgba(0, 0, 255.0f, 1.0f),
get("FILL_COLOR")))) // default value
您可以了解更多here。