SuperMap IS.NET自定义Action之兴趣点标注

在SuperMap IS.NET AjaxScripts开发中,提供了一个名为SuperMap.IS.Action.js的脚本文件,供开发人员添加自定义动作。

兴趣点(Point Of  Interest)标注算是经常用到的功能,供用户在浏览地图时,对自己感兴趣内容在图上进行标注。

本脚本算是初步完成,提供文本、点、线和面的标注。代码如下:

  1. //用户自定义兴趣点标注
  2. //title: 标注名
  3. //note: 备注
  4. //showPic: 是否显示logo ture/false
  5. //hotpic: logo图片名(包含后缀)
  6. SuperMap.IS.DrawMarkPointAction=function(title, note, showPic, hotpic)
  7. {
  8.     this.type="SuperMap.IS.DrawMarkPointAction";
  9.     var x=null;
  10.     var y=null;
  11.     var _showPic=false;
  12.     var _hotpic=null;
  13.    
  14.     this.Init=function(mapControl)
  15.     {
  16.         this.mapControl=mapControl;
  17.         if(ygPos.browser=="ie")
  18.         {
  19.             mapControl.container.style.cursor="images/cursors/PointQuery.cur";
  20.         }
  21.         else
  22.         {
  23.             mapControl.container.style.cursor="crosshair";
  24.         }
  25.         
  26.         if(showPic != null)
  27.         {
  28.             _showPic = showPic;
  29.         }
  30.         
  31.         if(hotpic == null)
  32.         {
  33.             _hotpic = "images/hotball.gif";
  34.         }
  35.         else
  36.         {
  37.             _hotpic = "images/" + hotpic;
  38.         }
  39.     }
  40.     
  41.     this.Destroy=function()
  42.     {
  43.         this.mapControl=null;
  44.         x=null;
  45.         y=null;
  46.     }
  47.     
  48.     function _OnClick(e)
  49.     {
  50.        x = e.mapCoord.x;
  51.        y = e.mapCoord.y;
  52.        
  53.        if(_showPic == true)
  54.        {
  55.            this.mapControl.CustomLayer.AddMark("markPoint", x, y, nullnull"<div><img src='" + _hotpic + "' style='cursor:pointer' title='" + note + "' /><span> " + title + "</span></div>");
  56.        }
  57.        else
  58.        {
  59.            this.mapControl.CustomLayer.AddMark("markPoint", x, y, nullnull"<div><b>" + title + "</b> " + note + "</div>");
  60.        }
  61.     }
  62.     
  63.     function _OnContextMenu(e)
  64.     {
  65.         this.mapControl.SetAction(null);
  66.     }
  67.     
  68.     function _GetJSON()
  69.     {
  70.         return _ActionToJSON(this.type,[]);
  71.     }
  72.     this.OnClick=_OnClick;
  73.     this.OnContextMenu=_OnContextMenu;
  74.     this.GetJSON=_GetJSON;
  75. }
  76. //用户自定义兴趣线标注
  77. //title: 标注名
  78. //note: 备注
  79. //showPic: 是否显示标注内容
  80. //hotpic: logo图片名(包含后缀)
  81. SuperMap.IS.DrawMarkLineAction=function(title, note, showLabel, hotpic)
  82. {
  83.     this.type="SuperMap.IS.DrawMarkLineAction";
  84.     var actionStarted=false;    
  85.     var keyPoints=new Array();
  86.     var xs=new Array();
  87.     var ys=new Array();
  88.     var _showLabel=false;
  89.     var _hotpic=null;
  90.     
  91.     this.Init=function(mapControl)
  92.     {
  93.         this.mapControl=mapControl;
  94.         if(ygPos.browser=="ie")
  95.         {
  96.             mapControl.container.style.cursor="images/cursors/PointQuery.cur";
  97.         }
  98.         else
  99.         {
  100.             mapControl.container.style.cursor="crosshair";
  101.         }
  102.         
  103.         if(showLabel != null)
  104.         {
  105.             _showLabel = showLabel;
  106.         }
  107.         
  108.         if(hotpic == null)
  109.         {
  110.             _hotpic = "images/hotball.gif";
  111.         }
  112.         else
  113.         {
  114.             _hotpic = "images/" + hotpic;
  115.         }
  116.     }
  117.     
  118.     this.Destroy=function()
  119.     {
  120.         this.mapControl=null;
  121.         xs=null;
  122.         ys=null;
  123.     }
  124.     
  125.     function _OnClick(e)
  126.     {        
  127.         if(!actionStarted)
  128.         {
  129.             keyPoints.push(e.mapCoord);
  130.             xs.push(e.mapCoord.x);ys.push(e.mapCoord.y);
  131.             actionStarted=true;         
  132.         }       
  133.         
  134.         keyPoints.push(e.mapCoord);
  135.         xs.push(e.mapCoord.x);ys.push(e.mapCoord.y);
  136.     }
  137.     
  138.     this.OnMouseMove=function(e){
  139.         if(!actionStarted){return false;}
  140.         keyPoints.pop();
  141.         xs.pop();ys.pop();
  142.         keyPoints.push(e.mapCoord);
  143.         xs.push(e.mapCoord.x);ys.push(e.mapCoord.y);
  144.         this.mapControl.CustomLayer.InsertLine(title,xs,ys,2,"blue");
  145.     }
  146.         
  147.     function _OnContextMenu(e)
  148.     {
  149.         if(_showLabel == true)
  150.         {
  151.             var i = Math.round(keyPoints.length / 2) - 1;    
  152.             this.mapControl.CustomLayer.InsertMark("markPoint", xs[i], ys[i], nullnull"<div><img src='" + _hotpic + "' style='cursor:pointer' title='" + note + "' /><span>" + title + "</span></div>");
  153.         }
  154.         
  155.         this.mapControl.SetAction(null);
  156.     }
  157.     
  158.     function _GetJSON()
  159.     {
  160.         return _ActionToJSON(this.type,[]);
  161.     }
  162.     this.OnClick=_OnClick;
  163.     this.OnContextMenu=_OnContextMenu;
  164.     this.GetJSON=_GetJSON;
  165. }
  166. //用户自定义兴趣面标注
  167. //title: 标注名
  168. //note: 备注
  169. //showPic: 是否显示标注内容
  170. //hotpic: logo图片名(包含后缀)
  171. SuperMap.IS.DrawMarkPolygonAction=function(title, note, showLabel, hotpic)
  172. {
  173.     this.type="SuperMap.IS.DrawMarkPolygonAction";
  174.     var actionStarted=false;
  175.     var keyPoints=new Array();
  176.     var xs=new Array();
  177.     var ys=new Array();
  178.     var xcenter=0;
  179.     var ycenter=0;
  180.     var _showLabel=false;
  181.     var _hotpic=null;
  182.     
  183.     this.Init=function(mapControl)
  184.     {
  185.         this.mapControl=mapControl;
  186.         if(ygPos.browser=="ie")
  187.         {
  188.             mapControl.container.style.cursor="images/cursors/PointQuery.cur";
  189.         }
  190.         else
  191.         {
  192.             mapControl.container.style.cursor="crosshair";
  193.         }
  194.         
  195.         if(showLabel != null)
  196.         {
  197.             _showLabel = showLabel;
  198.         }
  199.         
  200.         if(hotpic == null)
  201.         {
  202.             _hotpic = "images/hotball.gif";
  203.         }
  204.         else
  205.         {
  206.             _hotpic = "images/" + hotpic;
  207.         }
  208.     }
  209.     
  210.     this.Destroy=function()
  211.     {
  212.         this.mapControl=null;
  213.         xs=null;
  214.         ys=null;
  215.     }
  216.     
  217.     function _OnClick(e)
  218.     {        
  219.         if(!actionStarted)
  220.         {
  221.             keyPoints.push(e.mapCoord);
  222.             xs.push(e.mapCoord.x);ys.push(e.mapCoord.y);
  223.             actionStarted=true;         
  224.         }       
  225.         
  226.         keyPoints.push(e.mapCoord);
  227.         xs.push(e.mapCoord.x);ys.push(e.mapCoord.y);
  228.     }
  229.     
  230.     this.OnMouseMove=function(e){
  231.         if(!actionStarted){return false;}
  232.         keyPoints.pop();
  233.         xs.pop();ys.pop();
  234.         keyPoints.push(e.mapCoord);
  235.         xs.push(e.mapCoord.x);ys.push(e.mapCoord.y);
  236.         this.mapControl.CustomLayer.InsertPolygon(title, xs, ys, 2, "blue""white", 0.6,1);
  237.     }
  238.         
  239.     function _OnContextMenu(e)
  240.     {
  241.         if(_showLabel == true)
  242.         {
  243.             // 多边形几何中心
  244.             var n = keyPoints.length;
  245.             for(var i=0; i<n; i++)
  246.             {
  247.                 xcenter += xs[i] / n;
  248.                 ycenter += ys[i] / n;
  249.             }
  250.             
  251.             this.mapControl.CustomLayer.InsertMark("markPoint", xcenter, ycenter, nullnull"<div><img src='" + _hotpic + "' style='border:0px; cursor:pointer' title='" + note + "' /><span>" + title + "</span></div>");
  252.         }
  253.         
  254.         this.mapControl.SetAction(null);
  255.     }
  256.     
  257.     function _GetJSON()
  258.     {
  259.         return _ActionToJSON(this.type,[]);
  260.     }
  261.     this.OnClick=_OnClick;
  262.     this.OnContextMenu=_OnContextMenu;
  263.     this.GetJSON=_GetJSON;
  264. }

