加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用AJAX控件的v7限制Bing地图上的最小/最大缩放?

发布时间:2020-12-16 01:35:06 所属栏目:百科 来源:网络整理
导读:我正在使用一个使用Bing Maps AJAX控件的v7的网站.我需要做的一件事是限制缩放级别,以防止用户在一定程度上放大,或者缩小到一定程度. 我在Map对象上找到一个“getZoomRange”方法,检查它后,只需返回一个“min”和“max”属性的对象文字.所以,我认为重载它可
我正在使用一个使用Bing Maps AJAX控件的v7的网站.我需要做的一件事是限制缩放级别,以防止用户在一定程度上放大,或者缩小到一定程度.

我在Map对象上找到一个“getZoomRange”方法,检查它后,只需返回一个“min”和“max”属性的对象文字.所以,我认为重载它可能会做的诀窍:

// "map" is our Bing Maps object
map.getZoomRange = function ()
{
  return {
    max:      14
    min:      5
  };
};

…但不是.它没有任何效果(实际上与使用默认仪表板时缩放滑块的外观有关).

劫持事件并阻止事件进行也似乎没有效果.

根据Bing Maps的支持,做到这一点的唯一方法(这不是特别优雅,并且在地图上导致了一些不受欢迎的抖动)如下:
// "map" is our Bing Maps object,overload the built-in getZoomRange function
// to set our own min/max zoom
map.getZoomRange = function ()
{
  return {
    max:      14,min:      5
  };
};

// Attach a handler to the event that gets fired whenever the map's view is about to change
Microsoft.Maps.Events.addHandler(map,'viewchangestart',restrictZoom);

// Forcibly set the zoom to our min/max whenever the view starts to change beyond them 
var restrictZoom = function ()
{
  if (map.getZoom() <= map.getZoomRange().min) 
  {
    map.setView({
      'zoom':       map.getZoomRange().min,'animate':    false
    });
  }
  else if (map.getZoom() >= map.getZoomRange().max) 
  {
    map.setView({
      'zoom':       map.getZoomRange().max,'animate':    false
    });
  }
};

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读