我是mapbox的新手,找不到解决方案:
我在地图上有2层:
第一层中的每个功能(联系人)都具有布尔值“ isInEmergency”(我知道这很好用,因为我相应地显示了文本颜色)
现在,我要在(第二层的)群集图标上(从第一层显示)紧急指示:
GeoJsonSource非常动态,我正在动态添加/从源中删除点,并更新现有点的位置, 因此集群非常动态,并且随时随地发生变化
我该如何实现这种行为?
我尝试在群集层中使用表达式来检索紧急属性,但是返回值始终为false,尽管我知道第一层中的情况为真
我在做什么错了?
相关代码: 1)联系人层:
public void createContactsLayer(@NonNull Style loadedMapStyle , String contactsSourceId , String contactLayerId) {
FeatureCollection featureCollection = FeatureCollection.fromFeatures(contactsMapTable.values().toArray(new Feature[0]));
geoJsonSource = new GeoJsonSource(contactsSourceId, featureCollection, new GeoJsonOptions()
.withCluster(true)..;
loadedMapStyle.addSource(geoJsonSource);
loadedMapStyle.addLayer(new SymbolLayer(contactLayerId, contactsSourceId).withProperties(...
//////////////here I use the emergency property and it works well/////////////////////////////
textColor(switchCase(
eq(get("emergency-field"), true), rgba(255, 0, 0, 1.0f),
eq(get("emergency-field"), false), rgba(0, 255, 0, 1.0f), get("#FF5733")))
));
}
2)群集层:
private void createClusterLayer(@NonNull Style loadedMapStyle) {
int[] layers = new int[]{150, 20, 0};
for (int i = 0; i < layers.length; i++) {
//Add clusters' SymbolLayers images
SymbolLayer symbolLayer = new SymbolLayer(CLUSTER_LAYER_ID + i, CONTACTS_SOURCE_ID);
symbolLayer.setProperties(
//here I tried to use the emergency property and it's always false (the image is always CLUSTER_IMAGE_ID)/////////////////////////////
iconImage(switchCase(eq(toBool(get("emergency-field")), true), literal(CLUSTER_EMERGENCY_IMAGE_ID), eq(toBool(get("emergency-field")), false), literal(CLUSTER_IMAGE_ID), literal(CLUSTER_EMERGENCY_IMAGE_ID))),
textOffset(new Float[]{0.0f, -0.2f}),
textIgnorePlacement(true),
textAllowOverlap(false)
);
Expression pointCount = toNumber(get("point_count"));
// Add a filter to the cluster layer that hides the icons based on "point_count"
symbolLayer.setFilter(
i == 0
? all(has("point_count"),
gte(pointCount, literal(layers[i]))
) : all(has("point_count"),
gt(pointCount, literal(layers[i])),
lt(pointCount, literal(layers[i - 1]))
)
);
loadedMapStyle.addLayer(symbolLayer);
}
//Add a SymbolLayer for the cluster data number point count
loadedMapStyle.addLayer(new SymbolLayer(CLUSTER_LAYER_ID, CONTACTS_SOURCE_ID).withProperties(
...
));
每一个帮助我都会感激
感谢您抽出宝贵时间!