{"version":"0.1.0","code":"0000","result":true,"message":"处理成功","errdetail":"","timestamp":1671516365138,"data":{"id":71712657,"title":"6.3.4.2图层聚合能力","slug":"dzko18","format":"lake","bookId":26046811,"body":null,"body_draft":null,"body_html":"

场景图

\"image.png\"

时序图


关键参数

聚合图层聚合策略配置信息

com.autonavi.gbl.map.layer.model.BGDClusterStrategy

字段

含义

centerType

聚合点策略,第一个点或质心

minClusterSize

最少几个点可形成聚合点

clusterRange

指定的聚合范围,(屏幕坐标系)

vecClusterDis[MAP_LEVEL_COUNT]

聚合网格距离,传入0-22级比例尺所对应的聚合距离,数值大于0生效,(单位像素)

vecDisplayScale

配置每个聚合类型的显示范围,若没配置则按全比例尺显示

聚合图层点数据生效规则

com.autonavi.gbl.map.layer.model.ClusterDisplayScale

字段

含义

strTypeCode

POI类型代码或者品牌代码

displayScale

聚合点显示生效范围

聚合图层不同POI类型显示比例尺范围

com.autonavi.gbl.map.layer.model.ClusterCenterType

字段

含义

Cluster_FirstPoint

第一个点

Cluster_Centroid

质点

图层图元类型

com.autonavi.gbl.map.layer.model.LayerItemType

字段

含义

LayerItemClusterPointType

聚合点


核心接口

/* 设置基于网格和距离的聚合算法的策略 */\nvoid com.autonavi.gbl.map.layer.BaseLayer.setBGDClusterStrategy(BGDClusterStrategy clusterStrategy)\n\n/* 聚合能力开关 */\nvoid com.autonavi.gbl.map.layer.BaseLayer.enableCluster(bool bOpen)

说明:函数详情,请复制函数名称到在线API搜索


调用示例

自定义点图层数据添加

//显示自定义点图层\npublic void showCustomPointLayer() {\n    Coord3DDouble pos = new Coord3DDouble(116.353983, 39.939872, 0);\n    ArrayList<BizCustomPointInfo> vecThemeMapLayerItem = new ArrayList<>();\n    for (int cnt = 0; cnt < count; cnt++) {\n        BizCustomPointInfo bizCustomPointInfo = new BizCustomPointInfo();\n        bizCustomPointInfo.mTypeCode = mTypeCode;\n        bizCustomPointInfo.type = 5;\n        Coord3DDouble changePos = new Coord3DDouble();\n        changePos.lon = pos.lon + (cnt * 0.01);\n        changePos.lat = pos.lat + (cnt * 0.01);\n        if (cnt == 200) {\n            changePos.lon = 116.352996; // 北京北站\n            changePos.lat = 39.945202;\n            bizCustomPointInfo.mTypeCode = "1";\n            bizCustomPointInfo.type = 1;\n        } else if (cnt == 400) {\n            changePos.lon = 116.397564; // 天安门\n            changePos.lat = 39.908898;\n            bizCustomPointInfo.mTypeCode = "2";\n            bizCustomPointInfo.type = 2;\n        } else if (cnt == 1000) {\n            changePos.lon = 116.428119; // 北京站\n            changePos.lat = 39.904948;\n            bizCustomPointInfo.mTypeCode = "3";\n            bizCustomPointInfo.type = 3;\n        } else if (cnt == 2000) {\n            changePos.lon = 116.397564; // 天安门\n            changePos.lat = 39.908898;\n            bizCustomPointInfo.mTypeCode = "4";\n            bizCustomPointInfo.type = 4;\n        }\n        bizCustomPointInfo.mPos3D = changePos;\n        bizCustomPointInfo.id = "" + cnt;\n        vecThemeMapLayerItem.add(bizCustomPointInfo);\n    }\n    // bizCustomPointInfo为测试点,仅做参考\n    mBizCustomControl.updateCustomPoint(vecThemeMapLayerItem, BizCustomTypePoint.BizCustomTypePoint1);\n}

设置聚合策略

public void SetBGDClusterStrategy() {\n    BaseLayer baseLayer = mBizCustomControl.getCustomLayer(BizCustomTypePoint.BizCustomTypePoint1);\n   \n    //聚合策略(BasedGridDistance)\n    BGDClusterStrategy clusterStrategy;\n    \n    //配置typeCode的聚合结果的显示比例范围,若不设置则全比例尺显示\n    //这里对typeCode = "2"的聚合结果配置比例尺显示范围[9,12]\n    ClusterDisplayScale displayScale = new ClusterDisplayScale();\n    displayScale.strTypeCode = “2”;\n    displayScale.displayScale.minScale = 9;\n    displayScale.displayScale.maxScale = 12;\n    clusterStrategy.vecDisplayScale.clear();\n    clusterStrategy.vecDisplayScale.add(displayScale);\n    \n    //设定聚合生效范围,屏幕坐标系\n    //这里设置的聚合范围,左上角(512,300), 宽450, 高300\n    clusterStrategy.clusterRange.left   = 512; \n    clusterStrategy.clusterRange.top    = 300; \n    clusterStrategy.clusterRange.right  = 450; \n    clusterStrategy.clusterRange.bottom = 300;   \n    \n    //设定最少几个点聚合生效\n    //这里设置最少两个点可进行聚合\n    clusterStrategy.minClusterSize = 2;\n    \n    //设定聚合结果的聚合点类型\n    //这里设置以聚合结果的第一个点为聚合点\n    clusterStrategy.centerType     = Cluster_FirstPoint;  //Cluster_FirstPoint第一个点,Cluster_Centroid质心\n\n    //设定聚合距离\n    //这里设置不同比例尺有不同的聚合距离\n    for (int32_t i = 3; i < MAP_LEVEL_COUNT; i++) {\n        clusterStrategy.vecClusterDis[i] = (MAP_LEVEL_COUNT - i) * 15; //不同比例尺设置不同聚合距离\n    }\n\n    //设置聚合策略\n    baseLayer.setBGDClusterStrategy(clusterStrategy);\n}

打开聚合开关

BaseLayer baseLayer = mBizCustomControl.getCustomLayer(BizCustomTypePoint.BizCustomTypePoint1);\nbaseLayer.enableCluster(true);

设置聚合点可点击(点击有展开效果)

BaseLayer baseLayer = mBizCustomControl.getCustomLayer(BizCustomTypePoint.BizCustomTypePoint1);\nbaseLayer.setClickable(true);

样式及纹理回调(聚合点的itemType为LayerItemClusterPointType

/* 回调获取点json,回调获取markerID */\npublic class MapPrepareLayerStyle implements IPrepareLayerStyle {\n    ...\n    @Override\n    public String getLayerStyle(final BaseLayer pLayer, LayerItem layerItem, boolean b) {\n        String strStyleJson = "";\n        int itemType = layerItem.getItemType();\n        int businessType = layerItem.getBusinessType();\n        switch (itemType) {\n            case LayerItemType.LayerItemClusterPointType:\n                ... // 按需对businessType进行判断,获取指定的json串\n                strStyleJson = getStyleBeanJson("point_layer_item_style");\n                break;\n            case LayerItemType.xxx:\n                break;\n        }\n        return strStyleJson;\n    }   \n    ... \n    @Override\n    public int getMarkerId(BaseLayer pLayer, LayerItem pItem, String strMarkerId, String strMarkerInfo) {\n        int markerId = -1;\n        strMarkerId = strMarkerId.trim();\n        if (strMarkerId.isEmpty()) {\n            return markerId;\n        }   \n        ...\n        int itemType = layerItem.getItemType();\n        int businessType = layerItem.getBusinessType();\n        \n        switch (itemType) {\n            case LayerItemType.LayerItemClusterPointType:\n                ... // 按需对businessType进行判断\n                //判断纹理信息,若未加载则通过addLayerTexture加载纹理\n                markerId = addLayerTexture(texture);\n                break;\n            case LayerItemType.xxx:\n                markerId = -1;\n                break;\n        }\n        return markerId;\n    }   \n}  

[注意事项]

1、点聚合算法

AutoSDK提供基于网格和距离结合的点聚合算法。

基于网格和距离结合算法的聚合效果如下:

\"image.png\"


2、聚合内容对接

具体参考调用示例内容


3、430与460的聚合能力映射关系

3.1、各版本聚合能力说明

3.2、结构体映射

430版本

460版本

ClusterStrategy

BGDClusterStrategy

ClusterCenterPoint

ClusterCenterType

ClusterStrategy.centerPoint

BGDClusterStrategy.centerType

ClusterStrategy.mMinGridSize

BGDClusterStrategy.minClusterSize

ClusterStrategy.mDisplayBound

BGDClusterStrategy.clusterRange

ClusterStrategy.mVecClusterData

BGDClusterStrategy.vecClusterDis

ClusterStrategy.mVecClusterScale

BGDClusterStrategy.vecDisplayScale

ClusterStrategy.mMinScale+mMaxScale

BaseLayer.setDisplayScale

3.3、接口映射

430版本

460版本

GridDistanceClusterStrategy.setClusterStrategy

BaseLayer.setBGDClusterStrategy

3.4、变更映射说明

","body_lake":null,"pub_level":null,"status":"0","updated_at":"2022-04-06 07:03:57","deleted_at":null,"nameSpace":"mnlcaa/v610","browseCount":95,"collectCount":0,"estimateDate":16,"docStatus":0,"permissions":true,"overView":false}}