I created Custom Cluster Render
extending DefaultClusterRenderer<T>
, while using Google Maps Api
and android maps utils
. According to the following guide
https://github.com/googlemaps/android-maps-utils/blob/master/demo/src/com/google/maps/android/utils/demo/CustomMarkerClusteringDemoActivity.java
在使用Google Maps Api和Android地图实用程序时,我创建了自定义集群渲染扩展DefaultClusterReneller
。根据以下指南https://github.com/googlemaps/android-maps-utils/blob/master/demo/src/com/google/maps/android/utils/demo/CustomMarkerClusteringDemoActivity.java
When I have more then too many markers
in the same area, they cluster into the one. But the don't separate onto markers
while zooming, and I can see
当我在同一区域有超过太多的标记时,它们就会聚集在一起。但在缩放时不会分离到标记上,我可以看到
http://cs627121.vk.me/v627121202/51eb5/rY9f4p8ivos.jpg
Http://cs627121.vk.me/v627121202/51eb5/rY9f4p8ivos.jpg
Here's some code:
以下是一些代码:
public PlaceRender(Context context, GoogleMap map, ClusterManager<MyCluster> clusterManager) {
super(context, map, clusterManager);
mIconGenerator = new IconGenerator(context);
imageView = new ImageView(context);
mClusterImageView = new ImageView(context);
mIconGenerator.setContentView(imageView);
this.context = context;
this.map = map;
this.myClusterManager = clusterManager;
}
@Override
protected void onBeforeClusterItemRendered(MyCluster cluster, MarkerOptions markerOptions) {
super.onBeforeClusterItemRendered(cluster, markerOptions);
markerOptions.title(cluster.name).snippet(cluster.snippet);
markerOptions.infoWindowAnchor(0.5f, 0.0f);
}
@Override
protected void onBeforeClusterRendered(Cluster<MyCluster> cluster, MarkerOptions markerOptions) {
super.onBeforeClusterRendered(cluster, markerOptions);
}
@Override
protected boolean shouldRenderAsCluster(Cluster cluster) {
// Always render clusters.
return cluster.getSize() > 1;
}
@Override
protected void onClusterRendered(Cluster<MyCluster> cluster, Marker marker){
super.onClusterRendered(cluster, marker);
}
@Override
protected void onClusterItemRendered(MyCluster geo, Marker marker) {
super.onClusterItemRendered(geo, marker);
loadIconFromApi(geo, marker);
}
public void addItems(List<MyCluster> clusters, Context context, GoogleMap map) {
myClusterManager = new ClusterManager<>(context, map);
map.setOnMarkerClickListener(this);
for (int i = 0; i < clusters.size(); i++) {
myClusterManager.addItem(clusters.get(i));
myClusterManager.setRenderer(new PlaceRender(context, map, myClusterManager));
}
myClusterManager.cluster();
}
//
private void loadIconFromApi(MyCluster geo, Marker marker) {
PicassoMarker markers = new PicassoMarker(marker, mIconGenerator, imageView);
geo.setPicassoMarker(markers);
Picasso.with(context).load(geo.image).into(markers);
}
@Override
public boolean onMarkerClick(Marker marker) {
marker.showInfoWindow();
return true;
}
If I use 15x camera zoom
, so I can see every marker, and then zoom out
it, my markers won't merge into the one cluster
.
如果我使用15倍的相机变焦,这样我可以看到每个标记,然后缩小它,我的标记不会合并到一个簇中。
What did I missed?
我错过了什么吗?
更多回答
Please clarify as it is unclear what is the problem. Is it that markers do not cluster when you zoom out or they do not stop clustering when you zoom in to them? Or both?
由于不清楚问题出在哪里,请澄清。是缩小时标记不会聚集,还是放大时标记不会停止聚集?或者两者兼而有之?
优秀答案推荐
Your shouldRenderAsCluster()
is always clustering due to the condition you set.
由于您设置的条件,您的shouldRenderAsCluster()始终是集群的。
cluster.getSize() > 1;
You can check out a similar SO post over here
你可以在这里查看类似的so帖子
Also, try to check out this SO post. Figured that you are using PicassoMarker library which might have affected your cluster rendering too.
另外,试着去看看这篇文章。我想你使用的是PicassoMarker库,这可能也影响了你的集群渲染。
For me, I did not set CameraIdleListener with the map object.
Started to work and show individual pins when I zoomed in after setting CameraIdleListener as well as MarkerClickListener.
followed the implementation here
对于我来说,我没有使用map对象设置CameraIdleListener。在设置CameraIdleListener和MarkerClickListener后,当我放大时,开始工作并显示单独的管脚。遵循此处的实施
myClusterManager = new ClusterManager<>(context, map);
// Point the map's listeners at the listeners implemented by the cluster
// manager.
map.setOnCameraIdleListener(myClusterManager);
map.setOnMarkerClickListener(myClusterManager);
I needed to add this function and call it in onCameraChange
我需要添加此函数并在onCameraChange中调用它
public void updateUI(List<MyCluster> clusters) {
myClusterManager.clearItems();
for (int i = 0; i < clusters.size(); i++) {
myClusterManager.addItem(clusters.get(i));
// myClusterManager.setRenderer(new PlaceRender(context, map, myClusterManager));
}
myClusterManager.onCameraChange(map.getCameraPosition());
}
更多回答
Yeah, you're right. if I return false
in shouldRenderAsCluster()
markers don't cluster. But, how can I reach clustering
and unclustering
while zooming using Picasso
?
是啊,你说得对。如果我在shresdRenderAsCluster()中返回FALSE,则标记不会聚集。但是,如何在使用毕加索进行缩放的同时实现聚集和解聚呢?
我是一名优秀的程序员,十分优秀!