a33b8f820e658f3e6f27b1d88ff9b2f7a59221b6.svn-base 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. const options = {
  2. url: "/arcgisApi/4.7/init.js"
  3. };
  4. import _default,* as esriLoader from "esri-loader";
  5. import {getPersonTrack} from '../../../api/zhxxAPI.js'
  6. import {dateFormat} from '../../../utils/gw_date'
  7. var trackArr = [];
  8. var sttm,ettm;
  9. var contIntervalTime;
  10. export function getPerTrack(_self,item,obj){
  11. _self.mapObject.getLayers().forEach((val)=>{
  12. if(val){
  13. if(val.getProperties().id == 'ls_guijiPoint' || val.getProperties().id == 'ls_guijiPoint1'){
  14. _self.mapObject.removeLayer(val);
  15. }
  16. }
  17. });
  18. var ol = _self.$ol;
  19. var symbol_start = new ol.style.Style({
  20. image: new ol.style.Icon(({
  21. anchor: [0.5, 0.5],
  22. scale:1,
  23. src: '/src/views/zongHeXinXiOl/assets/xhstart.png'
  24. }))
  25. });
  26. var symbol_end = new ol.style.Style({
  27. image: new ol.style.Icon(({
  28. anchor: [0.5, 0.5],
  29. scale:1,
  30. src: '/src/views/zongHeXinXiOl/assets/xhend.png'
  31. }))
  32. });
  33. var symbolLine = new ol.style.Style({
  34. stroke:new ol.style.Stroke({
  35. color: '#ff0000',
  36. width: 3,
  37. lineCap:'round'
  38. })
  39. })
  40. // var symbolLine = {type: "simple-line",color: [ 255,0, 0, 1 ],width:"5px",style: "solid"};
  41. // var symbol_start = {
  42. // type: "picture-marker", // autocasts as new PictureMarkerSymbol()
  43. // url: "/src/views/zongHeXinXiOl/assets/xhstart.png",
  44. // width: "40px",
  45. // height: "40px"
  46. // };
  47. // var symbol_end = {
  48. // type: "picture-marker", // autocasts as new PictureMarkerSymbol()
  49. // url: "/src/views/zongHeXinXiOl/assets/xhend.png",
  50. // width: "40px",
  51. // height: "40px"
  52. // };
  53. var featuresPt = [];
  54. var gra,pt,symbol;
  55. trackArr = [];
  56. if(obj != 'track'){
  57. if(!sttm && !ettm){
  58. sttm = dateFormat(new Date());
  59. ettm = dateFormat(new Date(new Date().getTime() - 24*60*60*1000));
  60. }
  61. getPersonTrack(item.guid,sttm,ettm).then((res)=>{
  62. if(res.data){
  63. for(var i=res.data.length-1;i>=0;i--){
  64. if(res.data[i].latitude && res.data[i].longitude){
  65. trackArr.push([res.data[i].longitude,res.data[i].latitude]);
  66. }
  67. }
  68. }
  69. })
  70. }else{
  71. trackArr = item.pointList;
  72. if(trackArr.length==0){
  73. return;
  74. }
  75. // var ptStart = new Point(trackArr[0][0],trackArr[0][1]);
  76. var ptStart = new ol.geom.Point(ol.proj.transform([trackArr[0][0],trackArr[0][1]], "EPSG:4326", "EPSG:3857"))
  77. // var ptEnd = new Point(trackArr[trackArr.length-1][0],trackArr[trackArr.length-1][1]);
  78. var ptEnd = new ol.geom.Point(ol.proj.transform([trackArr[trackArr.length-1][0],trackArr[trackArr.length-1][1]], "EPSG:4326", "EPSG:3857"))
  79. var iconFeature = new ol.Feature({
  80. geometry: ptStart,
  81. name: '轨迹起点'
  82. });
  83. var iconFeature1 = new ol.Feature({
  84. geometry: ptEnd,
  85. name: '轨迹终点'
  86. });
  87. iconFeature.setStyle(symbol_start);
  88. iconFeature1.setStyle(symbol_end);
  89. featuresPt.push(iconFeature);
  90. featuresPt.push(iconFeature1);
  91. var vectorSource = new ol.source.Vector({
  92. features: featuresPt
  93. });
  94. var vectorLayer;
  95. _self.mapObject.getLayers().forEach((val)=>{
  96. if(val){
  97. if(val.getProperties().id == 'ls_guijiPoint'){
  98. vectorLayer = val;
  99. vectorLayer.getSource().getFeatures().push(vectorSource);
  100. }
  101. }
  102. });
  103. if(!vectorLayer){
  104. vectorLayer = new ol.layer.Vector({
  105. source: vectorSource,
  106. id:'ls_guijiPoint'
  107. });
  108. _self.mapObject.addLayer(vectorLayer);
  109. }
  110. }
  111. if(trackArr.length<0){
  112. _self.showInfo('track','暂无巡河轨迹信息!');
  113. }else{
  114. var symbol1 = new ol.style.Style({
  115. image: new ol.style.Circle({
  116. radius: 6,
  117. fill: new ol.style.Fill({
  118. color: 'red'
  119. })
  120. })
  121. });
  122. // var symbol = {
  123. // type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
  124. // style: "circle",
  125. // color: "red",
  126. // size: "5px", // pixels
  127. // outline: { // autocasts as new SimpleLineSymbol()
  128. // color: [ 255, 255, 0 ],
  129. // width: 0 // points
  130. // }
  131. // };
  132. var features1 = [];
  133. var vectorSource1;
  134. trackArr.forEach((item)=>{
  135. var pt = new ol.geom.Point(ol.proj.transform([item[0],item[1]], "EPSG:4326", "EPSG:3857"))
  136. // var pt = new Point(item[0],item[1]);
  137. // var gra = new Graphic({
  138. // geometry:pt,
  139. // symbol:symbol
  140. // });
  141. var iconFeature1 = new ol.Feature({
  142. geometry: pt,
  143. name: '轨迹点'
  144. });
  145. iconFeature1.setStyle(symbol1);
  146. features1.push(iconFeature1);
  147. vectorSource1 = new ol.source.Vector({
  148. features: features1
  149. });
  150. // trackGraphicLayer1.add(gra);
  151. })
  152. var vectorLayer1;
  153. _self.mapObject.getLayers().forEach((val)=>{
  154. if(val){
  155. if(val.getProperties().id == 'ls_guijiPoint1'){
  156. vectorLayer1 = val;
  157. vectorLayer1.getSource().getFeatures().push(vectorSource1);
  158. }
  159. }
  160. });
  161. if(!vectorLayer1){
  162. vectorLayer1 = new ol.layer.Vector({
  163. source: vectorSource1,
  164. id:'ls_guijiPoint1'
  165. });
  166. _self.mapObject.addLayer(vectorLayer1);
  167. }
  168. // var line = new Polyline({
  169. // paths: [trackArr],
  170. // spatialReference: { wkid: 4326 }
  171. // });
  172. // contIntervalTime = Math.round(5000/trackArr.length);
  173. // var hehuTempGra = new Graphic({
  174. // geometry:line,
  175. // symbol:symbolLine,
  176. // attributes:null
  177. // });
  178. // _self.viewObject.extent = hehuTempGra.geometry.extent;
  179. // var lod = Number(_self.viewObject.zoom);
  180. // var lod1 = Number(lod - 2);
  181. // _self.viewObject.goTo({
  182. // target:hehuTempGra,
  183. // zoom:lod1,
  184. // }).then(function(){
  185. // let realPathArray = trackArr;
  186. // console.log('realPathArray ');
  187. // realAnimateFun(realPathArray,0,_self);
  188. // });
  189. }
  190. // }).catch(err => {
  191. // console.error(err);
  192. // });
  193. }
  194. function realAnimateFun(pathsArray,startIndex,_self){
  195. console.log('realAnimateFun'+startIndex);
  196. let currentIndex = startIndex;
  197. let currentPaths = [];
  198. if(currentIndex+1>=pathsArray.length){
  199. return ;
  200. }
  201. currentPaths.push(pathsArray[currentIndex]);
  202. currentPaths.push(pathsArray[currentIndex+1]);
  203. esriLoader.dojoRequire(["esri/Graphic","esri/geometry/Point","esri/geometry/SpatialReference",
  204. "esri/layers/GraphicsLayer","esri/geometry/Polygon","esri/geometry/Polyline"
  205. ],(Graphic,Point,SpatialReference,GraphicsLayer,Polygon,Polyline)=>{
  206. var trackGraphicLayer = _self.mapObject.findLayerById("trackGraphicLayer");
  207. // trackGraphicLayer.removeAll();
  208. var symbolLine = {type: "simple-line",color: [ 255,0, 0, 1 ],width:"3px",style: "solid"};
  209. let line = new Polyline({
  210. paths: [currentPaths],
  211. spatialReference: { wkid: 4326 }
  212. });
  213. let hehuTempGra = new Graphic({
  214. geometry:line,
  215. symbol:symbolLine,
  216. attributes:null
  217. });
  218. trackGraphicLayer.add(hehuTempGra);
  219. });
  220. setTimeout(() => {
  221. realAnimateFun(pathsArray,currentIndex+1,_self);
  222. }, contIntervalTime);
  223. }