bigeMap.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. <template>
  2. <div>
  3. <div id='map'></div>
  4. <div id="position">
  5. <div id="zoom">
  6. 当前级别 : 6
  7. </div>
  8. <div id="move">
  9. 当前中心点: 纬度:0.00000,经度:0.00000
  10. </div>
  11. </div>
  12. <!-- <el-radio-group v-model="leavel" @change="setData">-->
  13. <!-- <el-radio class="radio" label="100">100Mb</el-radio>-->
  14. <!-- <el-radio class="radio" label="250">250Mb</el-radio>-->
  15. <!-- <el-radio class="radio" label="500">500Mb</el-radio>-->
  16. <!-- <el-radio class="radio" label="1000">1000Mb</el-radio>-->
  17. <!-- </el-radio-group>-->
  18. </div>
  19. </template>
  20. <script>
  21. import bigemap from '@/utils/bigemap/map'
  22. import Tiff from "tiff.js";
  23. import axios from "axios";
  24. let map;
  25. export default {
  26. name: "bigeMap",
  27. props: {mapValue: Object},
  28. watch: {
  29. mapValue: {
  30. immediate: true,
  31. handler(value) {
  32. if(value.params !== undefined){
  33. console.log("地形图:"+value)
  34. this.mapData = value
  35. this.initBigeMap()
  36. }
  37. }
  38. }
  39. },
  40. data() {
  41. return {
  42. bMap: null,
  43. velocityLayer: null,
  44. leavel: {},
  45. latlngs: [[[0.0, 0.0], [0.0, 0.0]]],
  46. cone: {},
  47. mTime: null,
  48. code: 230000,
  49. mapData:{},// 传过来的值
  50. href: window.location.href,
  51. level:6,
  52. center:[],
  53. }
  54. },
  55. mounted() {
  56. },
  57. methods: {
  58. initBigeMap() {
  59. let _self = this
  60. bigemap.then(() => {
  61. // window.BM.Config.HTTP_URL = 'http://www.bigemap.com:9000';
  62. //window.BM.Config.HTTP_URL = 'http://10.124.252.244/webgis-api';
  63. window.BM.Config.HTTP_URL = process.env.VUE_APP_GIS_API;
  64. let ip1 = process.env.VUE_APP_GIS_API;
  65. let ip2 = 'http://49.4.78.194:17143';
  66. let mapid = 'bigemap.re-huafu'
  67. // window.BM.Config.HTTP_URL = 'http://192.168.1.181:9000';
  68. // arcgis-satellite
  69. // amap-satellite
  70. // zhongkexingtu
  71. // let map = window.BM.map('map', 'bigemap.arcgis-satellite', {
  72. let map = window.BM.map('map', null, {
  73. center: [30, 104],
  74. minZoom: 6,
  75. zoom: 11,
  76. zoomControl: true,
  77. attributionControl: false,
  78. preferCanvas: true, //适用于数据量大时 地图反应速度加快
  79. });
  80. var promise = fetch(`${ip1}/tokens/v1?access_token=none`).then(function (response) {
  81. return response.json();
  82. }).then(function (body) {
  83. return body.token
  84. }).then(
  85. (token) => {
  86. var CanvasLayer = BM.GridLayer.extend({
  87. createTile: function (coords, done) {
  88. let error;
  89. let {
  90. x,
  91. y,
  92. z
  93. } = coords;
  94. let tile = new Image;
  95. tile.style.backgroundColor = 'inherit';
  96. tile.src = `${ip2}/${mapid}/tiles/${z}/${x}/${y}.png?access_token=${token}`
  97. setTimeout(function () {
  98. done(error, tile);
  99. return null
  100. }, 1000);
  101. return tile;
  102. }
  103. });
  104. new CanvasLayer({maxZoom:12}).addTo(map);
  105. }
  106. )
  107. window.Bmap=map;
  108. this.bMap=map;
  109. //首尾需要一致
  110. let mask = window.BMturf.polygon([[[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]]]);
  111. let geo2;
  112. fetch('/js/geojson/230000/' + this.code + '.geojson').then(res => res.json()).then(data => {
  113. // fetch('/js/geojson/' + this.code + '.geojson').then(res => res.json()).then(data => {
  114. geo2 = window.BM.geoJSON(data, {
  115. style: function () {
  116. return {
  117. color: '#ffffff',
  118. weight: 3,
  119. fillColor: '#ffffff',
  120. fillOpacity: 0
  121. };
  122. },
  123. onEachFeature: function (feature, layer) {
  124. feature.properties && feature.properties.name && layer.bindTooltip(feature.properties.name, {
  125. direction: 'bottom',
  126. className: 'my_default_tooltip',
  127. permanent: true
  128. });
  129. }
  130. }).on('mouseover', function (e) {
  131. e.layer.setStyle({
  132. color: '#ffffff',
  133. weight: 1,
  134. fillColor: 'transparent',
  135. fillOpacity: 0
  136. });
  137. }).on('mouseout', function (e) {
  138. e.layer.setStyle({
  139. color: '#ffffff',
  140. weight: 3,
  141. fillColor: '#ffffff',
  142. fillOpacity: 0
  143. });
  144. }).addTo(this.bMap);
  145. window.geo2=geo2;
  146. //限制拖动
  147. this.bMap.setMaxBounds(geo2.getBounds());
  148. this.bMap.fitBounds(geo2.getBounds());
  149. const layers = geo2.getLayers();
  150. for (const item of layers) {
  151. const layer = item.feature;
  152. mask = window.BMturf.mask(layer, mask);
  153. }
  154. window.BM.geoJSON(mask, {
  155. color: 'orange',
  156. fillColor: '#0A163A',
  157. fillOpacity: 0.7
  158. }).addTo(this.bMap);
  159. //初始化热力图
  160. // this.setHeatMap(this.bMap);
  161. //绑定事件
  162. this.bindEvents(this.bMap);
  163. if(this.mapData.level !== null){
  164. _self.level = this.mapData.level
  165. _self.center = this.mapData.center
  166. this.bMap.setView(this.mapData.center,this.mapData.level)
  167. // this.bMap.setZoom(this.mapData.level)
  168. // this.bMap.panTo(this.mapData.center)
  169. }
  170. })
  171. let sIconurl = 'http://'+_self.href.split("//")[1].split("/")[0]+'/largeScreenImg/station.png'
  172. let hfSIconurl = 'http://'+_self.href.split("//")[1].split("/")[0]+'/largeScreenImg/huafuStation.png'
  173. let pIconurl = 'http://' + _self.href.split("//")[1].split("/")[0] + '/largeScreenImg/project.png'
  174. let fjIconurl = 'http://' + _self.href.split("//")[1].split("/")[0] + '/img/fengji.png'
  175. // 所有场站标记点位
  176. if(this.mapData.allStationInfo !== null && this.mapData.allStationInfo !== undefined){
  177. let data = this.mapData.allStationInfo
  178. let station_icon = window.BM.icon({
  179. iconUrl: sIconurl,
  180. iconSize: [25, 43],
  181. iconAnchor: [25, 43]
  182. })
  183. let hf_station_icon = window.BM.icon({
  184. iconUrl: hfSIconurl,
  185. iconSize: [35, 55],
  186. iconAnchor: [35, 55]
  187. })
  188. for(let item of data.otherStation){
  189. let coordinate = [Number(item.latitude),Number(item.longitude)]
  190. let marker = window.BM.marker(coordinate,{
  191. icon: station_icon,
  192. riseOnHover: true
  193. }).addTo(this.bMap);
  194. marker.on('mouseover', function (e) {
  195. marker.bindTooltip('<div>场站名称:' + item.stationName + '</div>' + '<div>经度:' + item.longitude + '</div>' + '<div>纬度:' + item.latitude + '</div>',
  196. {permanent:true,className:'infoToolTip',offset:[0,-30]}).openTooltip();
  197. })
  198. marker.on('mouseout', function () {
  199. marker.bindTooltip().closeTooltip();
  200. })
  201. }
  202. for(let item of data.HDStation){
  203. let coordinate = [Number(item.latitude),Number(item.longitude)]
  204. let marker = window.BM.marker(coordinate,{
  205. icon: hf_station_icon,
  206. riseOnHover: true
  207. }).addTo(this.bMap);
  208. marker.on('mouseover', function (e) {
  209. marker.bindTooltip('<div>场站名称:' + item.stationName + '</div>' + '<div>经度:' + item.longitude + '</div>' + '<div>纬度:' + item.latitude + '</div>',
  210. {permanent:true,className:'infoToolTip',offset:[0,-30]}).openTooltip();
  211. })
  212. marker.on('mouseout', function () {
  213. marker.bindTooltip().closeTooltip();
  214. })
  215. }
  216. }
  217. // 项目标记点位
  218. if (this.mapData.projectInfo !== null && this.mapData.projectInfo !== undefined) {
  219. let data = this.mapData.projectInfo
  220. let station_icon = window.BM.icon({
  221. iconUrl: pIconurl,
  222. iconSize: [30, 50],
  223. iconAnchor: [30, 50]
  224. })
  225. for (let item of data) {
  226. let coordinate = [Number(item.latitude), Number(item.longitude)]
  227. let marker = window.BM.marker(coordinate, {
  228. icon: station_icon,
  229. riseOnHover: true
  230. }).addTo(this.bMap);
  231. // 悬浮动作
  232. marker.on('mouseover', function (e) {
  233. marker.bindTooltip('<div>项目名称:' + item.projectNameEasy + '</div>' + '<div>经度:' + item.longitude + '</div>' + '<div>纬度:' + item.latitude + '</div>',
  234. {permanent:true,className:'infoToolTip',offset:[0,-30]}).openTooltip();
  235. })
  236. marker.on('mouseout', function () {
  237. marker.bindTooltip().closeTooltip();
  238. })
  239. // 点击动作
  240. marker.on('click', function (e) {
  241. let project = {id: item.id,projectSort: item.projectName}
  242. sessionStorage.setItem("projectInfo", JSON.stringify(project))
  243. _self.$store.dispatch('equipmentInfo/projectInfo', JSON.stringify(project))
  244. _self.$router.push({path: "/homepage/projectInfo"})
  245. })
  246. }
  247. }
  248. // 华富场站标记点位
  249. if (this.mapData.staionInfo !== null && this.mapData.staionInfo !== undefined) {
  250. let data = this.mapData.staionInfo
  251. let station_icon = window.BM.icon({
  252. iconUrl: sIconurl,
  253. iconSize: [30, 50],
  254. iconAnchor: [30, 50],
  255. className:'stationIcon',
  256. })
  257. for (let item of data) {
  258. let coordinate = [Number(item.latitude), Number(item.longitude)]
  259. let marker = window.BM.marker(coordinate, {
  260. icon: station_icon,
  261. riseOnHover: true
  262. }).addTo(this.bMap);
  263. // 悬浮动作
  264. marker.on('mouseover', function (e) {
  265. marker.bindTooltip('<div>场站名称:' + item.stationName + '</div>' + '<div>经度:' + item.longitude + '</div>' + '<div>纬度:' + item.latitude + '</div>',
  266. {permanent:true,className:'infoToolTip',offset:[0,-30]}).openTooltip();
  267. })
  268. marker.on('mouseout', function () {
  269. marker.bindTooltip().closeTooltip();
  270. })
  271. // 点击动作
  272. marker.on('click', function (e) {
  273. let station = {id: item.id,stationName: item.stationName}
  274. sessionStorage.setItem("stationInfo",JSON.stringify(station))
  275. _self.$store.dispatch('equipmentInfo/stationInfo',JSON.stringify(station))
  276. _self.$router.push({path: "/homepage/stationInfo"})
  277. })
  278. }
  279. }
  280. // 所有风机、塔、拐点标记点位
  281. if (this.mapData.allPointInfo !== null && this.mapData.allPointInfo !== undefined) {
  282. let data = this.mapData.allPointInfo
  283. let station_icon = window.BM.icon({
  284. iconUrl: pIconurl,
  285. iconSize: [35, 55],
  286. iconAnchor: [35, 55],
  287. className:'stationIcon',
  288. })
  289. let fj_icon = window.BM.icon({
  290. iconUrl: fjIconurl,
  291. iconSize: [30, 30],
  292. iconAnchor: [30, 30],
  293. className:'stationIcon',
  294. })
  295. for(let item of data.fan){
  296. let coordinate = [Number(item.latitudeFan),Number(item.longitudeFan)]
  297. let marker = window.BM.marker(coordinate,{
  298. icon: fj_icon,
  299. riseOnHover: true
  300. }).addTo(this.bMap);
  301. }
  302. for(let item of data.coordinatesList){
  303. if(item.length>0){
  304. let latlngs = []
  305. for (let coor of item){
  306. latlngs.push([Number(coor.latitude),Number(coor.longitude)])
  307. window.BM.marker([Number(coor.latitude),Number(coor.longitude)]).addTo(this.bMap);
  308. }
  309. var polygon = BM.polygon(latlngs).addTo(this.bMap);
  310. // 让地图适配当前的线段
  311. this.bMap.fitBounds(polygon.getBounds());
  312. }
  313. }
  314. for (let item of data.towerList) {
  315. let coordinate = [Number(item.latitude), Number(item.longitude)]
  316. let marker = window.BM.marker(coordinate, {
  317. icon: station_icon,
  318. riseOnHover: true
  319. }).addTo(this.bMap);
  320. // 悬浮动作
  321. marker.on('mouseover', function (e) {
  322. // console.log(item)
  323. if(item.type === 'project'){
  324. marker.bindTooltip('<div>项目名称:' + item.projectName + '</div>'+ '<div>测风塔名称:' + item.towerName + '</div>' + '<div>经度:' + item.longitude + '</div>' + '<div>纬度:' + item.latitude + '</div>',
  325. {permanent:true,className:'infoToolTip',offset:[0,-30]}).openTooltip();
  326. }else{
  327. marker.bindTooltip('<div>场站名称:' + item.stationName + '</div>'+ '<div>测风塔名称:' + item.towerName + '</div>' + '<div>经度:' + item.longitude + '</div>' + '<div>纬度:' + item.latitude + '</div>',
  328. {permanent:true,className:'infoToolTip',offset:[0,-30]}).openTooltip();
  329. }
  330. })
  331. marker.on('mouseout', function () {
  332. marker.bindTooltip().closeTooltip();
  333. })
  334. // 点击动作
  335. marker.on('click', function (e) {
  336. if(item.type === 'project'){
  337. let project = {projectId:item.projectId,equipmentNo:item.towerNo}
  338. sessionStorage.setItem("emailWindTowerInfo", JSON.stringify(project))
  339. _self.$store.dispatch('equipmentInfo/emailWindTowerInfo', JSON.stringify(project))
  340. _self.$router.push({path: "/homepage/emailResourcesInfo"})
  341. }else {
  342. let station = {stationId:item.stationId,equipmentNo:item.towerNo}
  343. sessionStorage.setItem("realWindTowerInfo", JSON.stringify(station))
  344. _self.$store.dispatch('equipmentInfo/realWindTowerInfo', JSON.stringify(station))
  345. _self.$router.push({path: "/homepage/realResourcesInfo"})
  346. }
  347. })
  348. }
  349. }
  350. /**
  351. * 加载实时气象源动画效果
  352. fetch("/js/json/wind_data/20230403_00_atmoslev_1000_mb.json")
  353. .then((res) => {
  354. return res.json();
  355. })
  356. .then((data) => {
  357. this.velocityLayer = window.BM.velocityLayer({
  358. displayValues: true,
  359. displayOptions: {
  360. velocityType: "windy",
  361. displayPosition: "topright",
  362. displayEmptyString: "没有数据",
  363. directionString: "风向",
  364. speedString: "速度",
  365. },
  366. data: data,
  367. minVelocity: 0.05,
  368. maxVelocity: 10,
  369. colorScale: ["red", "green", "yellow", "pink"],
  370. velocityScale: 0.02, // default 0.005,
  371. });
  372. this.velocityLayer.addTo(this.bMmap);
  373. });
  374. */
  375. })
  376. },
  377. //设置热力图效果
  378. setHeatMap(map) {
  379. axios.get("/img/heapmap/mean-wind-speed_rendering.tiff", {
  380. responseType: "arraybuffer",
  381. }).then((res) => {
  382. const fr = new FileReader();
  383. fr.onloadend = function (e) {
  384. var image = new Tiff({buffer: e.target.result});
  385. var imageUrl = image.toDataURL(),
  386. imageBounds = [
  387. [43.422993, 121.183134],
  388. [53.564656, 135.091461],
  389. ];
  390. window.imgOverlay=window.BM.imageOverlay(imageUrl, imageBounds).addTo(map);
  391. map.fitBounds(imageBounds);
  392. };
  393. fr.readAsArrayBuffer(new Blob([res.data]));
  394. });
  395. },
  396. //绑定事件-监听地图级别和拖动
  397. bindEvents(map){
  398. let _self = this
  399. map.on('moveend', function (e) {
  400. const c = this.getCenter();
  401. _self.center = this.getCenter()
  402. document.getElementById('move').innerHTML = '当前中心点: 纬度:' + c.lat.toFixed(5) + ',经度:' + c.lng.toFixed(5);
  403. });
  404. //添加一个缩放事件
  405. map.on('zoomend', function (e) {
  406. _self.level = this.getZoom()
  407. document.getElementById('zoom').innerHTML = '当前级别 : ' + this.getZoom();
  408. });
  409. },
  410. setData(params) {
  411. fetch(`/js/json/wind_data/20230403_00_atmoslev_` + params + `_mb.json`)
  412. .then((res) => {
  413. return res.json();
  414. })
  415. .then((data) => {
  416. this.velocityLayer.options.displayOptions.velocityType = params + `Mb`;
  417. this.velocityLayer.setData(data);
  418. });
  419. },
  420. initRegion(code) {
  421. sessionStorage.clear();
  422. sessionStorage.setItem('latlngs', JSON.stringify(this.latlngs));
  423. this.chons(code)
  424. },
  425. //加载地图方法
  426. chons(code) {
  427. fetch('/js/geojson/230000/' + code + '.geojson')
  428. .then((res) => {
  429. return res.json();
  430. })
  431. .then((data) => {
  432. this.cone = this.BM.geoJSON(data, {
  433. style: function () {
  434. return {
  435. color: '#ffffff',
  436. fillColor: 'transparent',
  437. weight: 1,
  438. fillOpacity: 1
  439. };
  440. },
  441. }).on('mouseover', function (e) {
  442. const rel = e.layer.feature.properties;
  443. e.layer.setStyle({
  444. color: '#ffffff',
  445. fillColor: 'transparent',
  446. weight: 3,
  447. fillOpacity: 1
  448. });
  449. //显示弹窗信息坐标
  450. let x = rel.center['1'];
  451. let y = rel.center['0'];
  452. let coordinate = [[x, y]];
  453. //组装参数
  454. let adcode = rel.adcode;
  455. let name = rel.name;
  456. let level = rel.level;
  457. let cont =
  458. "<div>acode :" + adcode + "</div>" +
  459. "<div>name <span style='margin-left: 2px'>:</span>" + name + "</div>" +
  460. "<div>level <span style='margin-left: 7px'>:</span>" + level + "</div>";
  461. //显示弹窗
  462. if (!e.layer.getPopup()) {
  463. e.layer.bindPopup(cont);
  464. }
  465. e.layer.openPopup();
  466. }).on('mouseout', function (e) {
  467. e.layer.setStyle({
  468. color: '#ffffff',
  469. fillColor: 'transparent',
  470. weight: 1,
  471. fillOpacity: 1
  472. });
  473. // 点击地图区域向下钻取
  474. // }).on('click', (e) => {
  475. // const rel = e.layer.feature.properties;
  476. // const zb = e.layer._bounds;
  477. // if (code === rel.adcode) {
  478. // return false;
  479. // } else {
  480. // //定时器
  481. // clearTimeout(this.mTime);
  482. // this.mTime = setTimeout(() => {
  483. // //重新加载
  484. // this.chons(rel.adcode);
  485. // this.cone.remove();
  486. // //临时缓存
  487. // sessionStorage.setItem('diqu', JSON.stringify(rel.acroutes));
  488. // const latadd = sessionStorage.getItem('latlngs');
  489. // const lataddp = JSON.parse(latadd);
  490. // lataddp.push([[zb._northEast.lat, zb._northEast.lng], [zb._southWest.lat, zb._southWest.lng]]);
  491. // sessionStorage.setItem('latlngs', JSON.stringify(lataddp));
  492. // if (lataddp.slice(-1).length !== 0) {
  493. // this.bMap.fitBounds(lataddp.slice(-1));
  494. // }
  495. // }, 300);
  496. // }
  497. }).addTo(this.bMap);
  498. })
  499. }
  500. }
  501. }
  502. </script>
  503. <style>
  504. .infoToolTip{
  505. color: white;
  506. background: rgba(0, 133, 212, 0.75);
  507. border: .5px solid #0085d4;
  508. }
  509. .my_default_tooltip{
  510. color: transparent;
  511. background: transparent;
  512. border: none;
  513. /*font-size: 18px;*/
  514. }
  515. .my_default_tooltip::before{
  516. display: none;
  517. }
  518. </style>
  519. <style scoped>
  520. #map {
  521. width: 100%;
  522. height: calc(90vh);
  523. }
  524. .bigemap-popup-content-wrapper, .map-legends, .map-tooltip {
  525. border-radius: 8px;
  526. box-shadow: 5px 5px 5px rgb(0 0 0);
  527. }
  528. </style>