使用鼠标滚轮实现放大缩小地图
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());
完成。
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());
完成。
相关文章推荐
- 鼠标滚轮实现地图放大缩小 并以滚轮点为中心点
- mxGraph绘图区域使用鼠标滚轮实现放大/缩小
- ExtJs 完美实现图片在Window窗口中通过鼠标滚轮放大缩小以及点击拖拽
- [Unity3D]Unity3D游戏开发之鼠标滚轮实现放大缩小
- 用HTML5实现鼠标滚轮事件放大缩小图片的功能
- 修改ArcMap默认的鼠标滚轮放大缩小,AE实现修改鼠标滚轮放大缩小
- JS实现鼠标滚轮缩小放大拖动图片代码
- [Unity3D]Unity3D游戏开发之鼠标滚轮实现放大缩小
- 鼠标滚轮实现单文档视图的放大与缩小
- 图片实现鼠标滚轮滚动放大缩小图片
- 鼠标滚轮实现放大缩小
- js实现图片滚轮放大缩小以及鼠标拖动
- QGraphicsView放大和缩小下鼠标位置使用鼠标滚轮
- 【Unity3D自学记录】Unity3D游戏开发之鼠标滚轮实现放大缩小
- [Unity3D]Unity3D游戏开发之鼠标滚轮实现放大缩小
- [Unity3D]Unity3D游戏开发之鼠标滚轮实现放大缩小
- java JFrame去掉标题栏后如何实现鼠标移动到边框可以进行拖拉以放大缩小
- phpstrom 鼠标滚轮放大缩小字体
- 【C#】开发小记——关于WebBrowser中使用百度地图PanTo之后滚轮放大缩小失效
- IOS——地图的使用、地图定位到当前位置(包括ios8获取位置)、地图标注的添加、地图放大缩小监听