map-gaode-selfManagement.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import AMap from 'AMap'
  2. import mapData from '@a/js/map-data.js'
  3. // import AMapUI from 'AMapUI'
  4. export default {
  5. data() {
  6. return {
  7. icon: require('@a/img/icon/icon-qyzz.png'),
  8. map: null,
  9. mapPolList: [],
  10. colorList: [
  11. ['#99e', "#F33"],
  12. ['#ee6', "#c38"],
  13. ['#c38', "#F33"],
  14. ['#6E7', '#F33'],
  15. ['#6A7', "#F33"],
  16. ['#EF7', "#F33"],
  17. ['#AF7', "#F33"],
  18. ['#BAC', "#F33"],
  19. ['#BEF', "#F33"],
  20. ['#BBB', "#F33"],
  21. ['#EFA', "#F33"],
  22. ['#FE6', "#F33"],
  23. ['#7F6', "#F33"],
  24. ['#7dc', "#F33"],
  25. ],
  26. colorIndList: [-1, 7, 21, 26, 31, 37, 46, 52, 57, 66, 68, 71, 74, 100]
  27. }
  28. },
  29. mounted() {
  30. window['tb1'] = () => {
  31. this.tb1()
  32. },
  33. window['tb2'] = () => {
  34. this.tb2()
  35. }
  36. window['tb3'] = () => {
  37. this.tb3()
  38. }
  39. },
  40. methods: {
  41. tb1() {
  42. this.$store.commit('qyzz', { qyzz: "电量" });
  43. },
  44. tb2() {
  45. this.$store.commit('qyzz', { qyzz: "信号" });
  46. console.log(2)
  47. },
  48. tb3() {
  49. this.$store.commit('qyzz', { qyzz: "液位" });
  50. console.log(3)
  51. },
  52. addMarkerInfo(position, value) { //消防水情况
  53. var icon = this.icon
  54. // this.map.getIsOpen();
  55. this.map.clearInfoWindow();
  56. // var icon = require('')
  57. var json = eval('(' + value.property + ')');
  58. var code = value.code
  59. var infoWindow = new AMap.InfoWindow({
  60. isCustom: true, //使用自定义窗体
  61. closeWhenClickMap: true,
  62. content: `
  63. <div class="tableTooltip mapTab">
  64. <div class="tableTitle">
  65. <div>${value.deviceType}</div>
  66. </div>
  67. <el-row class="tableContent">
  68. <div class="max">设备编号:${value.code}</div>
  69. <div class="max">检测对象:${value.deviceType}</div>
  70. <div class="max">数据更新时间:${value.createTime}</div>
  71. <div class="max">剩余电量:
  72. ${json && json.find(val=>val.property === '电量') ? json.find(val=>val.property === '电量').serial : '--'}
  73. <img src="${icon}" alt="" class="icon2" v-if="json && json.find(val=>val.property === '电量')" onclick="tb1()" /></div>
  74. <div class="max">无线信号:
  75. ${json && json.find(val=>val.property === '信号') ? json.find(val=>val.property === '信号').serial : '--'}
  76. <img src="${icon}" alt="" class="icon2" v-if="json && json.find(val=>val.property === '信号')" onclick="tb2()" /></div>
  77. <div class="max">液位:
  78. ${json && json.find(val=>val.property === '水压') ? json.find(val=>val.property === '水压').serial : '--'}
  79. <img src="${icon}" alt="" class="icon2" v-if="json && json.find(val=>val.property === '水压')" onclick="tb3()" /></div>
  80. </el-row>
  81. </div>`,
  82. offset: new AMap.Pixel(16, -30)
  83. });
  84. infoWindow.open(this.map, position);
  85. },
  86. // async tb(msg) {
  87. // console.log(1, msg)
  88. // return msg
  89. // },
  90. async initMap() {
  91. this.map = await new AMap.Map('mapF', { //地图初始化
  92. mapStyle: 'amap://styles/d0ddc09bd7cbd7331a8e8fa691e5b0da', //设置地图的显示样式
  93. resizeEnable: true,
  94. zoom: 13,
  95. zooms: [3, 16],
  96. //pitch: 1, // 地图俯仰角度,有效范围 0 度- 83 度
  97. //viewMode: '3D' // 地图模式
  98. // features: [] //清空背景道路等
  99. })
  100. AMap.plugin(["AMap.Geolocation"], () => {
  101. var geolocation = new AMap.Geolocation({
  102. showButton: true, //是否显示定位按钮
  103. buttonPosition: "RT", //定位按钮的位置
  104. /* LT LB RT RB */
  105. buttonOffset: new AMap.Pixel(10, 20), //定位按钮距离对应角落的距离
  106. zoomToAccuracy: false, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
  107. showMarker: true, //是否显示定位点
  108. markerOptions: {
  109. //自定义定位点样式,同Marker的Options
  110. offset: new AMap.Pixel(-18, -36),
  111. content: '<img src="https://a.amap.com/jsapi_demos/static/resource/img/user.png" style="width:36px;height:36px"/>',
  112. },
  113. convert: true,
  114. showCircle: true, //是否显示定位精度圈
  115. circleOptions: {
  116. //定位精度圈的样式
  117. strokeColor: "#0093FF",
  118. noSelect: true,
  119. strokeOpacity: 0.5,
  120. strokeWeight: 1,
  121. fillColor: "#02B0FF",
  122. fillOpacity: 0.25,
  123. },
  124. });
  125. this.map.addControl(geolocation);
  126. // geolocation.getCurrentPosition();
  127. });
  128. this.mapPolList = mapData.map((val, ind) => {
  129. // console.log(val)
  130. let color = this.colorList[this.colorIndList.findIndex((value, index) => value <= ind && ind < this.colorIndList[index + 1])]
  131. return [new AMap.Polygon({
  132. map: this.map,
  133. fillOpacity: 0.5,
  134. path: val[3],
  135. fillColor: color[0],
  136. strokeColor: color[1],
  137. }), new AMap.Polygon({
  138. map: this.map,
  139. fillOpacity: 0.5,
  140. path: val[3],
  141. fillColor: color[1],
  142. strokeColor: color[0],
  143. })]
  144. })
  145. this.map.on('mousemove', (e) => {
  146. var point = [e.lnglat.getLng(), e.lnglat.getLat()]
  147. var pointList = mapData.map(val => {
  148. return AMap.GeometryUtil.isPointInRing(point, val[3])
  149. })
  150. this.mapPolList.forEach((element, ind) => {
  151. if (pointList[ind]) {
  152. this.map.remove(element[0]);
  153. this.map.add(element[1]);
  154. } else {
  155. this.map.remove(element[1]);
  156. this.map.add(element[0]);
  157. }
  158. });
  159. })
  160. this.map.setFitView();
  161. },
  162. randomColor() {
  163. var color = "#";
  164. //for循环中,如果后面仅有一条语句,{}可省略不写
  165. //随机生成6位0-15之间的数字,再用toString(16)将数字转成16进制
  166. for (var i = 0; i < 6; i++) color += parseInt(Math.random() * 16).toString(16);
  167. return color;
  168. },
  169. deleteMarker(lnglats) {
  170. this.map.remove(lnglats);
  171. },
  172. addMarker(lnglats, type) {
  173. // 创建标点和点击事件
  174. let icon = ''
  175. let markers = lnglats.map((val, ind) => {
  176. if (type === 'water') {
  177. icon = val.waterAdministrative === '单位' ? 'http://120.55.70.156/image/unitWater.png' : val.waterAdministrative === '市政' ? 'http://120.55.70.156/image/szWater.png' : val.waterAdministrative === '社区' || val.waterAdministrative === '居民' ? 'http://120.55.70.156/image/sqWater.png' : ''
  178. //icon = val.waterAdministrative === '单位' ? '' : val.waterAdministrative === '市政' ? '' : val.waterAdministrative === '社区' || val.waterAdministrative === '居民' ? '' : ''
  179. } else {
  180. icon = val.waterAdministrative === '单位' ? 'http://120.55.70.156/image/unitWater.png' : val.waterAdministrative === '市政' ? 'http://120.55.70.156/image/szWater.png' : val.waterAdministrative === '社区' || val.waterAdministrative === '居民' ? 'http://120.55.70.156/image/sqWater.png' : ''
  181. }
  182. let marker = new AMap.Marker({
  183. position: new AMap.LngLat(val.longitude, val.latitude),
  184. icon: icon,
  185. zIndex: 9,
  186. extData: {
  187. id: ind + 1
  188. }
  189. });
  190. if (lnglats.length == 1) {
  191. console.log("正常")
  192. this.addMarkerInfo([val.longitude, val.latitude], val)
  193. }
  194. marker.on('click', async() => {
  195. let res = await this.$axios.get(this.$api.selfManagement.one + "?" +
  196. this.$qs.stringify({
  197. id: val.id
  198. }));
  199. if (res) {
  200. this.$store.commit('qyzzId', { qyzzId: res.data.code });
  201. await this.addMarkerInfo([val.longitude, val.latitude], res.data)
  202. }
  203. })
  204. return marker
  205. })
  206. this.map.add(new AMap.OverlayGroup(markers));
  207. //this.map.setFitView(); // 根据所有点自适应
  208. },
  209. }
  210. }