微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我正在使用一个使用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
    });
  }
};

原文地址:https://www.jb51.cc/ajax/159857.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