dangerareamap.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. <!--
  2. * @Title:
  3. * @Description: 危险区地图
  4. * @Author: swp
  5. * @Date: 2022-08-24 10:49:21
  6. * @LastEditors:
  7. * @LastEditTime: 2022-08-24 10:49:21
  8. -->
  9. <template>
  10. <view class="container">
  11. <uni-nav-bar dark :fixed="true" backgroundColor="#3F9EFF" statusBar="false" left-icon="left" left-text="返回"
  12. @clickLeft="toBack">
  13. <view class="nav-title">
  14. <text>{{title}}</text>
  15. </view>
  16. </uni-nav-bar>
  17. <view class="page-body">
  18. <view class="page-section page-section-gap">
  19. <map id="myMap" :style="mapStyles" :latitude="latitude" :longitude="longitude" :markers="markets"
  20. enable-zoom="true" :polygons="polygons" :polyline="polylines" :scale="scale">
  21. </map>
  22. </view>
  23. <view :style="dataStyles">
  24. <uni-collapse @change="searchAreaStatus">
  25. <uni-collapse-item :show-animation="true" :open="true">
  26. <template v-slot:title>
  27. <view class="view-flex-block-center" style="height: 40px;width: 100%;">
  28. <view class="view-flex-inline-center">
  29. <text v-if="showSearch" style="color: coral;font-size: 1rem;">点击全屏地图</text>
  30. <text v-else style="color: coral;font-size: 1rem;">点击还原</text>
  31. </view>
  32. </view>
  33. </template>
  34. </uni-collapse-item>
  35. </uni-collapse>
  36. <view v-if="showSearch">
  37. <view class="view-flex-inline" style="color: gray;margin-left: 10px;">图层: </view>
  38. <view class="view-flex-inline" style="margin-top: 5px;padding-left: 10px;">
  39. <uni-data-checkbox :multiple="true" mode="button" v-model="mapCheck" :localdata="mapItems"
  40. @change="mapChange"></uni-data-checkbox>
  41. </view>
  42. <view class="view-flex-inline" style="color: gray;margin-left: 10px;">关联转移路线: </view>
  43. <view class="view-flex-inline" style="margin-top: 5px;">
  44. <view v-for="leaveline in leaveLines" :key="leaveline.id"
  45. class="view-flex-block-center view-border" style="border-radius: 5px; margin-left: 10px;"
  46. @click="onYjDangerAreaLinkLineClick(leaveline)">
  47. <view class="view-btn-text text-under-line"
  48. style="color: deepskyblue;font-size: 0.7rem;padding-left: 10px;padding-right: 10px;padding-bottom: 2px;">
  49. {{leaveline.leaveLineName}}
  50. </view>
  51. </view>
  52. </view>
  53. <view class="view-flex-inline" style="color: gray;margin-left: 10px;margin-top: 5px;">关联站点: </view>
  54. <view class="view-flex-inline" style="margin-top: 5px;">
  55. <view v-for="rtu in rtuPoints" :key="rtu.id" class="view-flex-block-center view-border"
  56. style="border-radius: 5px; margin-left: 10px;" @click="onYjDangerAreaLinkRtuClick(rtu)">
  57. <view class="view-btn-text text-under-line"
  58. style="color: deepskyblue;font-size: 0.7rem;padding-left: 10px;padding-right: 10px;padding-bottom: 2px;">
  59. {{rtu.stName}}
  60. </view>
  61. </view>
  62. </view>
  63. <view class="view-flex-inline" style="color: gray;margin-left: 10px;margin-top: 5px;">关联家庭户: </view>
  64. <view class="view-flex-inline" style="margin-top: 5px;">
  65. <view v-if="data.familyCount>0" class="view-flex-block-center view-border"
  66. style="border-radius: 5px; margin-left: 10px;" @click="onYjDangerAreaLinkFamilyClick()">
  67. <view class="view-btn-text text-under-line"
  68. style="color: deepskyblue;font-size: 0.7rem;padding-left: 10px;padding-right: 10px;padding-bottom: 2px;">
  69. 共有{{data.familyCount}}户
  70. </view>
  71. </view>
  72. <view v-else>
  73. <view style="color: deepskyblue;font-size: 0.7rem;padding-left: 10px;">暂无关联家庭户</view>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. </template>
  81. <script>
  82. import {
  83. gcoord
  84. } from '@/static/js/gcoord.global.prod.js'
  85. import http from '@/http/api.js';
  86. import {
  87. devUrl,
  88. prodUrl
  89. } from '@/common/setting';
  90. export default {
  91. components: {},
  92. data() {
  93. return {
  94. title: '',
  95. id: 0,
  96. showSearch: true,
  97. areaList: [],
  98. areaIndex: 0,
  99. latitude: 40.848119,
  100. longitude: 111.755426,
  101. zoom: true,
  102. scale: 13,
  103. dangerAreaPoints: [],
  104. markets: [],
  105. polygons: [],
  106. polylines: [],
  107. mapStyles: {
  108. width: '100%',
  109. height: '600px'
  110. },
  111. dataStyles: {
  112. width: '100%',
  113. height: '300px',
  114. },
  115. data: {},
  116. mapCheck: [0],
  117. mapItems: [{
  118. text: '危险区',
  119. value: 0
  120. },
  121. {
  122. text: '转移路线',
  123. value: 1
  124. },
  125. {
  126. text: '站点',
  127. value: 2
  128. },
  129. {
  130. text: '家庭户',
  131. value: 3
  132. }
  133. ],
  134. leaveLines: [],
  135. rtuPoints: [],
  136. familyPoints: [],
  137. mapContext: null,
  138. dangerStatus: '1',
  139. isShowDangerArea: true,
  140. isShowLine: false,
  141. isShowSite: false,
  142. isShowFamily: false
  143. }
  144. },
  145. computed: {},
  146. onShow() {
  147. },
  148. onLoad(options) {
  149. //this.mapContext = uni.createMapContext('myMap', this);
  150. this.mapStyles.height = (uni.getWindowInfo().windowHeight - 50 - 300) + "px";
  151. this.id = options.id;
  152. this.baseURL = process.env.NODE_ENV === 'development' ? devUrl : prodUrl;
  153. this.getDetail();
  154. },
  155. onReady() {
  156. //console.log("onReady" + JSON.stringify(uni.getWindowInfo()))
  157. //this.mapStyles.height = (uni.getWindowInfo().windowHeight - 75 - 20) + "px";
  158. this.mapContext = uni.createMapContext('myMap', this);
  159. },
  160. methods: {
  161. toBack() {
  162. uni.navigateBack({
  163. delta: 1
  164. })
  165. },
  166. searchAreaStatus(e) {
  167. if (e.length > 0) {
  168. this.showSearch = true;
  169. this.mapStyles.height = (uni.getWindowInfo().windowHeight - 50 - 300) + "px";
  170. this.dataStyles.height = "300px";
  171. } else {
  172. this.showSearch = false;
  173. this.mapStyles.height = (uni.getWindowInfo().windowHeight - 50 - 50) + "px";
  174. this.dataStyles.height = "50px";
  175. }
  176. },
  177. getDetail() {
  178. let that = this;
  179. let postData = {};
  180. postData['id'] = this.id;
  181. http.request({
  182. url: '/galaxy-business/map/dangerarea/detail',
  183. method: 'GET',
  184. data: postData
  185. }).then(res => {
  186. if (res.data != null) {
  187. that.data = res.data;
  188. that.title = res.data.dangerAreaName;
  189. that.leaveLines = res.data.leaveLines;
  190. that.rtuPoints = res.data.rtus;
  191. that.familyPoints = res.data.familyPoints;
  192. that.dangerStatus = res.data.dangerStatus;
  193. that.dangerAreaPoints = res.data.points;
  194. let p = {};
  195. let ps = res.data.points.map(item => {
  196. let l = gcoord.transform(
  197. [item.pointLng, item.pointLat],
  198. gcoord.WGS84,
  199. gcoord.GCJ02
  200. );
  201. return {
  202. latitude: l[1],
  203. longitude: l[0],
  204. }
  205. })
  206. p['points'] = ps;
  207. let dashArray = [];
  208. dashArray.push(4);
  209. dashArray.push(10);
  210. p['dashArray'] = dashArray;
  211. if (res.data.dangerStatus == '1') {
  212. p['strokeColor'] = '#FF0000';
  213. p['fillColor'] = '#F72C5B7D';
  214. } else {
  215. p['strokeColor'] = '#FC8452';
  216. p['fillColor'] = '#FAC8587D';
  217. }
  218. that.polygons.push(p);
  219. // let marketPoints = res.data.rtus.map(item => {
  220. // let rtu = {};
  221. // rtu['iconPath'] = '/static/images/icon_warning.png';
  222. // rtu['id'] = parseInt(item.id);
  223. // let r = gcoord.transform(
  224. // [item.stLong, item.stLat],
  225. // gcoord.WGS84,
  226. // gcoord.GCJ02
  227. // );
  228. // rtu['latitude'] = r[1];
  229. // rtu['longitude'] = r[0];
  230. // rtu['width'] = 20;
  231. // rtu['height'] = 20;
  232. // let label = {};
  233. // label['content'] = item.stName;
  234. // label['color'] = '#000000';
  235. // label['bgColor'] = '#ffffff';
  236. // label['anchorY'] = -40;
  237. // label['borderWidth'] = 1;
  238. // label['borderColor'] = '#ff0000';
  239. // label['padding'] = 4;
  240. // rtu['label'] = label;
  241. // return rtu;
  242. // });
  243. // that.markets = marketPoints;
  244. let c = gcoord.transform(
  245. [res.data.centerPointLng, res.data.centerPointLat],
  246. gcoord.WGS84,
  247. gcoord.GCJ02
  248. );
  249. that.latitude = c[1];
  250. that.longitude = c[0];
  251. }
  252. }).catch(err => {
  253. console.log(err)
  254. })
  255. },
  256. mapChange(e) {
  257. let selectDangerArea = false;
  258. let selectLine = false;
  259. let selectSite = false;
  260. let selectFamily = false;
  261. for (let i = 0; i < this.mapCheck.length; i++) {
  262. let value = this.mapCheck[i];
  263. if (value == 0) {
  264. selectDangerArea = true;
  265. } else if (value == 1) {
  266. selectLine = true;
  267. } else if (value == 2) {
  268. selectSite = true;
  269. } else if (value == 3) {
  270. selectFamily = true;
  271. }
  272. }
  273. if (selectDangerArea) {
  274. if (!this.isShowDangerArea) {
  275. let p = {};
  276. let ps = this.dangerAreaPoints.map(item => {
  277. let l = gcoord.transform(
  278. [item.pointLng, item.pointLat],
  279. gcoord.WGS84,
  280. gcoord.GCJ02
  281. );
  282. return {
  283. latitude: l[1],
  284. longitude: l[0],
  285. }
  286. })
  287. p['points'] = ps;
  288. let dashArray = [];
  289. dashArray.push(4);
  290. dashArray.push(10);
  291. p['dashArray'] = dashArray;
  292. if (this.dangerStatus == '1') {
  293. p['strokeColor'] = '#FF0000';
  294. p['fillColor'] = '#F72C5B7D';
  295. } else {
  296. p['strokeColor'] = '#FC8452';
  297. p['fillColor'] = '#FAC8587D';
  298. }
  299. this.polygons.push(p);
  300. this.isShowDangerArea = true;
  301. }
  302. } else {
  303. this.polygons = [];
  304. this.isShowDangerArea = false;
  305. }
  306. if (selectLine) {
  307. if (!this.isShowLine) {
  308. if (this.leaveLines != undefined && this.leaveLines != null && this.leaveLines.length > 0) {
  309. let line = this.leaveLines[0];
  310. this.getYjDangerAreaLineDetail(line);
  311. }
  312. this.isShowLine = true;
  313. }
  314. } else {
  315. this.polylines = [];
  316. this.isShowLine = false;
  317. }
  318. let rtus = [];
  319. if (selectSite) {
  320. rtus = this.rtuPoints.map(item => {
  321. let rtu = {};
  322. rtu['iconPath'] = '/static/images/icon_warning.png';
  323. rtu['id'] = parseInt(item.id);
  324. let r = gcoord.transform(
  325. [item.stLong, item.stLat],
  326. gcoord.WGS84,
  327. gcoord.GCJ02
  328. );
  329. rtu['latitude'] = r[1];
  330. rtu['longitude'] = r[0];
  331. rtu['width'] = 20;
  332. rtu['height'] = 20;
  333. let label = {};
  334. label['content'] = item.stName;
  335. label['color'] = '#000000';
  336. label['bgColor'] = '#ffffff';
  337. label['anchorY'] = -40;
  338. label['borderWidth'] = 1;
  339. label['borderColor'] = '#ff0000';
  340. label['padding'] = 4;
  341. rtu['label'] = label;
  342. return rtu;
  343. });
  344. this.isShowSite = true;
  345. } else {
  346. this.isShowSite = false;
  347. }
  348. let familys = [];
  349. if (selectFamily) {
  350. familys = this.familyPoints.map(item => {
  351. let rtu = {};
  352. rtu['iconPath'] = '/static/images/home.png';
  353. rtu['id'] = parseInt(item.id);
  354. let r = gcoord.transform(
  355. [item.longitude, item.latitude],
  356. gcoord.WGS84,
  357. gcoord.GCJ02
  358. );
  359. rtu['latitude'] = r[1];
  360. rtu['longitude'] = r[0];
  361. rtu['width'] = 20;
  362. rtu['height'] = 20;
  363. let label = {};
  364. label['content'] = item.personName;
  365. label['color'] = '#000000';
  366. label['bgColor'] = '#ffffff';
  367. label['anchorY'] = -40;
  368. label['borderWidth'] = 1;
  369. label['borderColor'] = '#ff0000';
  370. label['padding'] = 4;
  371. rtu['label'] = label;
  372. return rtu;
  373. });
  374. this.isShowFamily = true;
  375. } else {
  376. this.isShowFamily = false;
  377. }
  378. let markets = rtus.concat(familys)
  379. console.log(JSON.stringify(markets))
  380. this.markets = markets;
  381. },
  382. onYjDangerAreaLinkLineClick(line) {
  383. let that = this;
  384. if (this.isShowLine) {
  385. this.$nextTick(() => {
  386. that.getYjDangerAreaLineDetail(line);
  387. })
  388. }
  389. },
  390. getYjDangerAreaLineDetail(line) {
  391. let that = this;
  392. let postData = {};
  393. postData['id'] =line.id;
  394. http.request({
  395. url: '/galaxy-business/map/leaveline/detail',
  396. method: 'GET',
  397. data: postData
  398. }).then(res => {
  399. if (res.data != null) {
  400. that.polylines = [];
  401. let p = {};
  402. let ps = res.data.points.map(item => {
  403. let l = gcoord.transform(
  404. [item.pointLng, item.pointLat],
  405. gcoord.WGS84,
  406. gcoord.GCJ02
  407. );
  408. return {
  409. latitude: l[1],
  410. longitude: l[0],
  411. }
  412. })
  413. p['points'] = ps;
  414. if (that.dangerStatus == '1') {
  415. p['color'] = '#FAC858FF';
  416. } else {
  417. p['color'] = '#F72C5BFF';
  418. }
  419. p['width'] = 4;
  420. that.polylines.push(p);
  421. let c = gcoord.transform(
  422. [line.centerPointLng, line.centerPointLat],
  423. gcoord.WGS84,
  424. gcoord.GCJ02
  425. );
  426. that.mapContext.moveToLocation({
  427. longitude: c[0],
  428. latitude: c[1],
  429. success: (res) => {
  430. }
  431. });
  432. }
  433. }).catch(err => {
  434. console.log(err)
  435. })
  436. },
  437. onYjDangerAreaLinkRtuClick(rtu) {
  438. let c = gcoord.transform(
  439. [rtu.stLong, rtu.stLat],
  440. gcoord.WGS84,
  441. gcoord.GCJ02
  442. );
  443. let lat = c[1];
  444. let long = c[0];
  445. this.mapContext.moveToLocation({
  446. longitude: long,
  447. latitude: lat,
  448. success: (res) => {
  449. }
  450. });
  451. },
  452. onYjDangerAreaLinkFamilyClick() {
  453. let f = this.familyPoints[0];
  454. let c = gcoord.transform(
  455. [f.longitude, f.latitude],
  456. gcoord.WGS84,
  457. gcoord.GCJ02
  458. );
  459. this.mapContext.moveToLocation({
  460. longitude: c[0],
  461. latitude: c[1],
  462. success: (res) => {
  463. }
  464. });
  465. // let includePoints = this.familyPoints.map(item => {
  466. // let p = {};
  467. // let r = gcoord.transform(
  468. // [item.longitude, item.latitude],
  469. // gcoord.WGS84,
  470. // gcoord.GCJ02
  471. // );
  472. // p['latitude'] = r[1];
  473. // p['longitude'] = r[0];
  474. // return p;
  475. // });
  476. // this.mapContext.includePoints({
  477. // points: includePoints
  478. // });
  479. }
  480. }
  481. }
  482. </script>
  483. <style>
  484. /* page {
  485. background-color: rgb(240, 242, 244);
  486. } */
  487. .uni-body {
  488. font-size: 0.7rem;
  489. }
  490. </style>