Mapxtreme2005+c# 用鼠标滑轮实现地图的放大缩小
Mapxtreme2005+c# 用鼠标滑轮实现地图的放大缩小请大家多多指教! --------------------编程问答-------------------- ding~~~ --------------------编程问答-------------------- 首先设置地图的鼠标滑轮事件,然后向服务端发起请求,按级别影响地图ZOOM值. liminghua_2001@hotmail.com --------------------编程问答-------------------- 都是很好的建议! 值得学习 --------------------编程问答-------------------- boy20000 每个帖子都回,就是没有第二次光顾;
也说不清楚问题的所在。
鼠标滚轮事件,需要现定义一个工具,客户端脚本和服务器脚本;具体情况我也不清楚
你上网查查。 --------------------编程问答-------------------- 在客户端脚本里写图片的鼠标滚动事件,执行事件时就向服务器发送一次请求,服务器发现是来自滚动放大的请求,此时就更新放大后的地图
function imageZoom()
{
var e=window.event||event;
if(e.wheelDelta<= 0||e.detail>0)
{
var mapImage = document.getElementById("MapControl1_Image");
if (!mapImage.mapAlias) mapImage.mapAlias = mapImage.attributes["mapAlias"].value;
if (!mapImage.exportFormat) mapImage.exportFormat = mapImage.attributes["exportFormat"].value;
this.url = "MapController.ashx?Command=ZoomInImage" +
"&Width=" + mapImage.width +
"&Height=" + mapImage.height +
"&ExportFormat=" + mapImage.exportFormat +
"&Ran=" + Math.random();
mapImage.src=this.url;
}
else
{
var mapImage = document.getElementById("MapControl1_Image");
if (!mapImage.mapAlias) mapImage.mapAlias = mapImage.attributes["mapAlias"].value;
if (!mapImage.exportFormat) mapImage.exportFormat = mapImage.attributes["exportFormat"].value;
this.url = "MapController.ashx?Command=ZoomOutImage" +
"&Width=" + mapImage.width +
"&Height=" + mapImage.height +
"&ExportFormat=" + mapImage.exportFormat +
"&Ran=" + Math.random();
mapImage.src=this.url;
}
} --------------------编程问答-------------------- 帮顶~~~~~~~ --------------------编程问答-------------------- boy 只给出了客户端的脚本,服务器端的处理脚本没有给出 --------------------编程问答-------------------- 首先在地图容器上添加滚轮事件:
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());
完成。
--------------------编程问答-------------------- 接分。 --------------------编程问答-------------------- onmousewheel="mouseWheelZoomMap()"
请问这句话应该放在程序的什么地方? --------------------编程问答-------------------- ZOOM ~~MapInfo的工具已经实现这个功能了~~你捕捉它的事件就可以 void Map_ViewChangedEvent(object sender, MapInfo.Mapping.ViewChangedEventArgs e)
{
补充:企业软件 , 地理信息系统