markerClusterer点击放大
我刚刚在我的谷歌地图上添加了一个MarkerClusterer。它工作得很好。markerClusterer点击放大
我只是想知道是否有任何方式来调整集群点击时的放大行为。如果可能,我想改变缩放级别。
有没有办法达到这个目的?
感谢
我按照建议修改了clusterclick事件:
/**
* Triggers the clusterclick event and zoom's if the option is set.
*/
ClusterIcon.prototype.triggerClusterClick = function() {
var markerClusterer = this.cluster_.getMarkerClusterer();
// Trigger the clusterclick event.
google.maps.event.trigger(markerClusterer, 'clusterclick', this.cluster_);
if (markerClusterer.isZoomOnClick()) {
// Zoom into the cluster.
// this.map_.fitBounds(this.cluster_.getBounds());
// modified zoom in function
this.map_.setZoom(markerClusterer.getMaxZoom()+1);
}
};
它很棒!非常感谢
它出现的API只会让你切换缩放功能性
http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/docs/reference.html
所以你必须编辑源,这似乎是在线1055
/**
* Triggers the clusterclick event and zoom's if the option is set.
*/
ClusterIcon.prototype.triggerClusterClick = function() {
var markerClusterer = this.cluster_.getMarkerClusterer();
// Trigger the clusterclick event.
google.maps.event.trigger(markerClusterer, 'clusterclick', this.cluster_);
if (markerClusterer.isZoomOnClick()) {
// Zoom into the cluster.
this.map_.fitBounds(this.cluster_.getBounds());
}
};
已经有一个更新MarkerClusterer源代码,允许单击事件更容易访问:
google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) {
// your code here
});
其中“markerCluster” IST的MarkerCluster对象。 里面的功能,您还可以访问
cluster.getCenter();
cluster.getMarkers();
cluster.getSize();
我使用它来切换到不同的地图类型,因为我用更简单的概述定制片集合较低缩放级别:
map.setCenter(cluster.getCenter()); // zoom to the cluster center
map.setMapTypeId(google.maps.MapTypeId.ROADMAP); // switch map type
map.setOptions(myMapOptions); // apply some other map options (optional)
问候 杰克
这是否记录在某处? – blacklwhite 2016-02-18 16:31:21
它记录在这里: https://raw.githubusercontent.com/googlemaps/v3-utility-library/master/markerclustererplus/docs/reference.html – 2017-04-04 21:53:44
你可以做到这一点,而不使用监听器的clusterclick markerClusterer事件修改源代码:
var mcOptions = {gridSize: 40, maxZoom: 16, zoomOnClick: false, minimumClusterSize: 2};
markerClusterer = new MarkerClusterer(map, markers, mcOptions);
google.maps.event.addListener(markerClusterer, 'clusterclick', function(cluster){
map.setCenter(cluster.getCenter());
map.setZoom(map.getZoom()+1);
});
即。我设置了zoomOnClick = false以更好地控制地图缩放行为,以控制每次点击触发的缩放量和缩放位置。
如果有人需要在coffeescript中编写这个函数,我把最上面的答案和标记的答案合并成一个代码片段。
mcOptions =
maxZoom: 16
markerCluster = new MarkerClusterer map, markers, mcOptions
# listener if a cluster is clicked
google.maps.event.addListener markerCluster, "clusterclick", (cluster) ->
if markerCluster.isZoomOnClick() # default is true
#get bounds of cluster
map.fitBounds cluster.getBounds()
#zoom in to max zoom plus one.
map.setZoom markerCluster.getMaxZoom() + 1
此代码检查是放大点击设置。如果它放大到最大变焦加1,并居中在集群上。非常简单的代码。
上述代码与原始代码有什么区别? – Kabkee 2015-09-11 06:12:24
@Kabkee不同的是,这实际上改变了放大和上面的代码是一个骨架。 – Whitecat 2017-05-14 05:26:33