在变焦集群地图标记出来,在上撤出群集变焦 [英] Clustering map markers on zoom out and unclustering on zoom in
问题描述
我使用的是谷歌地图Android的聚类Utitlity 随着谷歌地图V2播放服务。
I am using the Google Map Android clustering Utitlity With Google Maps v2 play services.
我没有得到我预期的行为。正如你可以在下面的两张图片看,当我放大可以看到20的集群和单个标记了一个向左,但是当我缩小直到他们都在彼此的顶部,我没有看到他们的集群。 ,20个集群还称20而不是21?
I am not getting the behavior I expected. As you can see in the two images below, when zoomed in I can see a cluster of 20 and a single marker up an to the left, but when i zoom out til they are on top of each other i am not seeing them cluster.. the 20 cluster still says 20 and not 21?
是预期的行为?有没有一种方法可以使集群展示的21,而不是20 +
Is that expected behavior? Is there a way can make the cluster show 21 instead of 20+
推荐答案
这是在<指定的默认行为href="https://github.com/googlemaps/android-maps-utils/blob/master/library/src/com/google/maps/android/clustering/view/DefaultClusterRenderer.java#L698"><$c$c>DefaultClasterRenderer#onBeforeClusterRendered()$c$c>:
/**
* Called before the marker for a Cluster is added to the map.
* The default implementation draws a circle with a rough count of the number of items.
*/
protected void onBeforeClusterRendered(Cluster<T> cluster, MarkerOptions markerOptions) {
int bucket = getBucket(cluster);
BitmapDescriptor descriptor = mIcons.get(bucket);
if (descriptor == null) {
mColoredCircleBackground.getPaint().setColor(getColor(bucket));
descriptor = BitmapDescriptorFactory.fromBitmap(mIconGenerator.makeIcon(getClusterText(bucket)));
mIcons.put(bucket, descriptor);
}
// TODO: consider adding anchor(.5, .5) (Individual markers will overlap more often)
markerOptions.icon(descriptor);
}
需要注意的是文本标记的基础上选择了斗
,而不是项目的确切数量的群集
Note that text for the marker is chosen based on the bucket
, rather than exact number of items in cluster
对于快速解决将是修改描述创作是这样的:
The quick fix for that would be to modify descriptor creation to be something like:
descriptor = BitmapDescriptorFactory.fromBitmap(mIconGenerator.
makeIcon(cluster.getSize());
当然你也可以实现自定义的 ClasterRenderer
,并把它提供给<一个href="https://github.com/googlemaps/android-maps-utils/blob/master/library/src/com/google/maps/android/clustering/ClusterManager.java#L74"><$c$c>ClusterManager$c$c>.通过这种方式,你将负责你的标志呈现的,但如果你想只改变20 +
到21
- 我将与第一种方法去
Of course you can implement your custom ClasterRenderer
and provide it to the ClusterManager
. In this way you will be in charge of rendering of your markers, but if you want to just change the "20+"
to "21"
- I would go with first approach
编辑:
解决问题问的评论: 如果你想增加/减少间距门槛分组项 - 您可以修改<一个href="https://github.com/googlemaps/android-maps-utils/blob/master/library/src/com/google/maps/android/clustering/algo/NonHierarchicalDistanceBasedAlgorithm.java#L35">default算法可用于群集。就在这个不断播放(在你的情况应该是更小的):
Addressing question asked in comments: If you want to increase/decrease distance threshold for grouping items - you can modify default algorithm used for clustering. Just play with this constant (in your case should be smaller):
public static final int MAX_DISTANCE_AT_ZOOM = 100; // essentially 100 dp.
但正确的解决将是考虑到标记位图的大小,而不是恒定值。我想先生Broadfood 离开,作为一个功课爱好者:)
But the correct fix would be to take into account Marker bitmap size rather than constant value. I assume Mr. Broadfood left that as a homework to enthusiasts :)
private Bounds createBoundsFromSpan(Point p, double span) {
// TODO: Use a span that takes into account the visual size of the marker, not just its
// LatLng.
double halfSpan = span / 2;
return new Bounds(
p.x - halfSpan, p.x + halfSpan,
p.y - halfSpan, p.y + halfSpan);
}
这篇关于在变焦集群地图标记出来,在上撤出群集变焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!