如何检测用户何时处于最大缩放级别? (谷歌地图v3) [英] How do I detect when a user is at the maximum zoom level? (google maps v3)

查看:258
本文介绍了如何检测用户何时处于最大缩放级别? (谷歌地图v3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将我的标记集中在一起。当用户放大到最高级别时,我需要打开群集,以便用户可以查看单个项目的信息。鉴于缩放级别的数量取决于所用地图的类型而不同,并且'maxZoom'可能已在mapOptions中明确设置,我如何检测用户何时不能进一步缩放(即缩放滑块位于其最高点)?是否只有我可以使用的缩放级别号码(可能是21)?或者这个数字根据不同的情况而变化?这些情景会是什么?

I am clustering my markers together. When a user zooms in to the highest level I need to break the clusters up so that the user can view information for individual items. Given that the number of zoom levels is different depending on the type of map used and that 'maxZoom' may have been explicitly set in mapOptions, how do I detect when the user cannot zoom any further (i.e. the zoom slider is at its highest point)? Is there just a zoom level number I can use for this (21 perhaps)? Or is this number variable depending on different scenarios? What would these scenarios be?

在放大之前,我不需要知道这个值:只有当用户达到最高等级时。

I do not need to know this value prior to zooming in: only when the user REACHES the max level.

推荐答案

google maps api have a 服务,你可以像这样使用它:

google maps api have a service for that, you could use it like that:

(new google.maps.MaxZoomService()).getMaxZoomAtLatLng(map.getCenter(), function(response) {
    if (response.status != google.maps.MaxZoomStatus.OK) {
      alert("Error in MaxZoomService");
      return;
    } else {
      if (map.getZoom() >= response.zoom) {
          //do sth with your clusterer
          //probably markerClusterer.setMaxZoom(response.zoom - 1);
          //or markerClusterer.setMap(null);
      }
    }
});

编辑:我还在markerclusterer.js中找到了一个解决方案(来自google maps实用程序库),但它最近开始导致错误,我不确定它是否可靠:

there is also a solution I found in markerclusterer.js (from google maps utility library), but it recently started to cause errors and I am not sure if it is reliable:

map.mapTypes[map.getMapTypeId()].maxZoom;

这篇关于如何检测用户何时处于最大缩放级别? (谷歌地图v3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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