使用鼠标滚轮实现放大缩小地图

首先在地图容器上添加滚轮事件:
onmousewheel="mouseWheelZoomMap()"
客户端脚本:
//鼠标在地图区的滚轮事件

function mouseWheelZoomMap(){
    var zoomValue="";
    if(window.event.wheelDelta>0){
        zoomValue=0.5;
    }
    else{
        zoomValue=2;
    }
    var url = "MapController.ashx?Command=MouseWheelZoomMap&Ran=" + Math.random();
 var mapImage = document.getElementById("MapControl1_Image");                       
 if (mapImage.mapAlias)
  url +=  "&MapAlias=" + mapImage.mapAlias;
 url+="&Width="+mapImage.width+"&Height="+mapImage.height+"&ExportFormat="+mapImage.exportFormat;
 url+="&ZoomValue="+zoomValue;
 mapImage.src =url;
}

服务器端代码(cs文件namespace CustomWebTools):
/// <summary>
/// 鼠标滚轮放大缩小地图
/// </summary>
[Serializable]
public class MouseWheelZoomMap : MapInfo.WebControls.MapBaseCommand
{
    /// <summary>
    /// Constructor for this command, sets the name of the command
    /// </summary>
    /// <remarks>None</remarks>
    public MouseWheelZoomMap()
    {
        Name = "MouseWheelZoomMap";
        //Execute();
    }

    /// <summary>
    /// This method gets the map object out of the mapfactory with given mapalias and
    /// Adds a point feature into a temp layer, exports it to memory stream and streams it back to client.
    /// </summary>
    /// <remarks>None</remarks>

    public override void Process()
    {
        MapControlModel model = MapControlModel.GetModelFromSession();
        if (MapAlias == null) return;
        model.SetMapSize(MapAlias, MapWidth, MapHeight);

        MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
        if (map == null) return;
        //map.Bounds = map.Layers.Bounds;
        double zoomValue =Convert.ToDouble( HttpContext.Current.Request["ZoomValue"].ToString());
        double ZoomLevel = map.Zoom.Value * zoomValue;

        model.Zoom(MapAlias,-1.0,ZoomLevel);
        MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);
        StreamImageToClient(ms);
    }
}
最后在mapForm.cs的Page_Load()事件中添加:
            MapInfo.WebControls.MapControlModel controlModel = MapControlModel.SetDefaultModelInSession();

            // add custom commands to control model
            controlModel.Commands.Add(new CustomWebTools.MouseWheelZoomMap());

完成。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值