Maps API v3在不同缩放级别进行聚类 [英] Maps API v3 clustering at different zoom levels

查看:93
本文介绍了Maps API v3在不同缩放级别进行聚类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个需要集群的地图项目。我实现了商店定位器并使用了MarkerClusterer,它工作正常。现在我有另一个客户的要求,我想知道应该使用哪种解决方案来实现这些目标:


  • 缩放级别0:集群标记距离彼此有1500km

  • 缩放级别1:1000公里内的集群

  • 缩放级别2:750公里内的集群
  • 缩放级别3:400公里内的集群

  • 缩放级别4及以上:无集群



我在想我应该一起使用MarkerManager和MarkerClusterer,但我不确定这一点。任何帮助让我走上正轨?



预先感谢!

>

您只能使用 MarkerClusterer ,但您必须修改某些选项。

为防止级别4后面的clusterer动作,您必须使用 maxZoom 属性。它定义了聚类器可以聚集标记的最高水平,所以在你的情况下,你必须在4点修正它。

然后,要改变网格的大小取决于缩放级别,请使用 gridSize 属性。您可以在文档中找到所有选项字段的定义



因此,您的MarkerClusterer实例将如下所示:

  var mcOptions = {gridSize:/ *您的值* /,maxZoom:4}; 
var markerCluster = new MarkerClusterer(map,/ *您的数组标记* / mcOptions);


I am working on a map project where I need clustering. I implemented a store locator and used MarkerClusterer which works fine. Now I have another requirement from the customer and I wonder which solution I should use to achieve these goals:

  • Zoom level 0: Cluster markers within 1500km distance to each other
  • Zoom level 1: Cluster within 1000km
  • Zoom level 2: Cluster within 750km
  • Zoom level 3: Cluster within 400km
  • Zoom level 4 and above: no clustering

I was thinking I should be using MarkerManager and MarkerClusterer together, but I am not sure about that. Any help to get me on the right path?

Thanks in advance!

解决方案

You can only use MarkerClusterer, but you have to modify some options.

To prevent the clusterer acts after level 4, you have to use maxZoom property. It defines the max level where the clusterer can cluster marker, so in your case, you have to fix it at 4.

Then, to change the size of the grid depending the zoom level, use gridSize property. You can find a definition of all option fields on the doc.

So, your MarkerClusterer instanciation will look like something like this :

var mcOptions = {gridSize: /*Your value*/, maxZoom: 4};
var markerCluster = new MarkerClusterer(map, /*your array of markers*/ mcOptions);

这篇关于Maps API v3在不同缩放级别进行聚类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