调用方法:

  1. function SetCustomMark()
  2. {
  3.     var caption = $("Caption").value;
  4.     var remark = $("Remark").value;
  5.     var type = $("mark_type").value;
  6.    
  7.     switch(type)
  8.     {
  9.         case "text":
  10.             SetMarkTextAction(caption,remark);
  11.             break;
  12.         case "point":
  13.             SetMarkPointAction(caption,remark);
  14.             break;
  15.         case "line":
  16.             SetMarkLineAction(caption,remark);
  17.             break;
  18.         case "polygon":
  19.             SetMarkPolygonAction(caption,remark);
  20.             break;
  21.         default:
  22.             break;
  23.     }
  24. }
  25. function SetMarkTextAction(caption,remark)
  26. {
  27.     markPointAction = new SuperMap.IS.DrawMarkPointAction(caption,remark,false);
  28.     MapControl1.SetAction(markPointAction);
  29. }
  30. function SetMarkPointAction(caption,remark)
  31. {
  32.     markPointAction = new SuperMap.IS.DrawMarkPointAction(caption,remark,true);
  33.     MapControl1.SetAction(markPointAction);
  34. }
  35. function SetMarkLineAction(caption,remark)
  36. {
  37.     markLineAction = new SuperMap.IS.DrawMarkLineAction(caption,remark);
  38.     MapControl1.SetAction(markLineAction);
  39. }
  40. function SetMarkPolygonAction(caption,remark)
  41. {
  42.     markPolygonAction = new SuperMap.IS.DrawMarkPolygonAction(caption,remark);
  43.     MapControl1.SetAction(markPolygonAction);
  44. }

脚本下载地址:http://download.csdn.net/source/591063

还有部分待完善,使自主标注内容能在线保存:)

欢迎提供建议!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值