titleLayer.wmts.realtime.zt.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. window.getRouteLineByUrl = function (lanlats) {
  2. var latlngsArr = lanlats
  3. var len = lanlats.length;
  4. var startPoint = lanlats[0];
  5. var origin = startPoint[1] + "," + startPoint[0]
  6. var endPoint = lanlats[(len - 1)];
  7. var destination = endPoint[1] + "," + endPoint[0]
  8. var waypoints = "";
  9. var passPoint = lanlats[1];
  10. //为避免途径点过多,导致get请求失败,因此默认设置最多只取300个途径点
  11. // let ys = Math.floor(len / 300)
  12. for (var i = 1; i < len - 1; i++) {
  13. var passPoint = lanlats[i];
  14. waypoints += passPoint[1] + "," + passPoint[0] + ";"
  15. }
  16. waypoints = waypoints.substring(0, waypoints.length - 1)
  17. var url = window.SITE_CONFIG['routeUrl'] + "?origin=" + origin + "&destination=" + destination + "&waypoints=" + waypoints + "&format=json"
  18. window.doXHRBySync(url, function (data) {
  19. if (data.status === "ok") {
  20. for (var i = 0; i < data.results.length; i++) {
  21. var steps = data.results[i].steps
  22. var num = 0
  23. latlngsArr = []
  24. for (var j = 0; j < steps.length; j++) {
  25. var polyline = steps[j].path
  26. var startIndex = polyline.indexOf('(') + 1
  27. var endIndex = polyline.indexOf(')')
  28. var polylineNew = polyline.substring(startIndex, endIndex)
  29. var polylineArr = polylineNew.split(',')
  30. for (var z = 0; z < polylineArr.length; z++) {
  31. var polylineStr = []
  32. var polylineArrNew = polylineArr[z].replace(/^\s+|\s+$/g, '')
  33. polylineStr[0] = parseFloat(polylineArrNew.split(' ')[1])
  34. polylineStr[1] = parseFloat(polylineArrNew.split(' ')[0])
  35. latlngsArr[num] = polylineStr
  36. num++
  37. }
  38. }
  39. }
  40. }
  41. });
  42. // console.log(latlngsArr);
  43. return latlngsArr;
  44. }
  45. window.getCarMarkerPopup = function (attr) {
  46. if (attr) {
  47. let name = attr.name ? attr.name : "-"
  48. let createTime = attr.attributes.createTime ? attr.attributes.createTime : "-"
  49. let speed = attr.attributes.speed ? attr.attributes.speed : "-"
  50. let head = attr.attributes.head ? attr.attributes.head : "-"
  51. let lon = attr.lon ? attr.lon : "-"
  52. let lat = attr.lat ? attr.lat : "-"
  53. let mileage = attr.attributes.mileage ? attr.attributes.mileage : "-"
  54. let height = attr.attributes.height ? attr.attributes.height : "-"
  55. var html = "<div class='ship-ss-pop'>"
  56. + "<span>车牌号:" + name + "</span></br>"
  57. + "<span>定位时间:" + createTime + "</span></br>"
  58. + "<span>车速:" + speed + "</span></br>"
  59. + "<span>方向:" + head + "</span></br>"
  60. + "<span>经度:" + lon + "</span></br>"
  61. + "<span>纬度:" + lat + "</span></br>"
  62. + "<span>里程:" + mileage + "</span></br>"
  63. + "<span>海拔:" + height + "</span></br>"
  64. + "</div>"
  65. return html;
  66. }
  67. }
  68. window.getLssMarkerPopup = function (attr) {
  69. let targetID = attr.attributes._targetID ? attr.attributes._targetID : "-"
  70. let name = attr.name ? attr.name : "-"
  71. let scanTime = attr.attributes.scanTime ? attr.attributes.scanTime : "-"
  72. let rate = attr.attributes.rate ? attr.attributes.rate : "-"
  73. let heading = attr.attributes.heading ? attr.attributes.heading : "-"
  74. let altitude = attr.attributes.altitude ? attr.attributes.altitude : "-"
  75. let lon = attr.lon ? attr.lon : "-"
  76. let lat = attr.lat ? attr.lat : "-"
  77. let dz = attr.dz ? attr.dz : "-"
  78. var html = "<div class='ship-ss-pop'>"
  79. + "<span>设备编号:" + targetID + "</span></br>"
  80. + "<span>设备名称:" + name + "</span></br>"
  81. + "<span>扫描时间:" + scanTime + "</span></br>"
  82. + "<span>速率:" + rate + "</span></br>"
  83. + "<span>航向:" + heading + "</span></br>"
  84. + "<span>高度:" + altitude + "</span></br>"
  85. + "<span>经度:" + lon + "</span></br>"
  86. + "<span>纬度:" + lat + "</span></br>"
  87. + "<span>所属市县:" + dz + "</span></br>"
  88. + "</div>"
  89. return html;
  90. }
  91. window.getWgyInfoById = function (id){
  92. var wgyInfo = {}
  93. var url = "http://10.110.35.55:9900/api-idaas/idaas/app/account/detail/"+id
  94. window.doXHRByWgySync(url, function (data){
  95. if (data.code === 0) {
  96. wgyInfo.displayName = data.userInfo.displayName
  97. wgyInfo.email = data.userInfo.email
  98. wgyInfo.ouDirectory = data.userInfo.userOrganization[0].organizationName
  99. wgyInfo.ename = data.userInfo.username
  100. wgyInfo.phoneNumber = data.userInfo.phoneNumber
  101. }
  102. });
  103. return wgyInfo;
  104. }
  105. window.getWgyMarkerPopup = function (attr) {
  106. let id = attr.attributes._targetID ? attr.attributes._targetID : "-"
  107. let name = attr.name ? attr.name : "-"
  108. // let wgyInfo = window.getWgyInfoById(id)
  109. // let name = wgyInfo.displayName ? wgyInfo.displayName : "-"
  110. let time = '-'
  111. if( typeof attr.time === 'number' ){
  112. if((attr.time+"").length === 10 ){
  113. time = formatDate(attr.time * 1000)
  114. }else if((attr.time+"").length === 13){
  115. time = formatDate(attr.time)
  116. }
  117. }else if(typeof attr.time === 'string'){
  118. if(attr.time.length === 10 ){
  119. time = formatDate(parseInt(attr.time) * 1000)
  120. }else if(attr.time.length === 13){
  121. time = formatDate(parseInt(attr.time))
  122. }
  123. }
  124. var html = "<div class='ship-ss-pop'>"
  125. + "<span>编码:" + id + "</span></br>"
  126. + "<span>名称:" + name + "</span></br>"
  127. + "<span>经度:" + attr.lon + "</span></br>"
  128. + "<span>纬度:" + attr.lat + "</span></br>"
  129. + "<span>更新时间:" + time + "</span></br>"
  130. + "<span>来源:" + attr.layerCnName + "</span></br>"
  131. + "</div>"
  132. return html;
  133. }
  134. window.getYjMarkerPopupByCar = function (attr) {
  135. let title = attr.attributes.title ? attr.attributes.title : "-"
  136. let lon = attr.lon ? attr.lon : "-"
  137. let lat = attr.lat ? attr.lat : "-"
  138. let happenTime = attr.attributes.happenTime ? window.CstTimeToNomalTime(new Date(parseInt(attr.attributes.happenTime))) : "-"
  139. let happenPlace = attr.attributes.happenPlace ? attr.attributes.happenPlace : "-"
  140. let reliableLevelName = attr.attributes.reliableLevelName ? attr.attributes.reliableLevelName : "-"
  141. let sensitiveLevelName = attr.attributes.sensitiveLevelName ? attr.attributes.sensitiveLevelName : "-"
  142. let details = attr.attributes.details ? attr.attributes.details : "-"
  143. var html = "<div class='ship-ss-pop'>"
  144. + "<span>预警名称:" + title + "</span></br>"
  145. + "<span>经度:" + lon + "</span></br>"
  146. + "<span>纬度:" + lat + "</span></br>"
  147. + "<span>发生时间:" + happenTime + "</span></br>"
  148. + "<span>发生地点:" + happenPlace + "</span></br>"
  149. + "<span>可信度:" + reliableLevelName + "</span></br>"
  150. + "<span>关注度:" + sensitiveLevelName + "</span></br>"
  151. + "<span>详情:" + details + "</span></br>"
  152. + "</div>"
  153. return html;
  154. }
  155. L.TileLayer.WMTS.REALTIME.ZT = L.TileLayer.WMTS.REALTIME.extend({
  156. });
  157. L.tileLayer.wmts.realtime.zt = function (url, jsonUrl, options, markerClick) {
  158. return new L.TileLayer.WMTS.REALTIME.ZT(url, jsonUrl, options, markerClick);
  159. };
  160. L.REALTIMEGJ.ZT = L.REALTIMEGJ.extend({
  161. options: {
  162. routeLine: ''
  163. },
  164. pauseGuiji: function (targetList) {
  165. targetList.forEach((e) => {
  166. if (this.gjLayer.movingMarker[e]) {
  167. this.gjLayer.movingMarker[e].pause()
  168. }
  169. })
  170. },
  171. jixuHuifang: function (targetList) {
  172. targetList.forEach((e) => {
  173. if (this.gjLayer.movingMarker[e]) {
  174. this.gjLayer.movingMarker[e].start()
  175. }
  176. })
  177. },
  178. startPlayGJ: function (_targetID, gjData) {
  179. // console.log("gjData", gjData)
  180. this.clearGjLayerLayerGroup(_targetID);
  181. var lanlats = [], courses = [], speeds = [], collectimes = [], newLanLats = [], lanlatStr = [];
  182. if (!this.gjLayer.gjCircleMarker[_targetID]) {
  183. this.gjLayer.gjCircleMarker[_targetID] = [];
  184. }
  185. if (!this.gjLayer.seMarker[_targetID]) {
  186. this.gjLayer.seMarker[_targetID] = {};
  187. }
  188. let iconAnchor, noRealtimeGjList = {};
  189. this.gjLayer.gjPoyline[_targetID] = {};
  190. for (var i in gjData) {
  191. gjData[i].isTjd = "Y"
  192. collectimes.push(gjData[i].attributes.collecTime);
  193. courses.push(gjData[i].attributes.course);
  194. speeds.push(gjData[i].attributes.speed);
  195. lanlatStr.push(gjData[i].lat + "," + gjData[i].lon)
  196. // lanlats.push([gjData[i].lat, gjData[i].lon]);
  197. //处理过虚拟位置不打点
  198. if (gjData[i].attributes.no_realtime_gj
  199. && gjData[i].attributes.no_realtime_gj === 'no_realtime_gj') {
  200. noRealtimeGjList[i] = i;
  201. if (i !== 0 && !(gjData[i].lat + "_" + gjData[i].lon in (this.gjLayer.gjPoyline[_targetID]))) {
  202. this.gjLayer.gjPoyline[_targetID][gjData[i].lat + "_" + gjData[i].lon]
  203. = L.polyline([[gjData[i - 1].lat, gjData[i - 1].lon]
  204. , [gjData[i].lat, gjData[i].lon]], { color: 'red', dashArray: '10' }).addTo(this.gjLayer.layerGroup);
  205. }
  206. continue;
  207. }
  208. // if (i !== "0" && !(gjData[i].lat + "_" + gjData[i].lon in (this.gjLayer.gjPoyline[_targetID]))) {
  209. // this.gjLayer.gjPoyline[_targetID][gjData[i].lat + "_" + gjData[i].lon]
  210. // = L.polyline([[gjData[i - 1].lat, gjData[i - 1].lon]
  211. // , [gjData[i].lat, gjData[i].lon]], { color: 'red' }).addTo(this.gjLayer.layerGroup);
  212. // }
  213. var title = formatDate(gjData[i].attributes.collecTime * 1000);
  214. let m = L.circleMarker([gjData[i].lat, gjData[i].lon], { zIndexOffset: 10, radius: 2, color: '#f00' }).addTo(this.gjLayer.layerGroup);
  215. var circlePoint = L.circleMarker([gjData[i].lat, gjData[i].lon], { zIndexOffset: 10, title: title, radius: 3, color: 'blue' }).addTo(this.gjLayer.layerGroup);
  216. this.gjLayer.gjCircleMarker[_targetID].push(m);
  217. this.gjLayer.gjCircleMarker[_targetID].push(circlePoint);
  218. m.attributes = gjData[i];
  219. m.bindPopup(this.options.markerPopup(m.attributes), { autoPan: false, closeButton: false, offset: L.point(130, 315) });
  220. circlePoint.bindPopup(this.options.markerPopup(m.attributes), { autoPan: false, closeButton: false, offset: L.point(130, 255) });
  221. //autoPanPaddingBottomRight ,,{autoPan:false,closeButton:false,offset:L.point(120,185)}
  222. // var url = _this._jsonUrl+"?format=json&layer="+_this.options.gjLayer+"&customsQuery="+encodeURIComponent("{\"must\":[{\"term\":{\"attributes._targetID\":\""+attr.attributes._targetID+"\"}},{\"range\":{\"attributes.collectime\":{\"lte\":"+endTime+",\"gt\":"+startTime+"}}}]}")+"&sort=collectime:asc";
  223. let _this = this;
  224. m.on('mouseover', function (ev) {
  225. if (_this.pupopOpenHander) {
  226. clearTimeout(_this.pupopOpenHander);
  227. }
  228. _this.pupopOpenHander = setTimeout(function () {
  229. ev.target.openPopup();
  230. }, 500);
  231. if (_this.markerDrawJ) {
  232. _this.gjLayer.layerGroup.removeLayer(_this.markerDrawJ)
  233. }
  234. _this.markerDrawJ = L.marker(ev.target.getLatLng(), { zIndexOffset: 12, icon: new L.AngleIcon({ iconSize: new L.Point(32, 32) }) }).addTo(_this.gjLayer.layerGroup);
  235. _this.markerDrawJ.options.icon.drawJ();
  236. });
  237. circlePoint.on('mouseover', function (ev) {
  238. if (_this.pupopOpenHander) {
  239. clearTimeout(_this.pupopOpenHander);
  240. }
  241. _this.pupopOpenHander = setTimeout(function () {
  242. ev.target.openPopup();
  243. }, 500);
  244. if (_this.markerDrawJ) {
  245. _this.gjLayer.layerGroup.removeLayer(_this.markerDrawJ)
  246. }
  247. _this.markerDrawJ = L.marker(ev.target.getLatLng(), { icon: new L.AngleIcon({ iconSize: new L.Point(32, 32) }) }).addTo(_this.gjLayer.layerGroup);
  248. _this.markerDrawJ.options.icon.drawJ();
  249. });
  250. iconAnchor = [-70, 10];
  251. let pos = 'right';
  252. if (i % 2 == 0) {
  253. iconAnchor = [120, 10]
  254. pos = 'left';
  255. }
  256. // this.gjLayer.gjTimeMarker[_targetID].push(L.marker([gjData[i].lat, gjData[i].lon],{zIndexOffset:-10,icon:L.divIcon({iconSize: [120, 18] ,iconAnchor:iconAnchor,html:'<span>'+formatDate(gjData[i].attributes.collecTime*1000)+'</span>'})}).addTo(this.gjLayer.layerGroup));
  257. this.gjLayer.gjTimeMarker[_targetID][i] = L.marker([gjData[i].lat, gjData[i].lon], { zIndexOffset: -10, icon: L.iconWithLine({ pos: pos, iconSize: [120, 18], iconAnchor: iconAnchor, html: '<span>' + formatDate(gjData[i].time * 1000) + '</span>' }) });
  258. this.gjLayer.gjTimeMarker[_targetID][i].addTo(_this.gjLayer.layerGroup);
  259. //).addTo(this.gjLayer.layerGroup));
  260. }
  261. // console.log("guiji:", lanlatStr)
  262. let new_lanlats = [...new Set(lanlatStr)];
  263. console.log("new_lanlats", new_lanlats)
  264. new_lanlats.forEach((e) => {
  265. let splitLonlat = e.split(",");
  266. lanlats.push([splitLonlat[0], splitLonlat[1]]);
  267. })
  268. // console.log("lanlats:", lanlats)
  269. if (this.options.routeLine) {
  270. newLanLats = this.options.routeLine(lanlats)
  271. }
  272. for (var j in newLanLats) {
  273. if (j !== "0" && !(newLanLats[j][0] + "_" + newLanLats[j][1] in (this.gjLayer.gjPoyline[_targetID]))) {
  274. this.gjLayer.gjPoyline[_targetID][newLanLats[j][0] + "_" + newLanLats[j][1]]
  275. = L.polyline([[newLanLats[j - 1][0], newLanLats[j - 1][1]]
  276. , [newLanLats[j][0], newLanLats[j][1]]], { color: 'red' }).addTo(this.gjLayer.layerGroup);
  277. }
  278. // let m = L.circleMarker([newLanLats[j][0], newLanLats[j][1]], { zIndexOffset: 10, radius: 2, color: '#f00' }).addTo(this.gjLayer.layerGroup);
  279. // this.gjLayer.gjCircleMarker[_targetID].push(m);
  280. }
  281. var sicon = L.icon({ iconUrl: window.EASYMAP_CONFIG.myUrl + 'map-easy-client/track_start.png', iconSize: [25, 39], iconAnchor: [12, 39] });
  282. var eicon = L.icon({ iconUrl: window.EASYMAP_CONFIG.myUrl + 'map-easy-client/track_end.png', iconSize: [25, 39], iconAnchor: [12, 39] });
  283. var stitle = formatDate(gjData[0].time * 1000);
  284. this.gjLayer.seMarker[_targetID]['s'] = L.marker([gjData[0].lat, gjData[0].lon], { icon: sicon, title: stitle }).addTo(this.gjLayer.layerGroup);
  285. //console.log(data.resultList[data.resultList.length-1].attributes.collectime);
  286. var eTitle = formatDate(gjData[gjData.length - 1].time * 1000);
  287. this.gjLayer.seMarker[_targetID]['e'] = L.marker([gjData[gjData.length - 1].lat, gjData[gjData.length - 1].lon], { icon: eicon, title: eTitle }).addTo(this.gjLayer.layerGroup);
  288. var marker1 = L.Marker.movingMarker.zt(newLanLats, this.options.playSpeed, {
  289. autostart: true
  290. , course: 0
  291. , speed: gjData[gjData.length - 1].attributes.speed
  292. , courses: courses
  293. , speeds: speeds
  294. , collectimes: collectimes
  295. , iconUrl: gjData[0].markerPath+"?sessionToken="+window.sessionToken
  296. , zIndexOffset: 100
  297. , title: gjData[gjData.length - 1].name
  298. , showTitle: true
  299. , labelPosition: 'topleft'
  300. , noRealtimeGjList: noRealtimeGjList
  301. , gjTimeMarker: this.gjLayer.gjTimeMarker[_targetID]
  302. , layerGroup: this.gjLayer.layerGroup
  303. , markerDrawJ: this.markerDrawJ
  304. , gjData: gjData
  305. , pupopOpenHander: this.pupopOpenHander
  306. , markerPopup: this.options.markerPopup
  307. }).addTo(this.gjLayer.layerGroup);
  308. /* marker1.on('click', function() {
  309. if (marker1.isRunning()) {
  310. marker1.pause();
  311. } else if(marker1.isEnded()){
  312. //_this.resumeGjPlayCtx(gjData[0].attributes._targetID);
  313. //window.map.removeLayer(marker1);
  314. //marker1.off('click');
  315. } else{
  316. marker1.start();
  317. }
  318. });*/
  319. this.gjLayer.movingMarker[_targetID] = marker1;
  320. this.gjLayer.shipOne = marker1
  321. }
  322. });
  323. L.realtimeGj.zt = function (url, layername, targetList, startTime, endTime, options) {
  324. return new L.REALTIMEGJ.ZT(url, layername, targetList, startTime, endTime, options);
  325. };
  326. window.doXHRBySync = function (url, callback) {
  327. var httpXml = window.createXMLHttpRequest();
  328. httpXml.open('get', url, false);
  329. httpXml.send(null);
  330. var data = JSON.parse(httpXml.responseText);
  331. if (callback) {
  332. callback(data);
  333. }
  334. }
  335. window.doXHRByWgySync = function (url, callback) {
  336. var httpXml = window.createXMLHttpRequest();
  337. httpXml.open('get', url, false);
  338. httpXml.setRequestHeader("sessionToken",window.sessionToken)
  339. httpXml.send(null);
  340. var data = JSON.parse(httpXml.responseText);
  341. if (callback) {
  342. callback(data);
  343. }
  344. }