限制最小/最大变焦在Bing地图与AJAX控件V7? [英] Restrict the min/max zoom on a Bing Map with v7 of the AJAX control?

查看:166
本文介绍了限制最小/最大变焦在Bing地图与AJAX控件V7?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个网站,它使用Bing地图AJAX控件V7的。其中一个我需要做的事情是放大以往限制缩放级别,以prevent用户一定水平,或者缩小过去的一定水平。

I'm working on a site that makes use of v7 of the Bing Maps AJAX Control. One of the things I need to do is restrict the zoom level so as to prevent users from zoom in past a certain level, or zoom out past a certain level.

我发现Map对象上的getZoomRange的方法,检查后,它只是返回一个对象常量最小和最大的属性。所以,我想超载,它可能会做的伎俩:

I found a "getZoomRange" method on the Map object, after inspecting it, it simply returns an object literal with "min" and "max" properties. So, I figured overloading it would probably do the trick:

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

......但是没有。它有没有影响(实际使用默认的仪表板,当有事情做与缩放滑块的外观)。

...but no. It has no effect (it actually has something to do with the appearance of the zoom slider when using the default Dashboard).

劫持事件和$ P $从程序pventing它似乎也没有任何效果。

Hijacking the event and preventing it from proceeding also seems to have no effect.

推荐答案

据Bing地图的支持,只有这样,才能做到这一点(这是不是特别优雅,并导致在地图上的一些不受欢迎的抖动)如下:

According to Bing Maps support, the only way to do this (which isn't particularly elegant, and results in some unwelcome jitter on the map) is as follows:

// "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
    });
  }
};

这篇关于限制最小/最大变焦在Bing地图与AJAX控件V7?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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