鼠標滾輪放大縮小地圖

 
首先在地圖容器上添加滾輪事件:
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());


完成。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章