第1行: | 第1行: | ||
− | <div id="examples_center"> | + | <div id="examples_center"><!-- 页面标题 --><div class="title-hd">点聚合</div><!-- 标题下子标题及简介,可有多个 --><div class="title-mi">功能场景</div><div class="wrap-mi">通过该功能可以避免因Marker绘制过多呈现拥挤的情况,获得更优的展示效果,常用于充电桩、房产等app中。</div><!-- --></div><div class="demos_wrap"><div class="header"><div class="andiord-header active">Android</div><div class="ios-header">iOS</div></div><div class="andiord-wrap wrap"><div class="wrap-wp"><div class="wrap_left"><div class="left-video"><div class="img-bg-and"></div><div class="phone-android"><div class="video-wrap infor"><div class="video-control"></div><!-- 安卓视频位置 (不写协议)--><pre>//mapopen-website-wiki.bj.bcebos.com/demos/AndroidVideos/Android点聚合.mp4</pre> |
− | + | </div><div class="video-icon-and"><div class="play play-and"></div><div class="stop stop-and"></div></div></div><div class="progressWrap-hide-and"></div><div id="videoControls-and"><div id="progressWrap-and"><div id="playProgress-and"></div></div></div></div><div class="left-qrCode"><!-- 安卓二维码位置 --><div class="qrCode-and">1590746640|//mapopen-website-wiki.bj.bcebos.com/demos/qrcodes/点聚合.png</div><div>扫码体验</div></div></div><div class="wrap_right"><div class="wrap_right_nav"><div class="wrap_right_nav_l"><div>使用产品</div><div><!-- 安卓使用产品下选项,可有多个 --><!-- 产品1|/index.php?title=test --><div class="documentA">Android地图SDK|/index.php?title=androidsdk</div><div>></div><div class="documentA">点聚合|/index.php?title=androidsdk/guide/render-map/conflux</div></div></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><div class="wrap_table"><div class="table_nav"><div class="left-icon"></div><div>核心接口</div></div><div class="table_wrap"><div class="table_wrap_title"><div>类</div><div>接口</div><div>描述</div></div><!-- 表格接口,可有多个 --><div class="table_wrap_con"><div class="table_wrap_w"><div><div class="table-wrap-className">ClusterManager</div></div><div><div>getMarkerCollection()</div></div><div><div>获取所有已添加的marker集合</div></div></div><!-- --><div class="table_wrap_w"><div><div class="table-wrap-className">ClusterManager</div></div><div><div>getClusterMarkerCollection()</div></div><div><div>获取聚合后的marker簇集合</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">ClusterManager</div></div><div><div>getMarkerManager()</div></div><div><div>获取MarkerManager</div></div></div><!-- --><div class="table_wrap_w"><div><div class="table-wrap-className">ClusterManager</div></div><div><div>setAlgorithm(Algorithm<T> algorithm)</div></div><div><div>设置marker聚合算法</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">ClusterManager</div></div><div><div>clearItems()</div></div><div><div>清空所有已经添加的聚合点</div></div></div><!-- --><div class="table_wrap_w"><div><div class="table-wrap-className">ClusterManager</div></div><div><div>addItems(Collection<T> items</div></div><div><div>添加一组聚合点</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">ClusterManager</div></div><div><div>addItem(T myItem)</div></div><div><div>添加单个聚合点</div></div></div><!-- --><div class="table_wrap_w"><div><div class="table-wrap-className">ClusterManager</div></div><div><div>cluster()</div></div><div><div>强制聚合</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">ClusterManager</div></div><div><div>setOnClusterClickListener(OnClusterClickListener<T> listener)</div></div><div><div>设置聚合簇点击回调</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">ClusterManager</div></div><div><div>setOnClusterInfoWindowClickListener(OnClusterInfoWindowClickListener<T> listener)</div></div><div><div>设置聚合infoWindow点击回调</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">ClusterManager</div></div><div><div>setOnClusterItemClickListener(OnClusterItemClickListener<T> listener)</div></div><div><div>设置单个聚合点点击回调</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">ClusterManager</div></div><div><div>setOnClusterItemInfoWindowClickListener(OnClusterItemInfoWindowClickListener<T> listener)</div></div><div><div>设置单个聚合InfoWindow点击回调</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">MyItem</div></div><div><div>getPosition()</div></div><div><div>获取聚合点位置</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">MyItem</div></div><div><div>getBitmapDescriptor()</div></div><div><div>获取聚合点图标</div></div></div></div></div></div></div></div> | |
− | + | ||
− | + | ||
− | + | ||
− | </div> | + | |
− | <div class="demos_wrap"> | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | <div class="pre-nav"><div class="left-icon"></div><div>重点关注</div></div><div class="pre-nav" style="margin-left: 10px;"><div>在地图加载完成回调里添加聚合点,代码如下。</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>JAVA</div></div><!-- 安卓示例代码位置 --><div class="pre-wrap-w pre-wrap-w-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() { | ||
第258行: | 第19行: | ||
}); | }); | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-and">复制</div><div class="pre-btn-cb-and">深色</div></div><div class="success">复制成功</div></div></div> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | <div class="pre-nav"><div class="left-icon"></div><div>核心代码</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>JAVA</div></div><!-- 安卓示例代码位置 --><div class="pre-wrap-w pre-wrap-w-and"><pre class="prettyprint prettyprinted pre-and">/** | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | /** | + | |
* 向地图添加Marker点 | * 向地图添加Marker点 | ||
*/ | */ | ||
第318行: | 第61行: | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-and">复制</div><div class="pre-btn-cb-and">深色</div></div><div class="success">复制成功</div></div></div> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | </div><div class="ios-wrap wrap" style="display: none;"><div class="wrap-wp"><div class="wrap_left"><div class="left-video"><div class="img-bg-ios-sh"></div><div class="phone-ios"><div class="video-wrap infor"><div class="video-control"></div><!-- ios视频位置 --><pre>//mapopen-website-wiki.bj.bcebos.com/demos/iosVideos/iOS点聚合.mov</pre> | |
− | + | </div><div class="video-icon-ios"><div class="play play-ios"></div><div class="stop stop-ios"></div></div></div><div class="progressWrap-hide-ios"></div><div id="videoControls-ios"><div id="progressWrap-ios"><div id="playProgress-ios"></div></div></div></div><div class="left-qrCode"><!-- ios二维码位置 --><div class="qrCode-ios">//mapopen-website-wiki.bj.bcebos.com/demos/play.png</div><div>扫码手机观看</div></div></div><div class="wrap_right"><div class="wrap_right_nav"><div class="wrap_right_nav_l"><div>使用产品</div><div><!-- IOS使用产品下选项,可有多个 --><!-- 产品1|/index.php?title=test --><div class="documentA">IOS地图SDK|/index.php?title=iossdk</div><!-- --><div>></div><div class="documentA">点聚合|/index.php?title=iossdk/guide/map-render/pointPoly</div></div></div><div class="wrap_right_nav_r">下载源码</div><!-- IOS源码地址 --><div class="github-url-ios">//mapopen-website-wiki.bj.bcebos.com/demos/iosVideos/iOS示例中心Demo.zip</div></div><div class="wrap_table"><div class="table_nav"><div class="left-icon"></div><div>核心接口</div></div><div class="table_wrap"><div class="table_wrap_title"><div>类</div><div>接口</div><div>描述</div></div><!-- ios表格接口内容,可有多个 --><!-- 表格接口,可有多个 --><div class="table_wrap_con"><div class="table_wrap_w"><div><div class="table-wrap-className">BMKClusterManager</div></div><div><div>- (void)clearClusterItems;</div></div><div><div>清除标注集群items</div></div></div><!-- --><div class="table_wrap_w"><div><div class="table-wrap-className">BMKClusterManager</div></div><div><div>- (NSArray<BMKCluster *> *)getClusters:(CGFloat)zoomLevel;</div></div><div><div>根据地图缩放级别获取标注集群</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BMKMapView</div></div><div><div>- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation;</div></div><div><div>向地图添加标注</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BMKMapView</div></div><div><div>- (void)mapViewDidFinishLoading:(BMKMapView *)mapView;</div></div><div><div>地图加载完成时会调用此方法</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BMKMapView</div></div><div><div>- (void)mapView:(BMKMapView *)mapView onDrawMapFrame:(BMKMapStatus *)status;</div></div><div><div>地图渲染每一帧画面过程中,以及每次需要重新绘制地图时(例如添加覆盖物)都会调用此方法</div></div></div></div></div></div></div></div><div class="pre-nav"><div class="left-icon"></div><div>核心代码</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>Objective-C</div></div><div class="pre-wrap-w pre-wrap-w-ios code_container"><!-- ios示例代码位置 --><pre class="prettyprint prettyprinted pre-ios">/** 更新标注展示. */ | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | /** 更新标注展示. */ | + | |
- (void)updateClusters { | - (void)updateClusters { | ||
_clusterZoom = (NSInteger)_mapView.zoomLevel; | _clusterZoom = (NSInteger)_mapView.zoomLevel; | ||
第580行: | 第185行: | ||
/** 地图渲染每一帧画面过程中,以及每次需要重新绘制地图时(例如添加覆盖物)都会调用此方法*/ | /** 地图渲染每一帧画面过程中,以及每次需要重新绘制地图时(例如添加覆盖物)都会调用此方法*/ | ||
- (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]; | ||
} | } | ||
第586行: | 第191行: | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-ios">复制</div><div class="pre-btn-cb-ios">深色</div></div><div class="success">复制成功</div></div></div></div></div> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | </div> | + |
2020年6月1日 (一) 16:11的版本
点聚合
功能场景
通过该功能可以避免因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>(); }
复制
深色
复制成功