supermap学习系列(八)-给要素图层SuperMap.Layer.Vector注册事件

2016-7-21 14:57:12 0人评论 300次浏览 分类:技术文章

参考资源超图地理信息云门户-示例:
http://www.supermapcloud.com/online/developAPI.html

上代码:

[html] view plaincopy在CODE上查看代码片派生到我的代码片

  1. <p><!DOCTYPE html>  
  2. <html xmlns="<a target="_blank" href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>">  
  3. <head>  
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5.     <title></title>   
  6.     <script src="libs/SuperMap.Include.js"></script>        
  7.     <script type="text/javascript">      
  8.         var map, layer, popup;  
  9.         var featuresLayer, drawLine, drawPoint, drawPolygon, selectDrawFeature;  
  10.         var drawFeatureStyle = {  
  11.             strokeColor: null,  
  12.             strokeWidth: null,  
  13.             strokeOpacity: null,  
  14.             pointRadius: 6,  
  15.             fillColor: null,  
  16.             fillOpacity: null,  
  17.             cursor: "pointer"  
  18.         };//定义要添加要素的样式    
  19.         var selectStyle = {  
  20.             strokeColor: "#0099FF",  
  21.             strokeWidth: 2,  
  22.             pointerEvents: "visiblePainted",  
  23.             fillColor: "#FF8247",  
  24.             fillOpacity: 0.4,  
  25.             pointRadius: 6,  
  26.             label: "",  
  27.             fontSize: 14,  
  28.             fontWeight: "normal",  
  29.             cursor: "pointer"  
  30.         };// 点击添加的元素之后的样式  
  31.         // 设置访问的GIS服务地址  
  32.         var url = "<a target="_blank" href="http://localhost:8090/iserver/services/map-ChinaTestWorkPlace/rest/maps/ChinaTest">http://localhost:8090/iserver/services/map-ChinaTestWorkPlace/rest/maps/ChinaTest</a>";  
  33.         function GetMap() {  
  34.             // 创建地图对象  
  35.             map = new SuperMap.Map("map");  
  36.             //control = new SuperMap.Control.MousePosition();     //该控件显示鼠标移动时,所在点的地理坐标。  
  37.             //map.addControl(control);  //添加控件    
  38.             featuresLayer = new SuperMap.Layer.Vector("<a target="_blank" href="mailto:test!@#');//">test!@#");//</a>  test!@#  是图层的name属性  
  39.             drawLine = new SuperMap.Control.DrawFeature(featuresLayer, SuperMap.Handler.Path, { multi: true });  
  40.             drawLine.events.on({ "featureadded": drawCompleted });  
  41.             drawPoint = new SuperMap.Control.DrawFeature(featuresLayer, SuperMap.Handler.Point, { multi: true });  
  42.             drawPoint.events.on({ "featureadded": drawCompleted });  
  43.             drawPolygon = new SuperMap.Control.DrawFeature(featuresLayer, SuperMap.Handler.Polygon, { multi: true });  
  44.             drawPolygon.events.on({ "featureadded": drawCompleted });  
  45.             map.addControls([drawLine, drawPoint, drawPolygon]);  
  46.             map.addLayer(featuresLayer);  
  47.             // 创建图层对象  
  48.             layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, { transparent: true, cacheEnabled: true }, { maxResolution: "auto" });  
  49.             layer.events.on({ "layerInitialized": AddLayer });  
  50.         }  
  51.         // 加载图层  
  52.         function AddLayer() {  
  53.             // 向Map添加图层  
  54.             map.addLayer(layer);  
  55.             map.setCenter(new SuperMap.LonLat(116.409749, 39.912344), 1);</p><p>            featuresLayer.events.register("mouseover", "", getTest, true);  
  56.             featuresLayer.events.register("mouseout", "", getTest1, true);  
  57.         }  
  58.         function getTest(e) {  
  59.             var ee = e.object;  
  60.             var eee = e.target;  
  61.             var current_feature = ee.getFeatureById(eee._featureId);  
  62.             current_feature.style = selectStyle;  
  63.             featuresLayer.redraw();</p><p>            var name;  
  64.             if (current_feature.geometry.CLASS_NAME == "SuperMap.Geometry.MultiPoint") {  
  65.                 name = "标注点";  
  66.             } else if (current_feature.geometry.CLASS_NAME == "SuperMap.Geometry.MultiPolygon") {  
  67.                 name = "标注面"  
  68.             } else {  
  69.                 name = "标注线"  
  70.             }  
  71.             popup = new SuperMap.Popup.FramedCloud("chicken",  
  72.                                      current_feature.geometry.getBounds().getCenterLonLat(),  
  73.                                      null,  
  74.                                      name,  
  75.                                      null, true);  
  76.             current_feature.popup = popup;  
  77.             popup.panMapIfOutOfView = true;  
  78.             map.addPopup(popup);            
  79.         }  
  80.         function getTest1(e) {  
  81.             var ee = e.object;  
  82.             var eee = e.target;  
  83.             ee.getFeatureById(eee._featureId).style = drawFeatureStyle;  
  84.             featuresLayer.redraw();  
  85.             map.removePopup(ee.getFeatureById(eee._featureId).popup);  
  86.             ee.getFeatureById(eee._featureId).popup.destroy();  
  87.             ee.getFeatureById(eee._featureId).popup = null;             
  88.         }  
  89.         function drawFeature(type) {  
  90.             var fillColor = document.getElementById("color1").value;  
  91.             var strokeColor = document.getElementById("color2").value;  
  92.             var opacity = document.getElementById("txtOpacity").value;  
  93.             var lineWidth = document.getElementById("txtLineWidth").value;  
  94.             drawFeatureStyle.fillColor = fillColor;  
  95.             drawFeatureStyle.strokeColor = strokeColor;  
  96.             drawFeatureStyle.strokeWidth = lineWidth;  
  97.             drawFeatureStyle.strokeOpacity = opacity;  
  98.             drawFeatureStyle.fillOpacity = opacity;  
  99.             if (type === "point") {  
  100.                 drawPoints();  
  101.             }  
  102.             else if (type === "line") {  
  103.                 drawLines();  
  104.             }  
  105.             else if (type === "polygon") {  
  106.                 drawPolygons();  
  107.             }  
  108.         }  
  109.         function drawPoints() {  
  110.             featuresLayer.style = drawFeatureStyle;  
  111.             drawPoint.activate();  
  112.         }  
  113.         function drawLines() {  
  114.             featuresLayer.style = drawFeatureStyle;  
  115.             drawLine.activate();  
  116.         }  
  117.         function drawPolygons() {  
  118.             featuresLayer.style = drawFeatureStyle;  
  119.             drawPolygon.activate();  
  120.         }         
  121.         function drawCompleted(e) {  
  122.             drawLine.deactivate();  
  123.             drawPoint.deactivate();  
  124.             drawPolygon.deactivate();            
  125.         }  
  126.         function clearAll() {  
  127.             featuresLayer.removeAllFeatures();  
  128.         }         
  129.     </script>  
  130. </head>  
  131. <body onload="GetMap()">    
  132.     <div>  
  133.         <img alt="点" src="resource/controlImages/drawPoint.png" onclick="drawFeature('point')" />  
  134.         <img alt="线" src="resource/controlImages/drawLine.png" onclick="drawFeature('line')" />  
  135.         <img alt="面" src="resource/controlImages/drawRegion.png" onclick="drawFeature('polygon')" />  
  136.         <img alt="清除" src="resource/controlImages/eraser.png" onclick="clearAll()" />  
  137.     </div>    
  138.     <div>  
  139.        <table style="font-size: 12px">  
  140.                 <tr>  
  141.                     <td>  
  142.                         填充颜色:  
  143.                     </td>  
  144.                     <td>  
  145.                         <input type="text" size="10" id="color1" maxlength="7" name="rgb1" value="#FFFFFF"  
  146.                             onclick="showColorPicker(this, document.forms[0].rgb1)"/>  
  147.                     </td>  
  148.                 </tr>  
  149.                 <tr>  
  150.                     <td>  
  151.                         填充透明度:  
  152.                     </td>  
  153.                     <td>  
  154.                         <select id="txtOpacity">  
  155.                             <option value="0.1">0.1</option>  
  156.                             <option value="0.2">0.2</option>  
  157.                             <option value="0.3">0.3</option>  
  158.                             <option value="0.4">0.4</option>  
  159.                             <option value="0.5" selected="selected">0.5</option>  
  160.                             <option value="0.6">0.6</option>  
  161.                             <option value="0.7">0.7</option>  
  162.                             <option value="0.8">0.8</option>  
  163.                             <option value="0.9">0.9</option>  
  164.                             <option value="1.0">1.0</option>  
  165.                         </select>  
  166.                     </td>  
  167.                 </tr>  
  168.                 <tr>  
  169.                     <td>  
  170.                         线宽:  
  171.                     </td>  
  172.                     <td>  
  173.                         <input type="text" id="txtLineWidth" style="width: 50px" value="2" />  
  174.                     </td>  
  175.                 </tr>  
  176.                 <tr>  
  177.                     <td>  
  178.                         边线颜色:  
  179.                     </td>  
  180.                     <td>  
  181.                         <input type="text" size="10" id="color2" maxlength="7" name="rgb2" value="#FF0000"  
  182.                             onclick="showColorPicker(this, document.forms[0].rgb2)"/>  
  183.                     </td>  
  184.                 </tr>  
  185.             </table></p><p>  
  186.     </div>  
  187.     <div id="map" style="height: 640px; width: 720px; border: 1px solid red; margin-left: auto; margin-right: auto;"></div>  
  188. </body>  
  189. </html>  
  190. </p>  

