添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
慷慨大方的香烟  ·  ajax ...·  2 年前    · 
爱看书的竹笋  ·  Unable to parse ...·  3 年前    · 
不拘小节的咖啡豆  ·  NestJS and ...·  3 年前    · 
登录

MapboxMap中未显示CircleLayer群集

内容来源于 Stack Overflow,遵循 CC BY-SA 4.0 许可协议进行翻译与使用。IT领域专用引擎提供翻译支持

腾讯云小微IT领域专用引擎提供翻译支持

原文
Stack Overflow用户 修改于2021-03-31
  • 该问题已被编辑
  • 提问者: Stack Overflow用户
  • 提问时间: 2021-03-31 19:07

我正在尝试在本教程的帮助下为MapboxMap实现CircleLayer集群: https://docs.mapbox.com/android/maps/examples/circle-layer-clustering/

在我的应用程序中,我通过API接收4种类型的路由,我已经能够在源层中显示相应的图像。现在我想为这4种类型的路线添加圆圈图层聚类,但我的圆圈图层没有在地图上渲染。太远而无法进行集群的路由按其应有的方式显示,但我的CircleLayers都没有显示出来。这是我用来绘制路由标记和聚类的代码:

public void setRoutesToMap(FeatureCollection routesCollection) {
mapboxMap.getStyle(style -> {
    style.removeLayer(ROUTE_MARKER_LAYER);
    style.removeLayer(ROUTE_MARKER_CYCLING_CLUSTER_LAYER);
    style.removeLayer(ROUTE_MARKER_MTB_CLUSTER_LAYER);
    style.removeLayer(ROUTE_MARKER_SINGLETRAIL_CLUSTER_LAYER);
    style.removeLayer(ROUTE_MARKER_ROADBIKE_CLUSTER_LAYER);
    style.removeLayer(ROUTE_CLUSTER_COUNT_LAYER);
    style.removeSource(ROUTE_MARKER_SOURCE);
    // Disable any type of fading transition when icons collide on the map. This enhances the visual
    // look of the data clustering together and breaking apart.
    style.setTransition(new TransitionOptions(0, 0, false));
    //adding source (contains feature collection from which the markers get drawn)
    style.addSource(new GeoJsonSource(ROUTE_MARKER_SOURCE, routesCollection,
            new GeoJsonOptions().withCluster(true)
                    .withClusterMaxZoom(ROUTE_CLUSTER_MAX_ZOOM)
                    .withClusterRadius(ROUTE_CLUSTER_RADIUS)
                    //adding cluster property to distinguish types of clusters depending on the features route category
                    .withClusterProperty(MapboxHelper.ROUTE_PROPERTY_CATEGORY_CLUSTER, Expression.sum(Expression.accumulated(), Expression.get(MapboxHelper.ROUTE_PROPERTY_CATEGORY_CLUSTER)),
                            Expression.switchCase(
                                    //if route category equals BIKE_ROUTE, set cluster property to 1
                                    Expression.eq(Expression.get(MapboxHelper.ROUTE_PROPERTY_CATEGORY), RouteProperty.Category.BIKE_ROUTE), Expression.literal(1),
                                    //if route category equals MOUNTAINBIKE_ROUTE, set cluster property to 2
                                    Expression.eq(Expression.get(MapboxHelper.ROUTE_PROPERTY_CATEGORY), RouteProperty.Category.MOUNTAINBIKE_ROUTE), Expression.literal(2),
                                    //if route category equals SINGLETRAIL_ROUTE, set cluster property to 3
                                    Expression.eq(Expression.get(MapboxHelper.ROUTE_PROPERTY_CATEGORY), RouteProperty.Category.SINGLETRAIL_ROUTE), Expression.literal(3),
                                    //if route category equals ROADBIKE_ROUTE, set cluster property to 4
                                    Expression.eq(Expression.get(MapboxHelper.ROUTE_PROPERTY_CATEGORY), RouteProperty.Category.ROADBIKE_ROUTE), Expression.literal(4),
                                    //else set cluster property to 0
                                    Expression.literal(0)))
    //adding images with names of routes category so they get displayed with the correct category image
    style.addImage(RouteProperty.Category.BIKE_ROUTE, BitmapFactory.decodeResource(getResources(), R.drawable.map_route_radwandern));
    style.addImage(RouteProperty.Category.MOUNTAINBIKE_ROUTE, BitmapFactory.decodeResource(getResources(), R.drawable.map_route_mountainbike));
    style.addImage(RouteProperty.Category.SINGLETRAIL_ROUTE, BitmapFactory.decodeResource(getResources(), R.drawable.map_route_singletrail));
    style.addImage(RouteProperty.Category.ROADBIKE_ROUTE, BitmapFactory.decodeResource(getResources(), R.drawable.map_route_rennrad));
    //adding layer for unselected markers, images are used from category feature property
    style.addLayerBelow(new SymbolLayer(ROUTE_MARKER_LAYER, ROUTE_MARKER_SOURCE).withProperties(
            iconImage("{" + MapboxHelper.ROUTE_PROPERTY_CATEGORY + "}"),
            iconAllowOverlap(true)
    ), LOCATION_COMPONENT_BACKGROUND_LAYER);
    //Expression to filter whether we're displaying a cluster, since only clusters contain the property "point_count"
    Expression isCluster = Expression.has(MapboxHelper.PROPERTY_POINT_COUNT);
    //Expression to filter for clusters with cycling type
    Expression clusterCategoryCyclingFilter = Expression.eq(Expression.toNumber(Expression.get(MapboxHelper.ROUTE_PROPERTY_CATEGORY_CLUSTER)), Expression.literal(1));
    //Expression to filter for clusters with mountainbike type
    Expression clusterCategoryMountainbikeFilter = Expression.eq(Expression.toNumber(Expression.get(MapboxHelper.ROUTE_PROPERTY_CATEGORY_CLUSTER)), Expression.literal(2));
    //Expression to filter for clusters with singletrail type
    Expression clusterCategorySingletrailFilter = Expression.eq(Expression.toNumber(Expression.get(MapboxHelper.ROUTE_PROPERTY_CATEGORY_CLUSTER)), Expression.literal(3));
    //Expression to filter for clusters with roadbike type
    Expression clusterCategoryRoadbikeFilter = Expression.eq(Expression.toNumber(Expression.get(MapboxHelper.ROUTE_PROPERTY_CATEGORY_CLUSTER)), Expression.literal(4));
    //adding circle layer for cycling cluster with proper filter
    style.addLayer(new CircleLayer(ROUTE_MARKER_CYCLING_CLUSTER_LAYER, ROUTE_MARKER_SOURCE).withProperties(
            circleColor(getResources().getColor(R.color.color_cycling)),
            circleRadius(18f)
    ).withFilter(Expression.all(isCluster, clusterCategoryCyclingFilter)));
    //adding circle layer for mountainbike cluster with proper filter
    style.addLayer(new CircleLayer(ROUTE_MARKER_MTB_CLUSTER_LAYER, ROUTE_MARKER_SOURCE).withProperties(
            circleColor(getResources().getColor(R.color.color_mountainbike)),
            circleRadius(18f)
    ).withFilter(Expression.all(isCluster, clusterCategoryMountainbikeFilter)));
    //adding circle layer for singletrail cluster with proper filter
    style.addLayer(new CircleLayer(ROUTE_MARKER_SINGLETRAIL_CLUSTER_LAYER, ROUTE_MARKER_SOURCE).withProperties(
            circleColor(getResources().getColor(R.color.color_singletrail)),
            circleRadius(18f)
    ).withFilter(Expression.all(isCluster, clusterCategorySingletrailFilter)));
    //adding circle layer for roadbike cluster with proper filter
    style.addLayer(new CircleLayer(ROUTE_MARKER_ROADBIKE_CLUSTER_LAYER, ROUTE_MARKER_SOURCE).withProperties(
            circleColor(getResources().getColor(R.color.color_roadbike)),
            circleRadius(18f)
    ).withFilter(Expression.all(isCluster, clusterCategoryRoadbikeFilter)));
    //adding cluster count layer to display the amount of routes the cluster contains
    style.addLayer(new SymbolLayer(ROUTE_CLUSTER_COUNT_LAYER, ROUTE_MARKER_SOURCE).withProperties(
            textField(Expression.toString(Expression.get(MapboxHelper.PROPERTY_POINT_COUNT))),
            textSize(getResources().getDimension(R.dimen.text_14)),
            textColor(getResources().getColor(R.color.applicationBackground)),
            textIgnorePlacement(true),
            textAllowOverlap(true)