您的位置:首页 > 其它

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

2008-05-13 15:35 1471 查看
首先在地图容器上添加滚轮事件:
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());

完成。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: