客户端脚本
01.<pre class="jscript" name="code">function getObjectById(id)
02.{
03. if (typeof(id) != "string" || id == "")
04. return null;
05.
06. if (document.all)
07. return document.all(id);
08.
09. if (ElementById)
10. ElementById(id);
11.
12. try
13. {
14. return eval(id);
15. }
16. catch(e)
17. {
18. return null;
19. }
agv驱动器20.}
<pre class="jscript" name="code">function getObjectById(id)
隐私保护通话
{
if (typeof(id) != "string" || id == "")
return null;
if (document.all)
return document.all(id);
if (ElementById)
ElementById(id);
try
{
return eval(id);
}
catch(e)
{
return null;
}
}
view plaincopy to clipboardprint?
01.var MapImg = getObjectById('DigitalMapCtl_Image');//见Public.js
02.if(MapImg != null)
03.{
04. //MapImg.attachEvent('onmousewheel',MapCtlMouseWheel);仅为IE
05. //linkEvent(MapImg,'mousewheel',MapCtlMouseWheel);IE和NS //见Public.js
安全带插销06. usewheel = MapCtlMouseWheel;//绑定onmousewheel事件
07. useout = MapCtlMouseOut;
08.}
09.
10.function MapCtlMouseOut()
11.{
12. usewheel = function(){return true;};//鼠标离开MapControl范围时归还,onmousewheel事件给body
13.}
14.
15.///在地图上滚动鼠标滚轮放大缩小地图
16.///滚动请求地图图片
17.function MapCtlMouseWheel()
18.{
19. usewheel = function(){return false;};//鼠标在MapControl内,截获Body onmousewheel事件 再放大缩小地图时,文档滚动条不会随之滚动
20. var mapImg = ElementById('DigitalMapCtl_Image');
21. eventXY = new Point(event.x,event.y);////Point()参见MapXtremeWebResources/Interaction.js内部定义
22. var pointString = ""+"1,";
23. igin = GetAbsPos(mapImg);//GetAbsPos()参见MapXtremeWebResources/Interaction.js内部定义
24. var offsetObj = igin; //这个点的转换过程
25. if(eventXY.y != -99999) //参考MapXtremeWebResources内
26. { //Command.js 增加点串到url的
27. pointString += (eventXY.x - offsetObj.x) + "_" + (eventXY.y - offsetObj.y); //处理方式.
28. } //
29. else //
30. {
//
31. pointString += eventXY.x + "_" + eventXY.y; //
32. } //
33. var url = "MapController.ashx?Command=WheelZoom&Width=" + mapImg.width +"&Height="
34. + mapImg.height +"&ExportFormat=" + portFormat + "&Ran=" + Math.random()
35. + "&wheelvalue=" + event.wheelDelta + "&MapAlias=" + mapImg.mapAlias+"&Points=1,"+event.x + "_" + event.y; //pointString;
36.
37. var xmlHttp = new CreateXMLHttp();//引用于MapXtremeWebResources/Command.js
38. xmlHttp.open("GET",url,false);
39. xmlHttp.send();
40. mapImg.src = url;
41.}
42.//服务器端命令工具参见 CustomMapTools命名空间 WheelZoom类
var MapImg = getObjectById('DigitalMapCtl_Image');//见Public.js
if(MapImg != null)
{
//MapImg.attachEvent('onmousewheel',MapCtlMouseWheel);仅为IE
//linkEvent(MapImg,'mousewheel',MapCtlMouseWheel);IE和NS //见Public.js
}
function MapCtlMouseOut()
{
usewheel = function(){return true;};//鼠标离开MapControl范围时归还,onmousewheel事件给body
}
///在地图上滚动鼠标滚轮放大缩小地图
///滚动请求地图图片
function MapCtlMouseWheel()
{
usewheel = function(){return false;};//鼠标在MapControl内,截获Body onmousewheel事件 再放大缩小地图时,文档滚动条不会随之滚动
var mapImg = ElementById('DigitalMapCtl_Image');
eventXY = new Point(event.x,event.y);////Point()参见MapXtremeWebResources/Interaction.js内部定义
var pointString = ""+"1,";
var offsetObj = igin; //这个点的转换过程
if(eventXY.y != -99999) //参考MapXtremeWebResources内
{ //Command.js 增加点串到url的
pointString += (eventXY.x - offsetObj.x) + "_" + (eventXY.y - offsetObj.y); //处理方式.
} //
else //
{ //
pointString += eventXY.x + "_" + eventXY.y; //
} //
var url = "MapController.ashx?Command=WheelZoom&Width=" + mapImg.width +"&Height="
+ mapImg.height +"&ExportFormat=" + portFormat +
"&Ran=" + Math.random()
+ "&wheelvalue=" + event.wheelDelta + "&MapAlias=" + mapImg.mapAlias+"&Points=1,"+event.x + "_" + event.y; //pointString;
var xmlHttp = new CreateXMLHttp();//引用于MapXtremeWebResources/Command.js
xmlHttp.open("GET",url,false);
xmlHttp.send();
mapImg.src = url;
}
//服务器端命令工具参见 CustomMapTools命名空间 WheelZoom类
服务器端代码
view plaincopy to clipboardprint?
01.#region Class WheelZoom Command
02./// <summary><summary></summary>
03./// 鼠标滚轮自定义命令,实现鼠标滚轮放大缩小地图
04./// </summary>
05.[Serializable]
06.public class WheelZoom : MapBaseCommand
07.{
08. public WheelZoom()
09. {
10. Name = "WheelZoom";//工具名称
11. }
12.
13. public override void Process()
14. {
15. int wheelvalue = int.Parse(System.Convert.ToString(HttpContext.Current.Request["wheelvalue"]));//获取滚轮值
16. System.Drawing.Point[] cPoint = ExtractPoints(DataString);
17. MapControlModel model = MapControlModel.GetModelFromSession();
18. model.SetMapSize(MapAlias, MapWidth, MapHeight);
19. try
20. {
21. MapInfo.Mapping.Map myMap = model.GetMapObj("map1");
22. MapInfo.Geometry.Distance d = new MapInfo.Geometry.Distance(myMap.Zoom.Value * 0.1, myMap.Zoom.Unit);
23. if (wheelvalue > 0)
24. d = new MapInfo.Geometry.Distance(myMap.Zoom.Value * (1 - 0.1), myMap.Zoom.Unit)
;//缩小到原来的90%
液晶屏保护膜
25. else
26. d = new MapInfo.Geometry.Distance(myMap.Zoom.Value * (1 + 0.1), myMap.Zoom.Unit);//放大到原来的110%
27. myMap.Zoom = d;
28. model.Center(MapAlias, cPoint[0]);
29. }
30. finally
31. {
32. System.IO.MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);
33. StreamImageToClient(ms);
34. }
牧草割草机
35. }
36.}
37.#endregion
鼠标滚轮放大缩小地图
首先在地图容器上添加滚轮事件:
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 = ElementById("MapControl1_Image");
if (mapImage.mapAlias)
url += "&MapAlias=" + mapImage.mapAlias;
url+="&Width="+mapImage.width+"&Height="+mapImage.height+"&ExportFormat="+portFormat;
url+="&ZoomValue="+zoomValue;
mapImage.src =url;
}
服务器端代码(cs文件namespace CustomWebTools):
/// <summary>
/// 鼠标滚轮放大缩小地图
/// </summary>
[Serializable]
public class MouseWheelZoomMap : MapInfo.WebC
ontrols.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());