【发布时间】:2017-01-04 22:38:36
【问题描述】:
我有一个使用 Google 地图和 MarkerCluster API 的网页。 我需要能够以给定的缩放级别获取地图上的所有集群。以这段代码为例:
//Where the center of the screen will be
var center = new google.maps.LatLng(37.4419, -122.1419);
var options = {
'zoom': 13,
'center': center,
//Google map type
'mapTypeId': google.maps.MapTypeId.ROADMAP
};
//Create the google map
var map = new google.maps.Map(document.getElementById("map"), options);
//Create the marker clusters, where markers is an array of lat and longs
var mc = new MarkerClusterer(map, markers);
//Print all of the clusters at zoom level 13
console.log(mc.getTotalClusters());
问题是如果缩放级别为 13 时有 10 个集群,但只有 7 个在我的屏幕范围内,那么上面的代码只会打印出 7 个。我需要一种方法来访问 all em> 簇,即使它们不在屏幕上。
MarkerClusterer 工作原理的简单示例: https://googlemaps.github.io/js-marker-clusterer/examples/simple_example.html
以下是对 MarkerCluster API 的一些引用:
https://googlemaps.github.io/js-marker-clusterer/docs/reference.html
https://googlemaps.github.io/js-marker-clusterer/docs/examples.html
【问题讨论】:
标签: javascript google-maps markerclusterer