map.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <div class="sjdpMap">
  3. <!-- <div class="title">
  4. <div class="font"><font v-for="(item, i) in orgHistory" :key="i">{{item.name}}{{orgHistory.length-1 >i?"/":""}}</font></div>
  5. <img @click="orgBack" v-if="orgHistory.length > 1" class="ico" src="../../../static/mapBoard/goBack.png" />
  6. </div> -->
  7. <div class="date" v-if="dateTag">
  8. <font>日期范围:</font>
  9. <div class="input">
  10. <a-range-picker v-model="date" @change="pushFunc" @calendarChange="initDisabledDate" :placeholder="['起始日期', '截止日期']"
  11. :disabled-date="disabledDate" />
  12. </div>
  13. </div>
  14. <div id="container" class="map"></div>
  15. <!-- <div class="mapExample">
  16. <div class="one" v-if="userinfo.type <= 0">
  17. <img src="../../../static/mapBoard/mapExample_1.png" />
  18. <font>总中心</font>
  19. </div>
  20. <div class="one" v-if="userinfo.type <= 1">
  21. <img src="../../../static/mapBoard/mapExample_2.png" />
  22. <font>分中心</font>
  23. </div>
  24. <div class="one" v-if="userinfo.type <= 2">
  25. <img src="../../../static/mapBoard/mapExample_3.png" />
  26. <font>隧管站</font>
  27. </div>
  28. <div class="one" v-if="userinfo.type <= 3">
  29. <img src="../../../static/mapBoard/mapExample_4.png" />
  30. <font>隧道</font>
  31. </div>
  32. </div> -->
  33. </div>
  34. </template>
  35. <script>
  36. import BMPGL_style from '@components/index/map_style'
  37. import BMPGL from '@components/index/mapInit'
  38. export default {
  39. data () {
  40. return {
  41. userinfo: "", // 用户信息 - 从缓存中取
  42. orgData: [], // 组织机构数据
  43. orgLevel: 0, // 记录当前组织的等级
  44. orgHistory: [], // 记录当前层级到顶级的所有组织id
  45. orgNowChoose: [], // 组织机构 - 当前选择的组织id集合
  46. sdFId: [], // 选隧道 - 存隧管站ID
  47. timer: null, // 处理同一个元素上的单击和双击冲突
  48. date: ["", ""], // 日期
  49. disabledDate: "", // 日期控件可选的范围控制函数变量
  50. startDate: "2019-10-10 00:00:00", // 默认项目其实日期
  51. moveTag: false, // 是否移动
  52. map: null, // 地图
  53. }
  54. },
  55. props: {
  56. dateTag: Boolean, // 是否开启日期选择
  57. },
  58. created () {
  59. this.init();
  60. },
  61. methods: {
  62. //初始化
  63. init () {
  64. this.initMap();
  65. },
  66. // 初始化地图
  67. initMap () {
  68. let _this = this;
  69. // 地图实力存在需要先销毁
  70. // 销毁地图,当使用 WebGL 渲染地图时,如果确认不再使用该地图实例,则需要调用本方法销毁 WebGL 上下文,
  71. // 否则频繁创建新地图实例会导致浏览器报:too many WebGL context 的警告
  72. if (this.map !== null) {
  73. this.map.destroy();
  74. }
  75. BMPGL.init().then(BMapGL => {
  76. // 创建地图实例
  77. this.map = new BMapGL.Map('container');
  78. this.map.centerAndZoom(new BMapGL.Point(106.152924, 37.387416), 8);
  79. this.map.enableScrollWheelZoom(true);
  80. // 改变地图风格
  81. this.map.setMapStyleV2({
  82. styleJson: BMPGL_style
  83. });
  84. // 描边
  85. // var bd1 = new BMapGL.Boundary();
  86. // bd1.get('宁夏', function (rs) {
  87. // let count = rs.boundaries.length;
  88. // for (let i = 0; i < count; i++) {
  89. // let path = [];
  90. // let str = rs.boundaries[i].replace(' ', '');
  91. // let points = str.split(';');
  92. // for (let j = 0; j < points.length; j++) {
  93. // let lng = points[j].split(',')[0];
  94. // let lat = points[j].split(',')[1];
  95. // path.push(new BMapGL.Point(lng, lat));
  96. // }
  97. // let prism = new BMapGL.Prism(path, 5000, {
  98. // topFillColor: '#1e6aff',
  99. // topFillOpacity: 0.4,
  100. // sideFillColor: '#04367b',
  101. // sideFillOpacity: 0.4
  102. // });
  103. // _this.map.addOverlay(prism);
  104. // }
  105. // });
  106. // 描边
  107. var bd1 = new BMapGL.Boundary();
  108. bd1.get('银川', function (rs) {
  109. let count = rs.boundaries.length;
  110. for (let i = 0; i < count; i++) {
  111. let path = [];
  112. let str = rs.boundaries[i].replace(' ', '');
  113. let points = str.split(';');
  114. for (let j = 0; j < points.length; j++) {
  115. let lng = points[j].split(',')[0];
  116. let lat = points[j].split(',')[1];
  117. path.push(new BMapGL.Point(lng, lat));
  118. }
  119. let prism = new BMapGL.Prism(path, 5000, {
  120. topFillColor: '#00E6FF',
  121. topFillOpacity: 0.4,
  122. sideFillColor: '#04367b',
  123. sideFillOpacity: 0.4
  124. });
  125. _this.map.addOverlay(prism);
  126. }
  127. });
  128. // 描边
  129. var bd1 = new BMapGL.Boundary();
  130. bd1.get('吴忠', function (rs) {
  131. let count = rs.boundaries.length;
  132. for (let i = 0; i < count; i++) {
  133. let path = [];
  134. let str = rs.boundaries[i].replace(' ', '');
  135. let points = str.split(';');
  136. for (let j = 0; j < points.length; j++) {
  137. let lng = points[j].split(',')[0];
  138. let lat = points[j].split(',')[1];
  139. path.push(new BMapGL.Point(lng, lat));
  140. }
  141. let prism = new BMapGL.Prism(path, 5000, {
  142. topFillColor: '#3D8BFF',
  143. topFillOpacity: 0.4,
  144. sideFillColor: '#04367b',
  145. sideFillOpacity: 0.4
  146. });
  147. _this.map.addOverlay(prism);
  148. }
  149. });
  150. // 描边
  151. var bd1 = new BMapGL.Boundary();
  152. bd1.get('石嘴山', function (rs) {
  153. let count = rs.boundaries.length;
  154. for (let i = 0; i < count; i++) {
  155. let path = [];
  156. let str = rs.boundaries[i].replace(' ', '');
  157. let points = str.split(';');
  158. for (let j = 0; j < points.length; j++) {
  159. let lng = points[j].split(',')[0];
  160. let lat = points[j].split(',')[1];
  161. path.push(new BMapGL.Point(lng, lat));
  162. }
  163. let prism = new BMapGL.Prism(path, 5000, {
  164. topFillColor: '#7AAFFF',
  165. topFillOpacity: 0.4,
  166. sideFillColor: '#04367b',
  167. sideFillOpacity: 0.4
  168. });
  169. _this.map.addOverlay(prism);
  170. }
  171. });
  172. // 描边
  173. var bd1 = new BMapGL.Boundary();
  174. bd1.get('中卫', function (rs) {
  175. let count = rs.boundaries.length;
  176. for (let i = 0; i < count; i++) {
  177. let path = [];
  178. let str = rs.boundaries[i].replace(' ', '');
  179. let points = str.split(';');
  180. for (let j = 0; j < points.length; j++) {
  181. let lng = points[j].split(',')[0];
  182. let lat = points[j].split(',')[1];
  183. path.push(new BMapGL.Point(lng, lat));
  184. }
  185. let prism = new BMapGL.Prism(path, 5000, {
  186. topFillColor: '#FFB13D',
  187. topFillOpacity: 0.4,
  188. sideFillColor: '#04367b',
  189. sideFillOpacity: 0.4
  190. });
  191. _this.map.addOverlay(prism);
  192. }
  193. });
  194. // 描边
  195. var bd1 = new BMapGL.Boundary();
  196. bd1.get('固原', function (rs) {
  197. let count = rs.boundaries.length;
  198. for (let i = 0; i < count; i++) {
  199. let path = [];
  200. let str = rs.boundaries[i].replace(' ', '');
  201. let points = str.split(';');
  202. for (let j = 0; j < points.length; j++) {
  203. let lng = points[j].split(',')[0];
  204. let lat = points[j].split(',')[1];
  205. path.push(new BMapGL.Point(lng, lat));
  206. }
  207. let prism = new BMapGL.Prism(path, 5000, {
  208. topFillColor: '#D24EE9',
  209. topFillOpacity: 0.4,
  210. sideFillColor: '#04367b',
  211. sideFillOpacity: 0.4
  212. });
  213. _this.map.addOverlay(prism);
  214. }
  215. });
  216. // // 创建点标记
  217. // let _this = this;
  218. // this.orgData.forEach((item)=>{
  219. // let quanStyle = item.type === undefined?4:item.type;
  220. // let sizeDefault = [20, 20];
  221. // let size = [54, 54];
  222. // let mouseoverColor = ""; // 离开
  223. // let mouseoutColor = ""; // 进入
  224. // switch(quanStyle) {
  225. // case 1:
  226. // size = [54, 54];
  227. // mouseoverColor = "mapExample_1"; // 离开
  228. // mouseoutColor = "mapD_1"; // 进入
  229. // break;
  230. // case 2:
  231. // size = [54, 54];
  232. // mouseoverColor = "mapExample_2"; // 离开
  233. // mouseoutColor = "mapD_2"; // 进入
  234. // break;
  235. // case 3:
  236. // size = [48, 48];
  237. // mouseoverColor = "mapExample_3"; // 离开
  238. // mouseoutColor = "mapD_3"; // 进入
  239. // break;
  240. // case 4:
  241. // size = [44, 44];
  242. // mouseoverColor = "mapExample_4"; // 离开
  243. // mouseoutColor = "mapD_4"; // 进入
  244. // break;
  245. // }
  246. // // 创建图标
  247. // var myIcon = new BMapGL.Icon("/static/mapBoard/"+mouseoutColor+".png", new BMapGL.Size(size[0], size[1]));
  248. // // 创建Marker标注,使用小车图标
  249. // var pt = new BMapGL.Point(item.latitude, item.longitude);
  250. // var marker = new BMapGL.Marker(pt, {
  251. // icon: myIcon
  252. // });
  253. // // 将标注添加到地图
  254. // this.map.addOverlay(marker);
  255. // // 添加鼠标事件
  256. // marker.addEventListener('mouseover', function() {
  257. // var opts = {
  258. // width : 0, // 信息窗口宽度
  259. // height: 0,
  260. // offset: new BMapGL.Size(10, -10), // 偏移
  261. // title : item.name , // 信息窗口标题
  262. // }
  263. // var infoWindow = new BMapGL.InfoWindow(item.remark !== undefined?item.remark:item.lineName, opts); // 创建信息窗口对象
  264. // _this.map.openInfoWindow(infoWindow, new BMapGL.Point(item.latitude, item.longitude)); //开启信息窗口
  265. // });
  266. // marker.addEventListener('mouseout', function(e) {
  267. // _this.map.closeInfoWindow();
  268. // })
  269. // marker.addEventListener('click', function(e) {
  270. // _this.changeOrgID(item);
  271. // let mouseTag = e.target.getIcon().imageUrl.indexOf("/mapD_") >= 0;
  272. // if(mouseTag){
  273. // if(_this.orgNowChoose.length > 1){
  274. // var myIcon1 = new BMapGL.Icon("/static/mapBoard/"+mouseoverColor+".png", new BMapGL.Size(sizeDefault[0], sizeDefault[1]));
  275. // e.target.setIcon(myIcon1);
  276. // }
  277. // }else{
  278. // var myIcon1 = new BMapGL.Icon("/static/mapBoard/"+mouseoutColor+".png", new BMapGL.Size(size[0], size[1]));
  279. // e.target.setIcon(myIcon1);
  280. // }
  281. // })
  282. // marker.addEventListener('dblclick', function(e) {
  283. // _this.getOrg(item)
  284. // })
  285. // this.map.addOverlay(marker);
  286. // });
  287. })
  288. .catch(err => {
  289. console.log(err);
  290. });
  291. },
  292. }
  293. }
  294. </script>
  295. <style lang="scss" scoped>
  296. .sjdpMap {
  297. width: 100%;
  298. height: 100%;
  299. .map {
  300. width: 100%;
  301. height: 100%;
  302. z-index: 1;
  303. ::v-deep .anchorBL {
  304. display: none;
  305. }
  306. }
  307. .mapExample {
  308. position: absolute;
  309. bottom: 30px;
  310. right: 60px;
  311. > .one {
  312. overflow: hidden;
  313. margin-top: 10px;
  314. > img {
  315. float: left;
  316. }
  317. > font {
  318. line-height: 20px;
  319. float: left;
  320. margin-left: 9px;
  321. }
  322. }
  323. }
  324. }
  325. </style>