MapXtreme2005 Web页面上用鼠标中间键控制地图缩放

 

一、在页面的</form>之前添加如下js代码:
<script type="text/javascript">
        var Img = document.getElementById("MapControl1_Image");
        if(Img != null)
        {
            Img.attachEvent('onmousewheel', bbb);
        }
       
        function bbb()
        {
            var mapImage = document.getElementById("MapControl1_Image");
            var url = "MapController.ashx?Command=WheelZoom&Width=" + mapImage.width +"&Height=" + mapImage.height +"&ExportFormat=" + mapImage.exportFormat + "&Ran=" + Math.random() + "&wheelvalue=" + event.wheelDelta;
              if (mapImage.mapAlias)
                     url +=  "&MapAlias=" + mapImage.mapAlias;   
              var xmlHttp = CreateXMLHttp();
              xmlHttp.open("GET", url, false);
              xmlHttp.send(null);
              try {
            mapImage.src = url;
              } catch(e) { alert("ll"); }
         }
    </script>           
 

二、在后端代码添加如下类:

 

 

[Serializable]
public class WheelZoom : MapBaseCommand
{
    public WheelZoom()
    {
        Name = "WheelZoom";
    }

    public override void Process()
    {
        int wheelvalue = int.Parse(System.Convert.ToString(HttpContext.Current.Request["wheelvalue"]));
        MapControlModel model = MapControlModel.GetModelFromSession();
        model.SetMapSize(MapAlias, MapWidth, MapHeight);
        try
        {
            MapInfo.Mapping.Map myMap = model.GetMapObj("map1");
            MapInfo.Geometry.Distance d = new MapInfo.Geometry.Distance(myMap.Zoom.Value * 0.1, myMap.Zoom.Unit);
            if(wheelvalue > 0)
                d = new MapInfo.Geometry.Distance(myMap.Zoom.Value -900, myMap.Zoom.Unit);
            else
                d = new MapInfo.Geometry.Distance(myMap.Zoom.Value + 900, myMap.Zoom.Unit);
            myMap.Zoom = d;
        }
        finally
        {
            System.IO.MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);
            StreamImageToClient(ms);
        }
    }
}
 

 
三、在页面加载处注册command:

 

      

if(!IsPostBack)
 {
            MapControlModel model = MapControlModel.SetDefaultModelInSession();
            model.Commands.Add(new WheelZoom());
 }
    完毕,运行在页面地图上滚动鼠标中间键即可看到效果。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值