附件下载

相关资讯

  • 吉林省谷歌高清卫星地图下载(百度网盘离线包下载)

    一、概述吉林,地处中国东北中部,东北亚地理中心,因清初建吉林乌拉城而得名,简称“吉”,省会长春,原省会吉林市。吉林省位于日本、俄罗斯、朝鲜、韩国、蒙古与中国东北部组成的东北亚几何中心地带。北接黑龙江省,南邻辽宁省,西接内蒙古自治区,东与俄罗斯联邦接壤,东南…

    2018-6-22 16:04:09
  • 湖南省谷歌高清卫星地图下载(百度网盘离线包下载)

    一、概述湖南为中华人民共和国省级行政区,地处中国中南部、长江中游南部,宋代划定为荆湖南路而开始简称湖南,省内最大河流湘江流贯南北而简称“湘”,也称潇湘,省会驻东北部的长沙市。湖南东临江西,西接重庆、贵州,南毗广东、广西,北与湖北相连。湖南是华夏文明的重要发…

    2018-6-15 15:31:16
  • 湖北省谷歌高清卫星地图下载(百度网盘离线包下载)

    一、概述湖北,简称“鄂”,中华人民共和国省级行政区,省会武汉,因位于长江中游、洞庭湖以北,故名湖北。地处中国中部,东邻安徽,西连重庆,西北与陕西接壤,南接江西、湖南,北与河南毗邻。湖北省位居华中腹地,是中华文明的重要发祥地之一。先秦时期,从哲学到文学,产生…

    2018-6-5 15:16:09
  • 黑龙江省谷歌高清卫星地图下载(百度网盘离线包下载)

    一、概述黑龙江省,简称黑,省会哈尔滨,位于中国最东北部,中国国土的北端与东端均位于省境,因省境北面有黑龙江而得名。黑龙江东部和北部以乌苏里江、黑龙江为界河与俄罗斯为邻,与俄罗斯的水陆边界长约3045公里;西接内蒙古自治区,南连吉林省。介于北纬4326′~5333′,东经…

    2018-5-29 14:18:43

共有访客发表了评论 网友评论

验证码: 看不清楚?