使用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
    });
  }
};

相关文章

IE6是一个非常老旧的网页浏览器,虽然现在很少人再使用它,但...
PHP中的count()函数是用来计算数组或容器中元素的个数。这个...
使用 AJAX(Asynchronous JavaScript and XML)技术可以在不...
Ajax(Asynchronous JavaScript and XML)是一种用于改进网页...
本文将介绍如何通过AJAX下载Excel文件流。通过AJAX,我们可以...
Ajax是一种用于客户端和服务器之间的异步通信技术。通过Ajax...