(转)Arcgis for JS实现台风运动路径与影像范围的显示

http://blog.csdn.net/gisshixisheng/article/details/42025435

首先,看看具体的效果:

(转)Arcgis for JS实现台风运动路径与影像范围的显示

初始化状态

(转)Arcgis for JS实现台风运动路径与影像范围的显示

绘制中

(转)Arcgis for JS实现台风运动路径与影像范围的显示

绘制完成

首先,组织数据。我组织的数据是JSON的,数据的具体形式如下:

(转)Arcgis for JS实现台风运动路径与影像范围的显示

其次,实现思路。

1、添加显示路径。

根据起始点,生成polyline的JSON格式。如下:

(转)Arcgis for JS实现台风运动路径与影像范围的显示

并生成路径线。

(转)Arcgis for JS实现台风运动路径与影像范围的显示

2、添加中心点与影响范围

(转)Arcgis for JS实现台风运动路径与影像范围的显示

并添加到地图:

(转)Arcgis for JS实现台风运动路径与影像范围的显示

3、间隔添加

(转)Arcgis for JS实现台风运动路径与影像范围的显示

完整代码如下:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
  6. <title>Simple Map</title>
  7. <link rel="stylesheet" href="http://localhost/arcgis_js_api/library/3.9/3.9/js/esri/css/esri.css">
  8. <style>
  9. html, body, #map {
  10. height: 100%;
  11. margin: 0;
  12. padding: 0;
  13. }
  14. body {
  15. background-color: #FFF;
  16. overflow: hidden;
  17. font-family: "Trebuchet MS";
  18. }
  19. .textss{
  20. position: absolute;
  21. right: 20px;
  22. top: 20px;
  23. border: 1px solid #C9DCD7;
  24. background: #bfbfbf;
  25. padding: 0.1em 0.3em 0.1em;
  26. font-size: 11px;
  27. border-radius: 5px;
  28. /*box-shadow: 0 0 0.75em #777777;*/
  29. }
  30. </style>
  31. <script src="http://localhost/arcgis_js_api/library/3.9/3.9/init.js"></script>
  32. <script>
  33. var drawLine = {
  34. "id":32,
  35. "name":"北京",
  36. "X":116.068276,
  37. "Y":39.892225,
  38. endPt:[{"id":1,"name":"乌鲁木齐","X":87.575829,"Y":43.782212},
  39. {"id":2,"name":"拉萨","X":91.162998,"Y":29.71042},
  40. {"id":3,"name":"西宁","X":101.797303,"Y":36.593642},
  41. {"id":4,"name":"兰州","X":103.584297,"Y":36.119086}/*,
  42. {"id":5,"name":"成都","X":104.035508,"Y":30.714179},
  43. {"id":6,"name":"重庆","X":106.519115,"Y":29.478925},
  44. {"id":7,"name":"贵阳","X":106.668071,"Y":26.457312},
  45. {"id":8,"name":"昆明","X":102.726775,"Y":24.969385},
  46. {"id":9,"name":"银川","X":106.167225,"Y":38.598524},
  47. {"id":10,"name":"西安","X":108.967128,"Y":34.276112},
  48. {"id":11,"name":"南宁","X":108.233931,"Y":22.748296},
  49. {"id":12,"name":"海口","X":110.346181,"Y":19.96992},
  50. {"id":13,"name":"广州","X":113.226683,"Y":23.18307},
  51. {"id":14,"name":"长沙","X":112.947928,"Y":28.169916},
  52. {"id":15,"name":"南昌","X":115.893715,"Y":28.652363},
  53. {"id":16,"name":"福州","X":119.246768,"Y":26.070765},
  54. {"id":17,"name":"台北","X":121.503567,"Y":25.008274},
  55. {"id":18,"name":"杭州","X":120.183046,"Y":30.330584},
  56. {"id":19,"name":"上海","X":121.449707,"Y":31.253361},
  57. {"id":20,"name":"武汉","X":114.216597,"Y":30.579253},
  58. {"id":21,"name":"合肥","X":117.262302,"Y":31.838353},
  59. {"id":22,"name":"南京","X":118.805692,"Y":32.085022},
  60. {"id":23,"name":"郑州","X":113.6511,"Y":34.746308},
  61. {"id":24,"name":"济南","X":117.048331,"Y":36.60841},
  62. {"id":25,"name":"石家","X":114.478215,"Y":38.033276},
  63. {"id":26,"name":"太原","X":112.483066,"Y":37.798404},
  64. {"id":27,"name":"呼和浩特","X":111.842806,"Y":40.895751},
  65. {"id":28,"name":"天津","X":117.351094,"Y":38.925719},
  66. {"id":29,"name":"沈阳","X":123.296299,"Y":41.801604},
  67. {"id":30,"name":"长春","X":125.26142,"Y":43.981984},
  68. {"id":31,"name":"哈尔","X":126.567138,"Y":45.69381},
  69. {"id":33,"name":"香港","X":114.093117,"Y":22.427852},
  70. {"id":34,"name":"澳门","X":113.552482,"Y":22.184495}*/
  71. ]
  72. };
  73. var path = [
  74. {"id":1,  "x":120.49357,  "y":44.883323, "radius":100000},
  75. {"id":2,  "x":117.9872,   "y":42.350326, "radius":80000},
  76. {"id":3,  "x":115.545833, "y":39.79259,  "radius":120000},
  77. {"id":4,  "x":113.508521, "y":38.274465, "radius":40000},
  78. {"id":5,  "x":110.551524, "y":37.151942, "radius":150000},
  79. {"id":6,  "x":108.67448,  "y":36.30474,  "radius":110000},
  80. {"id":7,  "x":106.491804, "y":36.264706, "radius":130000},
  81. {"id":8,  "x":102.495929 ,"y":37.07025,  "radius":140000},
  82. {"id":9,  "x":98.093644,  "y":38.784154, "radius":160000},
  83. {"id":10, "x":92.640902,  "y":39.126654, "radius":170000},
  84. {"id":11, "x":91.005868,  "y":38.125725, "radius":160000},
  85. {"id":12, "x":90.545122,  "y":34.951701, "radius":130000},
  86. {"id":13, "x":91.309324,  "y":33.32037,  "radius":100000},
  87. {"id":14, "x":93.411982,  "y":31.777678, "radius":150000},
  88. {"id":15, "x":98.224212,  "y":30.395442, "radius":170000},
  89. {"id":16, "x":100.630326, "y":29.013206, "radius":180000},
  90. {"id":17, "x":101.171328, "y":27.058946, "radius":190000},
  91. {"id":18, "x":104.454919, "y":25.907586, "radius":190000},
  92. {"id":19, "x":108.053446, "y":26.965449, "radius":20000},
  93. {"id":20, "x":113.019257, "y":28.194103, "radius":130000},
  94. {"id":21, "x":116.535467, "y":26.871059, "radius":110000},
  95. {"id":22, "x":117.470083, "y":23.943192, "radius":100000}];
  96. var map, clickLayer,sr;
  97. var index = 0,t=0;
  98. require([
  99. "esri/map",
  100. "esri/layers/ArcGISTiledMapServiceLayer",
  101. "esri/layers/GraphicsLayer",
  102. "esri/symbols/PictureMarkerSymbol",
  103. "esri/symbols/SimpleLineSymbol", //简单线符号
  104. "dojo/_base/Color",
  105. "dojo/on",
  106. "dojo/dom",
  107. "dojo/domReady!"],
  108. function(Map,
  109. Tiled,
  110. GraphicsLayer,
  111. PictureMarkerSymbol,
  112. SimpleLineSymbol,
  113. Color,
  114. on,
  115. dom
  116. ) {
  117. map = new Map("map",{logo:false});
  118. var tiled = new Tiled("http://localhost:6080/arcgis/rest/services/image/MapServer",{"id":"tiled"});
  119. map.addLayer(tiled, 0);
  120. sr = map.spatialReference;
  121. var mapCenter = new esri.geometry.Point(103.847, 36.0473, sr);
  122. map.centerAndZoom(mapCenter);
  123. clickLayer = new GraphicsLayer({"id":"clickLayer"});
  124. map.addLayer(clickLayer);
  125. var popupLayer = new GraphicsLayer({"id":"popupLayer"});
  126. map.addLayer(popupLayer, 2);
  127. map.on("load",function(){
  128. addReadPopup(drawLine);
  129. });
  130. function addReadPopup(data){
  131. var pms = new PictureMarkerSymbol('images/red.png', 14, 16);
  132. var pt=new esri.geometry.Point(data.X,data.Y,sr);
  133. var graphic = new esri.Graphic(pt, pms, data);
  134. popupLayer.add(graphic);
  135. };
  136. popupLayer.on("click",popupLayerClick);
  137. popupLayer.on("mouse-over",popupLayerOver);
  138. popupLayer.on("mouse-out",popupLayerOut);
  139. function popupLayerClick(evt){
  140. clickLayer.clear();
  141. var graphic = evt.graphic;
  142. console.log(graphic);
  143. map.infoWindow.setTitle(graphic.attributes.name);
  144. map.infoWindow.setContent(graphic.attributes.name);
  145. map.infoWindow.show(graphic.geometry);
  146. var endPts = graphic.attributes.endPt;
  147. var lines = new Array();
  148. for(var i= 0,dl=endPts.length;i<dl;i++){
  149. var endPt = endPts[i];
  150. var pms = new PictureMarkerSymbol('images/house.png', 30, 30);
  151. var pt=new esri.geometry.Point(endPt.X,endPt.Y,sr);
  152. var ptGraphic = new esri.Graphic(pt, pms, endPt);
  153. popupLayer.add(ptGraphic);
  154. lines.push([graphic.attributes.X,graphic.attributes.Y],[endPt.X,endPt.Y]);
  155. }
  156. var lineJson={
  157. "paths":[lines],
  158. "spatialReference":{"wkid":4326}
  159. };
  160. var line = new esri.geometry.Polyline(lineJson);
  161. var sls = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
  162. new Color([0, 255, 0]),
  163. 2
  164. );
  165. var lineGraphic = new esri.Graphic(line, sls , endPt);
  166. clickLayer.add(lineGraphic);
  167. map.setExtent(line.getExtent().expand(2));
  168. }
  169. function popupLayerOver(e){
  170. map.setMapCursor("pointer");
  171. console.log(e.graphic.attributes);
  172. var scrPt = map.toScreen(e.graphic.geometry);
  173. var textDiv = dojo.doc.createElement("div");
  174. dojo.attr(textDiv,{
  175. "id":"text"
  176. });
  177. dojo.style(textDiv, {
  178. "left": scrPt.x+10 + "px",
  179. "top": scrPt.y+10 + "px",
  180. "position": "absolute",
  181. "z-index":99,
  182. "background":"#fcffd1",
  183. "font-size":"10px",
  184. "border":"1px solid #0096ff",
  185. "padding": "0.1em 0.3em 0.1em",
  186. "font-size": "11px",
  187. "border-radius": "3px",
  188. "box-shadow": "0 0 0.75em #777777"
  189. });
  190. textDiv.innerHTML =e.graphic.attributes.name+"市水利自动化研究所";
  191. dojo.byId("map").appendChild(textDiv);
  192. };
  193. function popupLayerOut(e){
  194. map.setMapCursor("default");
  195. dojo.byId("map").removeChild(dojo.byId("text"));
  196. };
  197. on(dom.byId("addPath"), "click", function(){
  198. console.log(path);
  199. addPath();
  200. });
  201. });
  202. function addPath(){
  203. require([
  204. "esri/geometry/Circle"
  205. ],
  206. function(Circle){
  207. console.log(index);
  208. var sms =  new esri.symbol.SimpleMarkerSymbol({
  209. "color": [255,255,0,255],
  210. "size": 8,
  211. "angle": -30,
  212. "xoffset": 0,
  213. "yoffset": 0,
  214. "type": "esriSMS",
  215. "style": "esriSMSCircle",
  216. "outline": {
  217. "color": [255,0,0,255],
  218. "width": 1,
  219. "type": "esriSLS",
  220. "style": "esriSLSSolid"
  221. }
  222. });
  223. var sls = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
  224. new esri.Color([255, 0, 0]),
  225. 2
  226. );
  227. var sfs = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,
  228. new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT,
  229. new esri.Color([0,0,255,0.2]), 2),new esri.Color([0,0,255,0.2])
  230. );
  231. var ptStart = new esri.geometry.Point(path[index].x, path[index].y, sr);
  232. var ptEnd   = new esri.geometry.Point(path[index+1].x, path[index+1].y, sr);
  233. var gPtStart = new esri.Graphic(
  234. ptStart,
  235. sms
  236. );
  237. var gCircleStart = new esri.Graphic(
  238. new Circle(ptStart, {"radius":path[index].radius}),
  239. sfs
  240. );
  241. var gPtEnd = new esri.Graphic(
  242. ptEnd,
  243. sms
  244. );
  245. var gCircleEnd = new esri.Graphic(
  246. new Circle(ptEnd, {"radius":path[index+1].radius}),
  247. sfs
  248. );
  249. var polylineJson = {
  250. "paths":[[[path[index].x,path[index].y], [path[index+1].x,path[index+1].y]]],
  251. "spatialReference":{"wkid":4326}
  252. };
  253. var gLine = new esri.Graphic(
  254. new esri.geometry.Polyline(polylineJson),
  255. sls
  256. );
  257. clickLayer.add(gLine);
  258. if(index<path.length-1){
  259. clickLayer.add(gCircleEnd);
  260. clickLayer.add(gPtEnd);
  261. }
  262. if(index === 0)
  263. {
  264. clickLayer.add(gCircleStart);
  265. clickLayer.add(gPtStart);
  266. }
  267. if(index<path.length-2){
  268. t = setTimeout('addPath()',1000);
  269. index++;
  270. }
  271. else{
  272. clearInterval(t);
  273. }
  274. });
  275. }
  276. </script>
  277. </head>
  278. <body>
  279. <div id="map">
  280. <button id="addPath" type="button" style="position: absolute; top: 10pt; right: 15pt; z-index: 99;">添加路径</button>
  281. </div>
  282. </body>
  283. </html>
上一篇:Arcgis for JS之Cluster聚类分析的实现


下一篇:System.Net.Sockets.Socket SendAsync System.ObjectDisposedException: Cannot access a disposed object.