markerClusterer上点击缩放
markerClusterer on click zoom
本文关键字:缩放 markerClusterer 更新时间:2023-09-26
我刚刚在我的谷歌地图上添加了一个MarkerClusterer。它工作得很好。
我只是想知道是否有任何方法调整放大行为时,集群被点击。如果可能的话,我想更改一下缩放级别。
有办法做到这一点吗?
谢谢
对MarkerClusterer源代码进行了更新,允许更容易地访问单击事件:
google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) {
// your code here
});
其中'markerCluster'列出了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)
的问候杰克
您可以通过在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(markerClusterer.getCenter());
map.setZoom(map.getZoom()+1);
});
ie。我设置zoomOnClick=false是为了更好地控制地图缩放行为,控制每次点击触发的缩放量和缩放位置。
我按照建议修改了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());
}
};
如果有人需要在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
此代码检查是否放大,单击是否设置。如果是,则将其放大到max zoom + 1,并以集群为中心。非常简单的代码。
相关文章:
- 更改高贴图的缩放级别
- 在不阻止默认行为的情况下检测IE10中的缩放
- 单击超链接时,如何使用Google Maps API v3缩放地图
- 缩放Raphael/SVG容器以适应所有内容
- 传单缩放控制位置错误
- 在不移动内部文本的情况下缩放元素的效果
- 调整缩放窗口高度提升缩放
- 计算CSS3缩放框在另一个框中的最高位置
- D3.JS向rect添加缩放和列表项
- 当我在节点上拖动鼠标时,我如何防止使用d3.ehavior.zoom().on(“缩放”,重绘)
- 将直流图表库中的折线图缩放限制为小时
- 为什么缩放按钮不会显示在照片擦除中
- 动态设置谷歌地图缩放
- 如何缩放像图像一样的元素
- 使用KineticJS变换(移动/缩放/旋转)形状
- 在手机上缩小/缩放滚动图像
- 将时间缩放添加到折线图(Chart.js)
- 当涉及css缩放时,如何获得页面上的点击位置
- 如何缩放地图框传单中的标记单击事件
- 自动缩放图像以匹配文本高度