简体   繁体   English

Fluster 2如何以特定的缩放级别显示所有标记

[英]Fluster 2 how to show all markers at a specific zoom level

I am using fluster 2 to cluster markers and have found that the fluster clustering method is overly aggressive. 我正在使用fluster 2对标记进行聚类,并且发现fluster聚类方法过于激进。 So that even when I am zoomed in to city level I still end up having a lot more clusters than I really want. 因此,即使我放大到城市级别,我仍然会拥有比我真正想要的集群更多的集群。 Does anyone know how to modify the fluster .js to make it show all markers once you get down to say zoom level 5? 有谁知道如何修改fluster .js,一旦您说到5级缩放,它就会显示所有标记?

There is a bit too much code relating to fluster to add here, so this question is more for people who already use fluster for their marker clustering needs. 这里有太多与fluster相关的代码要添加,因此对于已经使用fluster满足标记聚类需求的人们来说,这个问题更多。

Thank you, 谢谢,

you can make a listener on the zoom level of your map and then control the clusters. 您可以在地图的缩放级别上设置一个侦听器,然后控制群集。 this an example of what probably your code shoud look like. 这是您的代码应该看起来像的一个示例。 I havent tested the code , the comple tutorial from which i took the code is here . 我还没有测试代码,我从中获取代码的comple教程在这里

var fluster = new Fluster2(map);
// Set styles for the clustered icons
fluster.styles = {
  0: {
    image: "http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m1.png",
    textColor: "#FFFFFF",
    width: 53,
    height: 52
  },
  10: {
    image: "http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m2.png",
    textColor: "#FFFFFF",
    width: 56,
    height: 55
  },
  15: {
    image: "http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m3.png",
    textColor: "#FFFFFF",
    width: 66,
    height: 65
  }
};
// Initialize Fluster
// This will set event handlers on the map and calculate clusters the first time.
fluster.initialize();

// Event listener for switching to Street View/Road Map to show/hide the
// close button, respectively
google.maps.event.addListener(panorama,"visible_changed",toggleVisible);

// Add a listener to the zoom change event so we can change the grid size
// of the cluster script. Should be dynamic!
google.maps.event.addListener(map, "zoom_changed", function() {

  var zoomLevel = map.getZoom();

  switch(true){
    case zoomLevel > 13:
      fluster.gridSize = 0;
      break;
    case zoomLevel > 12:
      fluster.gridSize = 10;
      break;
    case zoomLevel > 7:
      fluster.gridSize = 20;
      break;
    case zoomLevel > 5:
      fluster.gridSize = 40;
      break;
    default:
      fluster.gridSize = 60;
      break;
  }

});

Good answer Zied. 好的答案Zied。

BTW if you have multiple markers with the same position, the clustering will still happen even though the gridSize is 0. To get around this set the grid to -1 顺便说一句,如果您有多个具有相同位置的标记,即使gridSize为0,聚类仍然会发生。要解决此问题,请将网格设置为-1

    google.maps.event.addListener(map, "zoom_changed", function() {

  var zoomLevel = map.getZoom();

  switch(true){
    case zoomLevel > 13:
      fluster.gridSize = -1;
          break;
    case zoomLevel > 12:
      fluster.gridSize = 10;
      break;
    case zoomLevel > 7:
      fluster.gridSize = 20;
      break;
    case zoomLevel > 5:
      fluster.gridSize = 40;
      break;
    default:
      fluster.gridSize = 60;
      break;
  }

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM