【发布时间】:2021-02-18 20:05:12
【问题描述】:
我正在开发一个地理可视化数据地图,它将根据不同的数值绘制不同颜色的地图。并且,还希望在圆圈顶部可视化数值(它是围绕路线盘旋的道路中的空气污染数据)。问题是当两个图层 SymbolLayer 和 CircleLayer 同时应用时,它们会使移动应用程序崩溃,这不起作用。我尝试只测试它们工作的一个层,只有当两者都应用时它们才会崩溃。是否有可能在存在彩色圆圈且数值标签也存在的情况下进行两层拖曳工作?另外,我正在使用存储在 Tilesets 中的数据。下面是应用程序的图片链接。由于这是我第一次使用 StackOverflow,因此无法发布图片。
//Map View
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.LIGHT, new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
style.addSource(new VectorSource(
VECTOR_SOURCE_ID,
"http://api.mapbox.com/v4/"+TILESET_KEY+".json?access_token=" + Mapbox.getAccessToken()
));
SymbolLayer label =new SymbolLayer(TILESET_LAYER_ID, VECTOR_SOURCE_ID);
label.setSourceLayer(VECTOR_SOURCE_ID);
label.withProperties(
textField(get("gaslvl_PM")), //This contains the number values
textSize(17f),
textColor(Color.RED),
textVariableAnchor(
new String[]{TEXT_ANCHOR_TOP, TEXT_ANCHOR_BOTTOM, TEXT_ANCHOR_LEFT, TEXT_ANCHOR_RIGHT}),
textJustify(TEXT_JUSTIFY_AUTO),
textRadialOffset(0.5f)
);
label.setFilter(all(
//This is to filter out the multiple rounds in the route of one full roundtrip.
//To prevent the same data from the same area to overlap.
eq(literal("roundtrip_number"), literal(roundT_val))));
style.addLayer(label);
CircleLayer circleLayer = new CircleLayer(TILESET_LAYER_ID, VECTOR_SOURCE_ID);
circleLayer.setSourceLayer(VECTOR_SOURCE_ID);
circleLayer.withProperties(
circleRadius(
interpolate(
exponential(1.75f),
zoom(),
stop(12, 2f),
stop(22, 180f)
)),
circleColor(
match(
get(TILESET_LAYER_ID),rgb(0, 0, 0),
stop("0", COLOR_GREEN),
stop("1", COLOR_GREEN),
stop("2", COLOR_GREEN),
stop("3", COLOR_GREEN),
stop("4", COLOR_GREEN)
//Didn't add the rest of the "stop colors" since it's 500 lines.
));
circleLayer.setFilter(all(
eq(literal("roundtrip_number"), literal(roundT_val))
//eq(literal("date"), literal(Date.valueOf(date_val)))
));
style.addLayer(circleLayer);
}
});
}
});
【问题讨论】:
标签: android mapbox mapbox-android