第46行: | 第46行: | ||
<!-- 产品1|/index.php?title=test --> | <!-- 产品1|/index.php?title=test --> | ||
<div class="documentA">Android地图SDK|/index.php?title=androidsdk</div> | <div class="documentA">Android地图SDK|/index.php?title=androidsdk</div> | ||
− | <div >></div> | + | <div>></div> |
<div class="documentA">点聚合|/index.php?title=androidsdk/guide/render-map/conflux</div> | <div class="documentA">点聚合|/index.php?title=androidsdk/guide/render-map/conflux</div> | ||
</div> | </div> | ||
</div> | </div> | ||
<div class="wrap_right_nav_r">下载源码</div><!-- 安卓源码地址 --> | <div class="wrap_right_nav_r">下载源码</div><!-- 安卓源码地址 --> | ||
− | <div class="github-url-and">//mapopen-pub-androidsdk.cdn.bcebos.com/map/sample/BaiduLBS_AndroidSDK_Sample.zip</div> | + | <div class="github-url-and"> |
+ | //mapopen-pub-androidsdk.cdn.bcebos.com/map/sample/BaiduLBS_AndroidSDK_Sample.zip</div> | ||
</div> | </div> | ||
<div class="wrap_table"> | <div class="wrap_table"> | ||
第63行: | 第64行: | ||
<div>接口</div> | <div>接口</div> | ||
<div>描述</div> | <div>描述</div> | ||
− | </div> | + | </div><!-- 表格接口,可有多个 --> |
− | + | ||
<div class="table_wrap_con"> | <div class="table_wrap_con"> | ||
<div class="table_wrap_w"> | <div class="table_wrap_w"> | ||
第104行: | 第104行: | ||
</div> | </div> | ||
<div> | <div> | ||
− | <div>setAlgorithm(Algorithm | + | <div>setAlgorithm(Algorithm<T> algorithm)</div> |
</div> | </div> | ||
<div> | <div> | ||
第126行: | 第126行: | ||
</div> | </div> | ||
<div> | <div> | ||
− | <div>addItems(Collection | + | <div>addItems(Collection<T> items</div> |
</div> | </div> | ||
<div> | <div> | ||
第159行: | 第159行: | ||
</div> | </div> | ||
<div> | <div> | ||
− | <div>setOnClusterClickListener(OnClusterClickListener | + | <div>setOnClusterClickListener(OnClusterClickListener<T> listener)</div> |
</div> | </div> | ||
<div> | <div> | ||
第170行: | 第170行: | ||
</div> | </div> | ||
<div> | <div> | ||
− | <div>setOnClusterInfoWindowClickListener(OnClusterInfoWindowClickListener | + | <div>setOnClusterInfoWindowClickListener(OnClusterInfoWindowClickListener<T> |
+ | listener)</div> | ||
</div> | </div> | ||
<div> | <div> | ||
第181行: | 第182行: | ||
</div> | </div> | ||
<div> | <div> | ||
− | <div>setOnClusterItemClickListener(OnClusterItemClickListener | + | <div>setOnClusterItemClickListener(OnClusterItemClickListener<T> listener) |
+ | </div> | ||
</div> | </div> | ||
<div> | <div> | ||
第192行: | 第194行: | ||
</div> | </div> | ||
<div> | <div> | ||
− | <div>setOnClusterItemInfoWindowClickListener(OnClusterItemInfoWindowClickListener | + | <div> |
+ | setOnClusterItemInfoWindowClickListener(OnClusterItemInfoWindowClickListener<T> | ||
+ | listener)</div> | ||
</div> | </div> | ||
<div> | <div> | ||
第200行: | 第204行: | ||
<div class="table_wrap_w"> | <div class="table_wrap_w"> | ||
<div> | <div> | ||
− | <div class="table-wrap-className">MyItem </div> | + | <div class="table-wrap-className">MyItem</div> |
</div> | </div> | ||
<div> | <div> | ||
第211行: | 第215行: | ||
<div class="table_wrap_w"> | <div class="table_wrap_w"> | ||
<div> | <div> | ||
− | <div class="table-wrap-className">MyItem </div> | + | <div class="table-wrap-className">MyItem</div> |
</div> | </div> | ||
<div> | <div> | ||
第223行: | 第227行: | ||
</div> | </div> | ||
</div> | </div> | ||
− | |||
</div> | </div> | ||
</div> | </div> | ||
− | |||
<div class="pre-nav"> | <div class="pre-nav"> | ||
第240行: | 第242行: | ||
</div><!-- 安卓示例代码位置 --> | </div><!-- 安卓示例代码位置 --> | ||
<div class="pre-wrap-w pre-wrap-w-and"> | <div class="pre-wrap-w pre-wrap-w-and"> | ||
− | <pre class="prettyprint prettyprinted pre-and"> | + | <pre class="prettyprint prettyprinted pre-and">mBaiduMap.setOnMapLoadedCallback(new BaiduMap.OnMapLoadedCallback() { |
− | mBaiduMap.setOnMapLoadedCallback(new BaiduMap.OnMapLoadedCallback() { | + | |
@Override | @Override | ||
public void onMapLoaded() { | public void onMapLoaded() { | ||
第263行: | 第264行: | ||
</div> | </div> | ||
<div class="success">复制成功</div> | <div class="success">复制成功</div> | ||
− | |||
</div> | </div> | ||
</div> | </div> | ||
− | |||
<div class="pre-nav"> | <div class="pre-nav"> | ||
第277行: | 第276行: | ||
</div><!-- 安卓示例代码位置 --> | </div><!-- 安卓示例代码位置 --> | ||
<div class="pre-wrap-w pre-wrap-w-and"> | <div class="pre-wrap-w pre-wrap-w-and"> | ||
− | <pre class="prettyprint prettyprinted pre-and"> | + | <pre class="prettyprint prettyprinted pre-and">/** |
− | /** | + | |
* 向地图添加Marker点 | * 向地图添加Marker点 | ||
*/ | */ | ||
第324行: | 第322行: | ||
</div> | </div> | ||
<div class="success">复制成功</div> | <div class="success">复制成功</div> | ||
− | |||
</div> | </div> | ||
</div> | </div> | ||
− | |||
第368行: | 第364行: | ||
<!-- 产品1|/index.php?title=test --> | <!-- 产品1|/index.php?title=test --> | ||
<div class="documentA">IOS地图SDK|/index.php?title=iossdk</div><!-- --> | <div class="documentA">IOS地图SDK|/index.php?title=iossdk</div><!-- --> | ||
− | <div >></div> | + | <div>></div> |
<div class="documentA">点聚合|/index.php?title=iossdk/guide/map-render/pointPoly</div> | <div class="documentA">点聚合|/index.php?title=iossdk/guide/map-render/pointPoly</div> | ||
</div> | </div> | ||
</div> | </div> | ||
<div class="wrap_right_nav_r">下载源码</div><!-- IOS源码地址 --> | <div class="wrap_right_nav_r">下载源码</div><!-- IOS源码地址 --> | ||
− | <div class="github-url-ios">//mapopen-website-wiki.bj.bcebos.com/ | + | <div class="github-url-ios">//mapopen-website-wiki.bj.bcebos.com/BaiduMapSDKDemo.zip</div> |
</div> | </div> | ||
<div class="wrap_table"> | <div class="wrap_table"> | ||
第390行: | 第386行: | ||
<div class="table_wrap_w"> | <div class="table_wrap_w"> | ||
<div> | <div> | ||
− | <div class="table-wrap-className">BMKClusterManager </div> | + | <div class="table-wrap-className">BMKClusterManager</div> |
</div> | </div> | ||
<div> | <div> | ||
第401行: | 第397行: | ||
<div class="table_wrap_w"> | <div class="table_wrap_w"> | ||
<div> | <div> | ||
− | <div class="table-wrap-className">BMKClusterManager </div> | + | <div class="table-wrap-className">BMKClusterManager</div> |
</div> | </div> | ||
<div> | <div> | ||
第412行: | 第408行: | ||
<div class="table_wrap_w"> | <div class="table_wrap_w"> | ||
<div> | <div> | ||
− | <div class="table-wrap-className">BMKMapView | + | <div class="table-wrap-className">BMKMapView</div> |
</div> | </div> | ||
<div> | <div> | ||
− | <div>- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id | + | <div>- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation;</div> |
</div> | </div> | ||
<div> | <div> | ||
第423行: | 第419行: | ||
<div class="table_wrap_w"> | <div class="table_wrap_w"> | ||
<div> | <div> | ||
− | <div class="table-wrap-className">BMKMapView | + | <div class="table-wrap-className">BMKMapView</div> |
</div> | </div> | ||
<div> | <div> | ||
第434行: | 第430行: | ||
<div class="table_wrap_w"> | <div class="table_wrap_w"> | ||
<div> | <div> | ||
− | <div class="table-wrap-className">BMKMapView | + | <div class="table-wrap-className">BMKMapView</div> |
</div> | </div> | ||
<div> | <div> | ||
− | <div>- (void)mapView:(BMKMapView *)mapView onDrawMapFrame:(BMKMapStatus *)status;</div> | + | <div>- (void)mapView:(BMKMapView *)mapView onDrawMapFrame:(BMKMapStatus *)status; |
+ | </div> | ||
</div> | </div> | ||
<div> | <div> | ||
第443行: | 第440行: | ||
</div> | </div> | ||
</div> | </div> | ||
− | |||
</div> | </div> | ||
</div> | </div> | ||
</div> | </div> | ||
− | |||
</div> | </div> | ||
</div> | </div> | ||
第458行: | 第453行: | ||
<div>Objective-C</div> | <div>Objective-C</div> | ||
</div> | </div> | ||
− | |||
<div class="pre-wrap-w pre-wrap-w-ios code_container"> | <div class="pre-wrap-w pre-wrap-w-ios code_container"> | ||
<!-- ios示例代码位置 --> | <!-- ios示例代码位置 --> | ||
− | <pre class="prettyprint prettyprinted pre-ios"> | + | <pre class="prettyprint prettyprinted pre-ios">/** 更新标注展示. */ |
− | /** 更新标注展示. */ | + | |
- (void)updateClusters { | - (void)updateClusters { | ||
_clusterZoom = (NSInteger)_mapView.zoomLevel; | _clusterZoom = (NSInteger)_mapView.zoomLevel; | ||
第581行: | 第574行: | ||
/** 地图渲染每一帧画面过程中,以及每次需要重新绘制地图时(例如添加覆盖物)都会调用此方法*/ | /** 地图渲染每一帧画面过程中,以及每次需要重新绘制地图时(例如添加覆盖物)都会调用此方法*/ | ||
- (void)mapView:(BMKMapView *)mapView onDrawMapFrame:(BMKMapStatus *)status { | - (void)mapView:(BMKMapView *)mapView onDrawMapFrame:(BMKMapStatus *)status { | ||
− | if (_clusterZoom != 0 && _clusterZoom != (NSInteger)mapView.zoomLevel) { | + | if (_clusterZoom != 0 && _clusterZoom != (NSInteger)mapView.zoomLevel) { |
[self updateClusters]; | [self updateClusters]; | ||
} | } | ||
第594行: | 第587行: | ||
</div> | </div> | ||
</div> | </div> | ||
− | |||
</div> | </div> | ||
</div> | </div> |
2020年6月1日 (一) 19:14的版本
点聚合
功能场景
通过该功能可以避免因Marker绘制过多呈现拥挤的情况,获得更优的展示效果,常用于充电桩、房产等app中。
Android
iOS
//mapopen-website-wiki.bj.bcebos.com/demos/AndroidVideos/Android点聚合.mp4
1590746640|//mapopen-website-wiki.bj.bcebos.com/demos/qrcodes/点聚合.png
扫码体验
使用产品
Android地图SDK|/index.php?title=androidsdk
>
点聚合|/index.php?title=androidsdk/guide/render-map/conflux
下载源码
//mapopen-pub-androidsdk.cdn.bcebos.com/map/sample/BaiduLBS_AndroidSDK_Sample.zip
核心接口
类
接口
描述
ClusterManager
getMarkerCollection()
获取所有已添加的marker集合
ClusterManager
getClusterMarkerCollection()
获取聚合后的marker簇集合
ClusterManager
getMarkerManager()
获取MarkerManager
ClusterManager
setAlgorithm(Algorithm<T> algorithm)
设置marker聚合算法
ClusterManager
clearItems()
清空所有已经添加的聚合点
ClusterManager
addItems(Collection<T> items
添加一组聚合点
ClusterManager
addItem(T myItem)
添加单个聚合点
ClusterManager
cluster()
强制聚合
ClusterManager
setOnClusterClickListener(OnClusterClickListener<T> listener)
设置聚合簇点击回调
ClusterManager
setOnClusterInfoWindowClickListener(OnClusterInfoWindowClickListener<T>
listener)
设置聚合infoWindow点击回调
ClusterManager
setOnClusterItemClickListener(OnClusterItemClickListener<T> listener)
设置单个聚合点点击回调
ClusterManager
setOnClusterItemInfoWindowClickListener(OnClusterItemInfoWindowClickListener<T>listener)
设置单个聚合InfoWindow点击回调
MyItem
getPosition()
获取聚合点位置
MyItem
getBitmapDescriptor()
获取聚合点图标
重点关注
主义在地图加载完成回调里添加聚合点,代码如下。
JAVA
mBaiduMap.setOnMapLoadedCallback(new BaiduMap.OnMapLoadedCallback() { @Override public void onMapLoaded() { // 添加marker initCluster(); addMarkers(); // 设置初始中心点为北京 LatLng center = new LatLng(39.963175, 116.400244); // 需要更新下地图状态,聚合点才会显示出来 MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.newLatLngZoom(center, 10); mBaiduMap.setMapStatus(mapStatusUpdate); } });
复制
深色
复制成功
核心代码
JAVA
/** * 向地图添加Marker点 */ public void addMarkers() { // 添加Marker点 LatLng llA = new LatLng(40.109965, 116.380244); LatLng llB = new LatLng(40.106965, 116.359199); LatLng llC = new LatLng(40.105965, 116.405541); LatLng llD = new LatLng(40.103175, 116.401394); LatLng llE = new LatLng(40.102821, 116.421394); LatLng llF = new LatLng(39.993175, 116.432394); LatLng llG = new LatLng(39.992821, 116.431394); LatLng llH = new LatLng(39.999723, 116.451394); LatLng llI = new LatLng(39.996965, 116.460244); LatLng llJ = new LatLng(39.999965, 116.489199); LatLng llK = new LatLng(39.999723, 116.315541); LatLng llL = new LatLng(39.996965, 116.291394); LatLng llM = new LatLng(40.010065, 116.351394); LatLng llN = new LatLng(40.016965, 116.331394); LatLng llO = new LatLng(40.015965, 116.361394); LatLng llP = new LatLng(40.017965, 116.291394); LatLng llQ = new LatLng(39.899723, 116.315541); LatLng llR = new LatLng(39.896965, 116.341394); LatLng llS = new LatLng(39.895065, 116.351394); LatLng llT = new LatLng(39.916965, 116.341394); LatLng llU = new LatLng(39.915965, 116.331394); LatLng llV = new LatLng(39.917965, 116.321394); LatLng llW = new LatLng(39.893175, 116.412394); LatLng llX = new LatLng(39.892821, 116.411394); LatLng llY = new LatLng(39.899723, 116.431394); LatLng llZ = new LatLng(39.896965, 116.440244); LatLng llA0 = new LatLng(39.899965, 116.469199); List<MyItem> items = new ArrayList<MyItem>(); mClusterManager.addItems(items); }
复制
深色
复制成功