最大变焦在不同地区是不同的

问题描述 投票:0回答:2

在陆地上我最多可以放大到 20 点,但是在海洋上我只能放大到 7-12 点(这取决于你在哪个位置缩放)。如果我在海洋上放大 7-12 点以上,我会在浏览器控制台 (https://khms0.googleapis.com/kh?v=944&hl=en-GB&x=260660&y=177418&z=19) 中看到 404 错误,当我到达 19 地图变成灰色。

有没有办法根据您站立的坐标限制最大缩放值并消除控制台错误?

leaflet http-status-code-404 zoom-sdk
2个回答
0
投票

您可以使用

MaxZoomService
available in the api 获取特定区域可用的最大缩放级别 api。

这样你就可以遵循这个算法:

  1. 获取当前位置
  2. 通过google maps api获取当前位置可用的最大缩放
  3. 将其设置为传单的最大缩放
  4. 获取地图当前的放大倍数
  5. If currentZoom > maxZoom, then zoom out to the max zoom available

0
投票

这里是完整的代码:

var maxZoomService = new google.maps.MaxZoomService();

mapDrawing.map.on('moveend', function () {
  maxZoomService.getMaxZoomAtLatLng(
    map.getCenter(),
    result => {
      if (result.status === "OK") {
        map.options.maxZoom = result.zoom;
      }
    }
  );
});
© www.soinside.com 2019 - 2024. All rights reserved.