amapnow.vue 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843
  1. <template>
  2. <div class="map-wrap">
  3. <div id="container" tabindex="0"></div>
  4. <div id="mask"></div>
  5. <div class="yun-wrap">
  6. <img class="yun yun1" src="../assets/img/云1.png" alt />
  7. </div>
  8. <div class="yun-wrap">
  9. <img class="yun yun2" src="../assets/img/云2.png" alt />
  10. </div>
  11. <div class="yun-wrap">
  12. <img class="yun yun3" src="../assets/img/云3.png" alt />
  13. </div>
  14. <el-dialog title="查看图片" :modal="false" :visible.sync="imgDialogVisible" width="40%">
  15. <img width="100%" style="height:580px" :src="dialogImageUrl" alt />
  16. </el-dialog>
  17. </div>
  18. </template>
  19. <script>
  20. import AMapLoader from '@amap/amap-jsapi-loader';
  21. import { mapMutations, mapState, mapGetters } from 'vuex';
  22. import {
  23. smallClassMap,
  24. rightScrollData,
  25. forestSample,
  26. alarmDataApi,
  27. financeBasePlant,
  28. financeBaseDetail,
  29. farmInfo,
  30. smallClassDetail,
  31. treePlant
  32. } from '@/service/index.js';
  33. import axios from 'axios';
  34. export default {
  35. name: 'Mapview',
  36. data() {
  37. return {
  38. imgDialogVisible: false,
  39. dialogImageUrl: null,
  40. AMap: null,
  41. map: null,
  42. lngLat: [106.628201, 26.646694],
  43. adName: '贵州省',
  44. mapLevel: 'province',
  45. adcode: '贵州省',
  46. parentId: '520000',
  47. province: '',
  48. zoom: 8,
  49. districtExplorer: null,
  50. tipMarker: null,
  51. $tipMarkerContent: null,
  52. currentAreaNode: null,
  53. cityMarkerArr: [],
  54. eventMarker: null,
  55. streetMarkerArr: [],
  56. leftPage: 'forest',
  57. putPolygonData: [],
  58. //乡镇边界
  59. townPolygons: [],
  60. // 基地详情
  61. baseMarkers: [],
  62. // 小班详情
  63. smallMarkers: [],
  64. // 时间详情
  65. eventMarkers: [],
  66. // 林场
  67. treesMarkerArr: [],
  68. // 小班边界
  69. smallClassMapArr: [],
  70. // 作物
  71. economicsArr: [],
  72. // 基地定位
  73. baseMarkerArr: [],
  74. // 时间信息
  75. eventMarkersArr: [],
  76. // 样地、小班
  77. forestMarkerArr: [],
  78. // 样地号
  79. smallClassNArr: [],
  80. // 森林资源小班边界
  81. smallClassPolygonArr: [],
  82. // 林木结构小班边界
  83. treesPolygonArr: [],
  84. townPolygonArr: [],
  85. economicsArr: [],
  86. selectData: {},
  87. districtData: {},
  88. streetData: {}
  89. };
  90. },
  91. watch: {
  92. '$store.state.addr.parentId': {
  93. handler(val) {
  94. // 加载小班边界
  95. this.getSmallClass();
  96. this.parentId = val;
  97. if (this.$store.state.addr.mapLevel == 'street') {
  98. this.parentId = val.substring(0, 6);
  99. if (this.map) {
  100. this.switch2AreaNode(
  101. this.parentId,
  102. this.$store.state.addr.mapLevel,
  103. this.$store.state.addr.selectCity,
  104. this.leftPage
  105. );
  106. }
  107. }
  108. if (this.$store.state.addr.mapLevel != 'street') {
  109. this.selectData = this.$store.state.addr.selectCity;
  110. this.districtData = this.$store.state.addr.selectDistrict;
  111. this.streetData = this.$store.state.addr.selectStreet;
  112. if (this.map) {
  113. this.switch2AreaNode(
  114. this.parentId,
  115. this.$store.state.addr.mapLevel,
  116. this.$store.state.addr.selectCity,
  117. this.leftPage
  118. );
  119. }
  120. if (
  121. this.polygon ||
  122. this.streetMarkerArr ||
  123. this.townPolygons ||
  124. this.forestMarkerArr ||
  125. this.smallClassNArr ||
  126. this.forestMarkerArr ||
  127. this.townPolygonArr
  128. ) {
  129. this.map.remove(this.polygon);
  130. this.map.remove(this.streetMarkerArr);
  131. this.map.remove(this.townPolygons);
  132. this.map.remove(this.forestMarkerArr);
  133. this.map.remove(this.smallClassNArr);
  134. this.map.remove(this.forestMarkerArr);
  135. this.map.remove(this.townPolygonArr);
  136. }
  137. }
  138. }
  139. },
  140. '$store.state.addr.selectStreet'(val) {
  141. if (val.label && val.value && val.areaId) {
  142. this.map.remove(this.polygon);
  143. let labelTown = val.label;
  144. this.map.setCity(labelTown);
  145. if (this.leftPage === 'forest') {
  146. this.addForestPolygon(this.smallClassMapArr);
  147. this.getForestSample(this.leftPage);
  148. } else if (this.leftPage === 'treeSpecies') {
  149. this.addTreeSpeciesPolygon(this.smallClassMapArr);
  150. this.getRightScrollData(this.leftPage);
  151. } else if (this.leftPage === 'economics') {
  152. this.getEconomics(this.smallClassMapArr);
  153. } else if (this.leftPage === 'event') {
  154. this.getEven();
  155. }
  156. }
  157. },
  158. '$store.state.addr.page': {
  159. handler(val) {
  160. this.leftPage = val;
  161. if (!this.parentId) {
  162. this.parentId = '520000';
  163. this.$store.state.addr.parentName = '贵州省';
  164. }
  165. if (this.parentId) {
  166. // this.getSmallClass();
  167. this.mapPolygon();
  168. }
  169. if (val != 'forest') {
  170. this.map.remove(this.forestMarkerArr);
  171. this.map.remove(this.smallClassNArr);
  172. this.map.remove(this.smallClassPolygonArr);
  173. }
  174. if (val != 'treeSpecies') {
  175. this.map.remove(this.forestMarkerArr);
  176. this.map.remove(this.treesPolygonArr);
  177. }
  178. if (val != 'economics') {
  179. this.map.remove(this.economicsArr);
  180. this.map.remove(this.baseMarkerArr);
  181. }
  182. if (val != 'event') {
  183. this.map.remove(this.eventMarkersArr);
  184. }
  185. }
  186. },
  187. '$store.state.addr.smallClassSearch': {
  188. deep: true,
  189. immediate: true,
  190. handler: function (val, oldVal) {
  191. let _this = this;
  192. if (val) {
  193. if (val.longitude && val.latitude && !val.name) {
  194. let lanLatArr = [val.longitude, val.latitude];
  195. let imgList = [];
  196. if (val.imageList.length > 0) {
  197. val.imageList.forEach((element) => {
  198. imgList.push(`<img id="markerLabel" src="${element.image}"/>`);
  199. });
  200. } else {
  201. imgList.push('暂无图片');
  202. }
  203. this.imgClick();
  204. let smallLabel =
  205. "<div class='info-details'>" +
  206. "<h5 class='marker-title'>" +
  207. val.countyName +
  208. '-' +
  209. val.smallNumber +
  210. '</h5>' +
  211. "<div class='marker-content'>" +
  212. '<div>' +
  213. '<p>小班号:' +
  214. val.smallNumber +
  215. '</p>' +
  216. '<p>样地数:' +
  217. val.sampleCount +
  218. '</p>' +
  219. '<p>小班蓄积量:' +
  220. val.smallClassStock +
  221. '(立方米)' +
  222. '</p>' +
  223. '<p>小班占地面积:' +
  224. val.landArea +
  225. '(亩)' +
  226. '</p>' +
  227. '<p>小班树种组成:' +
  228. val.treeComp +
  229. '</p>' +
  230. '<p>地类:' +
  231. val.landType +
  232. '</p>' +
  233. '<p>林地权属:' +
  234. val.landOwner +
  235. '</p>' +
  236. '<p>林木权属:' +
  237. val.forestOwner +
  238. '</p>' +
  239. '<p>林种:' +
  240. val.forestClass +
  241. '</p>' +
  242. '<p>树种结构:' +
  243. val.treeStruct +
  244. '</p>' +
  245. '</div>' +
  246. '<div>' +
  247. '<p>起源:' +
  248. val.origin +
  249. '</p>' +
  250. '<p>优势树种:' +
  251. val.superTree +
  252. '</p>' +
  253. '<p>主要灌木名称:' +
  254. val.shrubName +
  255. '</p>' +
  256. '<p>地貌:' +
  257. val.landForm +
  258. '</p>' +
  259. '<p>海拔:' +
  260. val.altitude +
  261. '</p>' +
  262. '<p>坡位:' +
  263. val.slopePosit +
  264. '</p>' +
  265. '<p>坡向:' +
  266. val.slopeDirect +
  267. '</p>' +
  268. '<p>坡形:' +
  269. val.slopeForm +
  270. '</p>' +
  271. '<p>坡度:' +
  272. val.slope +
  273. '</p>' +
  274. '<p>森林健康度:' +
  275. val.forestHealth +
  276. '</p>' +
  277. '</div>' +
  278. '</div>' +
  279. '<div class="imgList">' +
  280. "<span class='marker-span'>图片:</span>" +
  281. '<div class="marker-imgs">' +
  282. imgList +
  283. '</div>' +
  284. '</div>' +
  285. '</div>';
  286. this.smallMarker = new AMap.Marker({
  287. map: this.map,
  288. position: lanLatArr,
  289. icon: require('@/assets/img/small-marker.png'),
  290. anchor: 'bottom-center',
  291. offset: new AMap.Pixel(0, 0),
  292. zIndex: 9999
  293. });
  294. this.smallMarker.setLabel({
  295. direction: 'right',
  296. offset: new AMap.Pixel(-230, -160), //设置文本标注偏移量
  297. content: smallLabel //设置文本标注内容
  298. });
  299. this.smallMarkers.push(_this.smallMarker);
  300. } else if (val.name == false && this.smallMarker) {
  301. this.map.on('rightclick', function (e) {
  302. _this.map.remove(_this.smallMarkers);
  303. });
  304. }
  305. }
  306. }
  307. },
  308. '$store.state.addr.eventData': {
  309. deep: true,
  310. immediate: true,
  311. handler: function (val, oldVal) {
  312. let _this = this;
  313. if (val) {
  314. if (val.longitude && val.latitude && !val.name) {
  315. let lanLatArr = [val.longitude, val.latitude];
  316. let baseIcon = '';
  317. let fireIcon = require('@/assets/img/fire.png');
  318. let cutTreeIcon = require('@/assets/img/cutTree.png');
  319. let insectpestIcon = require('@/assets/img/insectpest.png');
  320. if (val.eventType == 1) {
  321. val.eventContLabel = '火灾';
  322. baseIcon = fireIcon;
  323. } else if (val.eventType == 2) {
  324. val.eventContLabel = '砍伐';
  325. baseIcon = cutTreeIcon;
  326. } else if (val.eventType == 3) {
  327. val.eventContLabel = '病虫害';
  328. baseIcon = insectpestIcon;
  329. } else if (val.eventType == 4) {
  330. val.eventContLabel = '偷盗林木';
  331. }
  332. let treeSmallLabel =
  333. "<div class='info-small'>" +
  334. "<h5 class='marker-title'>历史事件" +
  335. '</h5>' +
  336. "<div class='marker-content'>" +
  337. '<p>事件类型:' +
  338. val.eventContLabel +
  339. '</p>' +
  340. '<p>上报时间:' +
  341. val.createTime +
  342. '</p>' +
  343. '<p>上报人:' +
  344. val.createBy +
  345. '</p>' +
  346. '<p>位置:' +
  347. val.cityName +
  348. val.countyName +
  349. val.townName +
  350. val.villageName +
  351. '</p>' +
  352. '</div>' +
  353. '</div>';
  354. this.eventMarker = new AMap.Marker({
  355. map: this.map,
  356. position: lanLatArr,
  357. icon: baseIcon,
  358. anchor: 'bottom-center',
  359. offset: new AMap.Pixel(0, 0),
  360. zIndex: 9999
  361. });
  362. this.eventMarker.setLabel({
  363. direction: 'top',
  364. offset: new AMap.Pixel(-10, 0), //设置文本标注偏移量
  365. content: treeSmallLabel //设置文本标注内容
  366. });
  367. this.eventMarkers.push(this.eventMarker);
  368. // this.map.add(this.eventMarker);
  369. } else if (val.name == false && this.eventMarker) {
  370. this.map.on('rightclick', function (e) {
  371. _this.map.remove(_this.eventMarkers);
  372. });
  373. }
  374. }
  375. }
  376. },
  377. '$store.state.addr.baseDetail': {
  378. deep: true,
  379. immediate: true,
  380. handler: function (val, oldVal) {
  381. let _this = this;
  382. if (val) {
  383. if (val.baseLongitude && val.baseLatitude && !val.name) {
  384. let lanLatArr = [val.baseLongitude, val.baseLatitude];
  385. let treeSmallLabel =
  386. "<div class='info-small'>" +
  387. "<h5 class='marker-title'>" +
  388. val.baseName +
  389. '</h5>' +
  390. "<div class='marker-content'>" +
  391. '<p>基地名称:' +
  392. val.baseName +
  393. '</p>' +
  394. '<p>种植/养殖/加工作物:' +
  395. val.cropName +
  396. '</p>' +
  397. '<p>占地面积:' +
  398. val.baseArea +
  399. '亩' +
  400. '</p>' +
  401. '<p>位置:' +
  402. val.cityName +
  403. val.countyName +
  404. val.townName +
  405. '</p>' +
  406. '</div>' +
  407. '</div>';
  408. this.baseMarker = new AMap.Marker({
  409. map: this.map,
  410. position: lanLatArr,
  411. icon: require('@/assets/img/small-marker.png'),
  412. anchor: 'bottom-center',
  413. offset: new AMap.Pixel(0, 0),
  414. zIndex: 9999
  415. });
  416. this.baseMarker.setLabel({
  417. direction: 'top',
  418. offset: new AMap.Pixel(0, 0), //设置文本标注偏移量
  419. content: treeSmallLabel //设置文本标注内容
  420. });
  421. this.baseMarkers.push(_this.baseMarker);
  422. } else if (val.name == false && this.baseMarker) {
  423. this.map.on('rightclick', function (e) {
  424. _this.map.remove(_this.baseMarkers);
  425. });
  426. }
  427. }
  428. }
  429. }
  430. },
  431. computed: {
  432. ...mapGetters(['vuexCityList', 'vuexDistrictList', 'vuexStreetList']),
  433. ...mapState(['selectCity', 'selectDistrict', 'selectStreet'])
  434. },
  435. created() {
  436. this.getTreePlant();
  437. },
  438. mounted() {
  439. this.initAMap();
  440. // 加载小班边界
  441. this.getSmallClass();
  442. },
  443. methods: {
  444. ...mapMutations([
  445. 'changeSelectCity',
  446. 'changeSelectDistrict',
  447. 'changeSelectStreet',
  448. 'changeSelectAddr'
  449. ]),
  450. initAMap() {
  451. window._AMapSecurityConfig = {
  452. securityJsCode: 'e6666dfe93e7d3c6f3a5dc35cad6befb' // 密钥
  453. };
  454. let _this = this;
  455. AMapLoader.load({
  456. key: 'f79d862df9288710e3dce6591af9dff1', //设置您的key
  457. version: '2.0',
  458. plugins: [
  459. 'AMap.ToolBar',
  460. 'AMap.Driving',
  461. 'AMap.DistrictSearch',
  462. 'AMap.MapboxVectorTileLayer'
  463. ],
  464. Loca: {
  465. version: '2.0'
  466. },
  467. AMapUI: {
  468. version: '1.1',
  469. plugins: ['overlay/SimpleMarker']
  470. },
  471. features: ['road', 'bg', 'building']
  472. }).then((AMap) => {
  473. _this.AMap = AMap;
  474. _this.map = new AMap.Map('container', {
  475. viewMode: '3D',
  476. zoom: _this.zoom,
  477. center: _this.lngLat,
  478. pitch: 45,
  479. terrain: true,
  480. features: ['road', 'bg', 'building'],
  481. layers: [new AMap.TileLayer.Satellite()]
  482. });
  483. AMapUI.load(
  484. ['ui/geo/DistrictExplorer', 'ui/geo/DistrictCluster', 'lib/$'],
  485. function (DistrictExplorer, DistrictCluster, $) {
  486. window.DistrictCluster = DistrictCluster;
  487. _this.loadMapData(DistrictExplorer, $);
  488. }
  489. );
  490. let wms = new AMap.TileLayer.WMTS({
  491. url: 'http://t4.tianditu.gov.cn/img_w/wmts',
  492. blend: false,
  493. tileSize: 256,
  494. params: {
  495. Layer: 'img',
  496. Version: '1.0.0',
  497. Format: 'tiles',
  498. TileMatrixSet: 'w',
  499. STYLE: 'default',
  500. tk: '064688075f565aa463866b915c378e00'
  501. }
  502. });
  503. wms.setMap(_this.map);
  504. this.map.on('mousewheel', (e) => {
  505. var zoom = this.map.getZoom(); //获取当前地图级别
  506. if (
  507. zoom > '10.5' &&
  508. zoom < '11' &&
  509. this.$store.state.addr.mapLevel == 'street'
  510. ) {
  511. if (this.districtData.value) {
  512. let districtCode = this.districtData.value.substring(0, 6);
  513. this.$store.dispatch('searchArea', {
  514. parentId: districtCode,
  515. name: this.districtData.label,
  516. mapLevel: 'district'
  517. });
  518. }
  519. }
  520. if (
  521. zoom > '9' &&
  522. zoom < '9.5' &&
  523. this.$store.state.addr.mapLevel == 'district'
  524. ) {
  525. if (this.selectData.value) {
  526. let districtCode = this.selectData.value.substring(0, 6);
  527. this.$store.dispatch('searchArea', {
  528. parentId: districtCode,
  529. name: this.selectData.label,
  530. mapLevel: 'city'
  531. });
  532. }
  533. }
  534. if (
  535. zoom > '7.6' &&
  536. zoom < '7.9' &&
  537. this.$store.state.addr.mapLevel == 'city'
  538. ) {
  539. this.$store.dispatch('searchArea', {
  540. parentId: '520000',
  541. name: '贵州省',
  542. mapLevel: 'province'
  543. });
  544. }
  545. });
  546. });
  547. },
  548. loadMapData(DistrictExplorer, $) {
  549. let that = this;
  550. //创建一个实例
  551. that.districtExplorer = window.districtExplorer = new DistrictExplorer({
  552. eventSupport: true, //打开事件支持
  553. bubble: true,
  554. map: that.map
  555. });
  556. //当前聚焦的区域
  557. this.$tipMarkerContent = $('<div class="tipMarker top"></div>');
  558. // eslint-disable-next-line no-undef
  559. this.tipMarker = new AMap.Marker({
  560. content: this.$tipMarkerContent.get(0),
  561. offset: new AMap.Pixel(0, 0),
  562. bubble: true
  563. });
  564. //监听feature的hover事件
  565. this.districtExplorer.on(
  566. 'featureMouseout featureMouseover',
  567. (e, feature) => {
  568. this.toggleHoverFeature(
  569. feature,
  570. e.type === 'featureMouseover',
  571. e.originalEvent ? e.originalEvent.lnglat : null
  572. );
  573. }
  574. );
  575. //监听鼠标在feature上滑动
  576. this.districtExplorer.on('featureMousemove', (e) => {
  577. //更新提示位置
  578. this.tipMarker.setPosition(e.originalEvent.lnglat);
  579. });
  580. let adName = that.adName; //贵州省
  581. let mapLevel = that.mapLevel;
  582. let adcode = '520000';
  583. //feature被点击
  584. this.districtExplorer.on('featureClick', (e, feature) => {
  585. const props = feature.properties;
  586. if (props.subFeatureIndex != null) {
  587. adName = props.name;
  588. adcode = props.adcode;
  589. mapLevel = props.level;
  590. for (let item of this.forestFarmData) {
  591. if (props.name == item.cityName || props.name == item.countyName) {
  592. mapLevel = props.level;
  593. adName = props.name;
  594. this.$store.dispatch('searchArea', {
  595. parentId: props.adcode,
  596. name: props.name,
  597. mapLevel: props.level
  598. });
  599. let valCode = props.adcode + '000000';
  600. let areaId = '';
  601. this.vuexCityList.forEach((item) => {
  602. if (valCode == item.areaCode) {
  603. areaId = item.areaId;
  604. }
  605. });
  606. this.vuexDistrictList.forEach((item) => {
  607. if (valCode == item.areaCode) {
  608. areaId = item.areaId;
  609. }
  610. });
  611. if (props.level == 'city') {
  612. this.changeSelectCity({
  613. value: valCode,
  614. label: props.name,
  615. areaId: areaId
  616. });
  617. } else if (props.level == 'district') {
  618. this.changeSelectDistrict({
  619. value: valCode,
  620. label: props.name,
  621. areaId: areaId
  622. });
  623. }
  624. this.map.remove(this.treesMarkerArr);
  625. }
  626. }
  627. }
  628. });
  629. this.switch2AreaNode(adcode);
  630. },
  631. //根据Hover状态设置相关样式
  632. toggleHoverFeature(feature, isHover, position) {
  633. if (feature.properties.subFeatureIndex != null) {
  634. this.tipMarker.setMap(isHover ? this.map : null);
  635. if (!feature) {
  636. return;
  637. }
  638. const props = feature.properties;
  639. if (isHover) {
  640. //更新提示内容
  641. this.$tipMarkerContent.html(props.name);
  642. //更新位置
  643. this.tipMarker.setPosition(position || props.center);
  644. }
  645. //更新相关多边形的样式
  646. const polys = this.districtExplorer.findFeaturePolygonsByAdcode(
  647. props.adcode
  648. );
  649. polys.forEach((elemnt) => {
  650. elemnt.setOptions({
  651. fillColor: '#0dbc79',
  652. fillOpacity: isHover ? 0.5 : 0
  653. });
  654. });
  655. }
  656. },
  657. //绘制某个区域的边界
  658. renderAreaPolygons(areaNode) {
  659. let _this = this;
  660. //更新地图视野
  661. if (this.$store.state.addr.mapLevel != 'street') {
  662. this.map.setBounds(areaNode.getBounds(), null, null, false);
  663. }
  664. // 加载相关标识
  665. this.mapPolygon();
  666. //清除已有的绘制内容
  667. this.districtExplorer.clearFeaturePolygons();
  668. // 清除已绘制的省市县名称
  669. this.map.remove(this.cityMarkerArr);
  670. //绘制子区域
  671. this.districtExplorer.renderSubFeatures(areaNode, () => {
  672. return {
  673. cursor: 'default',
  674. bubble: true,
  675. strokeColor: 'yellow', //线颜色
  676. strokeOpacity: 1, //线透明度
  677. strokeWeight: 2, //线宽
  678. fillOpacity: 0 //填充透明度
  679. };
  680. });
  681. //绘制父区域
  682. this.districtExplorer.renderParentFeature(areaNode, {
  683. cursor: 'default',
  684. bubble: true,
  685. strokeColor: '#00eeff', //线颜色
  686. strokeOpacity: 1, //线透明度
  687. strokeWeight: 2, //线宽
  688. fillOpacity: 0 //填充透明度
  689. });
  690. // 绘制父级蒙版
  691. let areaPolygon = areaNode.getParentFeature();
  692. let outer = [
  693. new AMap.LngLat(-360, 90, true),
  694. new AMap.LngLat(-360, -90, true),
  695. new AMap.LngLat(360, -90, true),
  696. new AMap.LngLat(360, 90, true)
  697. ];
  698. let areaPolygonArr = [];
  699. areaPolygon.geometry.coordinates.forEach((element) => {
  700. areaPolygonArr.push(element[0]);
  701. });
  702. let holes = areaPolygonArr;
  703. let pathArray = [outer];
  704. pathArray.push.apply(pathArray, holes);
  705. this.polygon = new AMap.Polygon({
  706. pathL: pathArray,
  707. map: this.map,
  708. strokeColor: '#00eeff',
  709. strokeWeight: 1,
  710. fillColor: '#0c1b05', // 遮罩背景色
  711. fillOpacity: 0.8,
  712. height: 10000
  713. });
  714. this.polygon.setPath(pathArray);
  715. if (areaPolygon.properties.level != 'district') {
  716. this.setMarker();
  717. } else {
  718. this.map.remove(this.treesMarkerArr);
  719. }
  720. //查询乡镇 标识
  721. if (areaPolygon.properties.level == 'district') {
  722. if (this.$store.state.addr.mapLevel != 'street') {
  723. this.getrjx(areaPolygon.properties.name);
  724. }
  725. AMap.plugin(['AMap.DistrictSearch'], function () {
  726. let district = new AMap.DistrictSearch({
  727. // 返回行政区边界坐标等具体信息
  728. extensions: 'all',
  729. // 设置查询行政区级别为 区 (district)
  730. level: areaPolygon.properties.level,
  731. // 显示下级行政区级数,1表示返回下一级行政区
  732. subdistrict: 1
  733. });
  734. let areaCode = areaPolygon.properties.name;
  735. district.search(areaCode, function (status, result) {
  736. let streetArr = result.districtList[0].districtList;
  737. for (let elementLs in streetArr) {
  738. _this.streetMarker = new AMap.Text({
  739. //c城市指示标
  740. text: streetArr[elementLs].name,
  741. zIndex: 1,
  742. map: _this.map,
  743. anchor: 'center', // 设置文本标记锚点
  744. style: {
  745. padding: '0px 6px',
  746. color: '#fff',
  747. border: 'none',
  748. fontSize: '12px',
  749. 'background-color': '#E6810C'
  750. },
  751. position: [
  752. streetArr[elementLs].center.lng,
  753. streetArr[elementLs].center.lat
  754. ]
  755. });
  756. _this.streetMarkerArr.push(_this.streetMarker);
  757. }
  758. });
  759. });
  760. }
  761. // 添加城市标识
  762. let cityArr = areaNode.getSubFeatures();
  763. if (cityArr) {
  764. for (let i = 0; i < cityArr.length; i++) {
  765. this.cityMarker = new AMap.Text({
  766. //c城市指示标
  767. text: cityArr[i].properties.name,
  768. zIndex: 1,
  769. map: this.map,
  770. anchor: 'center', // 设置文本标记锚点
  771. style: {
  772. padding: '0px 6px',
  773. color: '#fff',
  774. border: 'none',
  775. fontSize: '12px',
  776. 'background-color': '#E6810C'
  777. },
  778. position: cityArr[i].properties.centroid
  779. });
  780. this.cityMarkerArr.push(this.cityMarker);
  781. }
  782. }
  783. },
  784. //切换区域后刷新显示内容
  785. refreshAreaNode(areaNode) {
  786. this.districtExplorer.setHoverFeature(null);
  787. this.renderAreaPolygons(areaNode);
  788. },
  789. //切换区域
  790. switch2AreaNode(adcode, mapLevel, selectStreet, page, callback) {
  791. // if (
  792. // this.currentAreaNode &&
  793. // '' + this.currentAreaNode.getAdcode() === '' + adcode
  794. // ) {
  795. // return;
  796. // }
  797. this.loadAreaNode(adcode, (error, areaNode) => {
  798. if (error) {
  799. if (callback) {
  800. callback(error);
  801. }
  802. return;
  803. }
  804. this.currentAreaNode = areaNode;
  805. //设置当前使用的定位用节点
  806. this.districtExplorer.setAreaNodesForLocating([this.currentAreaNode]);
  807. this.refreshAreaNode(areaNode);
  808. if (callback) {
  809. callback(null, areaNode);
  810. }
  811. });
  812. },
  813. // 加载区域
  814. loadAreaNode(adcode, callback) {
  815. this.districtExplorer.loadAreaNode(adcode, (error, areaNode) => {
  816. if (error) {
  817. if (callback) {
  818. callback(error);
  819. }
  820. window.console.error(error);
  821. return;
  822. }
  823. if (callback) {
  824. callback(null, areaNode);
  825. }
  826. });
  827. },
  828. // 加载林场
  829. setMarker() {
  830. this.forestFarmData = [];
  831. if (this.treesMarkerArr.length > 0) {
  832. this.map.remove(this.treesMarkerArr);
  833. }
  834. farmInfo().then((res) => {
  835. this.forestFarmData = res.rows;
  836. let parentMarker = require('@/assets/img/pre-marker.png');
  837. this.forestFarmData.forEach((item) => {
  838. let selectCity = this.$store.state.addr.selectCity.label;
  839. switch (this.$store.state.addr.selectCity.label) {
  840. case '黔西南州':
  841. selectCity = '黔西南布依族苗族自治州';
  842. break;
  843. case '黔东南州':
  844. selectCity = '黔东南苗族侗族自治州';
  845. break;
  846. case '黔南州':
  847. selectCity = '黔南布依族苗族自治州';
  848. break;
  849. }
  850. if (this.$store.state.addr.selectCity.label) {
  851. if (selectCity == item.cityName) {
  852. let lngLat = [item.longitude, item.latitude];
  853. this.treesMarker = new AMap.Marker({
  854. map: this.map,
  855. position: lngLat,
  856. icon: parentMarker,
  857. anchor: 'bottom-center',
  858. offset: new AMap.Pixel(0, 0)
  859. });
  860. this.treesMarker.setLabel({
  861. direction: 'bottom',
  862. offset: new AMap.Pixel(0, 0), //设置文本标注偏移量
  863. content: `<div>${item.forestName}</div>` //设置文本标注内容
  864. });
  865. this.treesMarkerArr.push(this.treesMarker);
  866. }
  867. } else {
  868. let lngLat = [item.longitude, item.latitude];
  869. this.treesMarker = new AMap.Marker({
  870. map: this.map,
  871. position: lngLat,
  872. icon: parentMarker,
  873. anchor: 'bottom-center',
  874. offset: new AMap.Pixel(0, 0)
  875. });
  876. this.treesMarker.setLabel({
  877. direction: 'bottom',
  878. offset: new AMap.Pixel(0, 0), //设置文本标注偏移量
  879. content: `<div>${item.forestName}</div>` //设置文本标注内容
  880. });
  881. this.treesMarkerArr.push(this.treesMarker);
  882. }
  883. });
  884. });
  885. },
  886. // 加载乡镇边界
  887. getrjx(cityName) {
  888. if (cityName == '榕江县') {
  889. axios.get('/static/rongjangintown.json').then((res) => {
  890. this.putPolygonData = res.data.features;
  891. this.putPolygon();
  892. });
  893. } else if (cityName == '清镇市') {
  894. axios.get('/static/qingzhenzhen.json').then((res) => {
  895. this.putPolygonData = res.data.features;
  896. this.putPolygon();
  897. });
  898. }
  899. },
  900. putPolygon() {
  901. let that = this;
  902. this.putPolygonData.forEach((element) => {
  903. this.boundaryPolygon = new AMap.Polygon({
  904. map: that.map,
  905. path: element.geometry.coordinates,
  906. strokeOpacity: 1,
  907. fillOpacity: 0,
  908. strokeColor: 'yellow',
  909. strokeWeight: 1,
  910. zIndex: 999,
  911. cursor: 'pointer'
  912. });
  913. that.townPolygons.push(this.boundaryPolygon);
  914. this.boundaryPolygon.on('click', (e) => {
  915. let centerLanLatArr = [e.lnglat.lng, e.lnglat.lat];
  916. that.map.remove(that.townPolygons);
  917. // that.districtExplorer.clearFeaturePolygons();
  918. let valCode = element.properties.XIANG;
  919. let areaId = '';
  920. let label = element.properties.XIANG_NAME;
  921. this.vuexStreetList.forEach((item) => {
  922. if (valCode == item.areaCode) {
  923. areaId = item.areaId;
  924. }
  925. });
  926. this.changeSelectStreet({
  927. value: valCode,
  928. label: label,
  929. areaId: areaId
  930. });
  931. this.changeSelectAddr('street');
  932. this.$store.dispatch('searchArea', {
  933. parentId: valCode,
  934. name: label,
  935. mapLevel: 'street'
  936. });
  937. let townPolygon = new AMap.Polygon({
  938. map: that.map,
  939. path: element.geometry.coordinates,
  940. strokeColor: 'yellow',
  941. strokeWeight: 3,
  942. fillOpacity: 0
  943. });
  944. this.townPolygonArr.push(townPolygon);
  945. that.map.setZoomAndCenter(14, centerLanLatArr, false, 13);
  946. });
  947. that.boundaryPolygon.on('rightclick', function (e) {
  948. if (that.smallMarkers || that.baseMarkers || that.eventMarkers) {
  949. that.map.remove(that.smallMarkers);
  950. that.map.remove(that.baseMarkers);
  951. that.map.remove(that.eventMarkers);
  952. }
  953. });
  954. });
  955. },
  956. getSmallClass() {
  957. this.smallClassMapArr = [];
  958. let params = {
  959. cityId: this.$store.state.addr.selectCity.areaId,
  960. countyId: this.$store.state.addr.selectDistrict.areaId
  961. // townId: this.$store.state.addr.selectStreet.areaId
  962. };
  963. if (this.smallClassPolygonArr.length > 0) {
  964. this.map.remove(this.smallClassPolygonArr);
  965. }
  966. if (this.treesPolygonArr.length > 0) {
  967. this.map.remove(this.treesPolygonArr);
  968. }
  969. if (this.economicsArr.length > 0) {
  970. this.map.remove(this.economicsArr);
  971. }
  972. smallClassMap(params).then((res) => {
  973. console.log(res);
  974. if (res.code == 200) {
  975. this.smallClassMapArr = res.rows;
  976. if (this.leftPage === 'forest') {
  977. this.addForestPolygon(this.smallClassMapArr);
  978. } else if (this.leftPage === 'treeSpecies') {
  979. this.addTreeSpeciesPolygon();
  980. } else if (this.leftPage === 'economics') {
  981. this.getEconomics(this.smallClassMapArr);
  982. }
  983. }
  984. });
  985. },
  986. mapPolygon() {
  987. if (this.smallClassMapArr) {
  988. if (this.leftPage === 'forest') {
  989. this.addForestPolygon(this.smallClassMapArr);
  990. if (
  991. this.$store.state.addr.mapLevel == 'district' ||
  992. this.$store.state.addr.mapLevel == 'street'
  993. ) {
  994. this.getForestSample(this.leftPage);
  995. }
  996. } else if (this.leftPage === 'treeSpecies') {
  997. this.addTreeSpeciesPolygon();
  998. if (
  999. this.$store.state.addr.mapLevel == 'district' ||
  1000. this.$store.state.addr.mapLevel == 'street'
  1001. ) {
  1002. this.getRightScrollData(this.leftPage);
  1003. }
  1004. } else if (this.leftPage === 'economics') {
  1005. this.getEconomics(this.smallClassMapArr);
  1006. } else if (this.leftPage === 'event') {
  1007. this.getEven();
  1008. }
  1009. }
  1010. },
  1011. addForestPolygon(smallClassMapArr) {
  1012. let that = this;
  1013. if (smallClassMapArr) {
  1014. smallClassMapArr.forEach((item) => {
  1015. let polyData = JSON.parse(item.mapInfo);
  1016. for (let elementLs in polyData.features) {
  1017. let smallClassPolygon = new AMap.Polygon({
  1018. map: that.map,
  1019. path: polyData.features[elementLs].geometry.coordinates,
  1020. strokeOpacity: 1,
  1021. fillOpacity: 0,
  1022. strokeColor: 'red',
  1023. strokeWeight: 2,
  1024. zIndex: 999,
  1025. cursor: 'pointer',
  1026. fillColor: ''
  1027. });
  1028. this.smallClassPolygonArr.push(smallClassPolygon);
  1029. if (item.longitude && item.latitude) {
  1030. var lanLatArr = [];
  1031. lanLatArr = [item.longitude, item.latitude];
  1032. if (
  1033. this.$store.state.addr.mapLevel == 'district' ||
  1034. this.$store.state.addr.mapLevel == 'street'
  1035. ) {
  1036. this.smallClassN = new AMap.Text({
  1037. map: this.map,
  1038. position: lanLatArr,
  1039. text: item.smallNumber,
  1040. anchor: 'bottom-center',
  1041. offset: new AMap.Pixel(0, 8),
  1042. style: {
  1043. 'background-color': 'transparent',
  1044. border: 'none',
  1045. color: '#05dfff',
  1046. fontSize: '12px'
  1047. }
  1048. });
  1049. this.smallClassNArr.push(this.smallClassN);
  1050. }
  1051. smallClassPolygon.on('click', (e) => {
  1052. let imgList = [];
  1053. if (item.imageList.length > 0) {
  1054. item.imageList.forEach((element) => {
  1055. imgList.push(
  1056. `<img id="markerLabel" src="${element.image}"/>`
  1057. );
  1058. });
  1059. } else {
  1060. imgList.push('暂无图片');
  1061. }
  1062. this.imgClick();
  1063. let smallLabel =
  1064. "<div class='info-details'>" +
  1065. "<h5 class='marker-title'>" +
  1066. item.countyName +
  1067. '-' +
  1068. item.smallNumber +
  1069. '</h5>' +
  1070. "<div class='marker-content'>" +
  1071. '<div>' +
  1072. '<p>小班号:' +
  1073. item.smallNumber +
  1074. '</p>' +
  1075. '<p>样地数:' +
  1076. item.sampleCount +
  1077. '</p>' +
  1078. '<p>小班蓄积量:' +
  1079. item.smallClassStock +
  1080. '(立方米)' +
  1081. '</p>' +
  1082. '<p>小班占地面积:' +
  1083. item.landArea +
  1084. '(亩)' +
  1085. '</p>' +
  1086. '<p>小班树种组成:' +
  1087. item.treeComp +
  1088. '</p>' +
  1089. '<p>地类:' +
  1090. item.landType +
  1091. '</p>' +
  1092. '<p>林地权属:' +
  1093. item.landOwner +
  1094. '</p>' +
  1095. '<p>林木权属:' +
  1096. item.forestOwner +
  1097. '</p>' +
  1098. '<p>林种:' +
  1099. item.forestClass +
  1100. '</p>' +
  1101. '<p>树种结构:' +
  1102. item.treeStruct +
  1103. '</p>' +
  1104. '</div>' +
  1105. '<div>' +
  1106. '<p>起源:' +
  1107. item.origin +
  1108. '</p>' +
  1109. '<p>优势树种:' +
  1110. item.superTree +
  1111. '</p>' +
  1112. '<p>主要灌木名称:' +
  1113. item.shrubName +
  1114. '</p>' +
  1115. '<p>地貌:' +
  1116. item.landForm +
  1117. '</p>' +
  1118. '<p>海拔:' +
  1119. item.altitude +
  1120. '</p>' +
  1121. '<p>坡位:' +
  1122. item.slopePosit +
  1123. '</p>' +
  1124. '<p>坡向:' +
  1125. item.slopeDirect +
  1126. '</p>' +
  1127. '<p>坡形:' +
  1128. item.slopeForm +
  1129. '</p>' +
  1130. '<p>坡度:' +
  1131. item.slope +
  1132. '</p>' +
  1133. '<p>森林健康度:' +
  1134. item.forestHealth +
  1135. '</p>' +
  1136. '</div>' +
  1137. '</div>' +
  1138. '<div class="imgList">' +
  1139. "<span class='marker-span'>图片:</span>" +
  1140. '<div class="marker-imgs">' +
  1141. imgList +
  1142. '</div>' +
  1143. '</div>' +
  1144. '</div>';
  1145. that.smallMarker = new AMap.Marker({
  1146. map: that.map,
  1147. position: lanLatArr,
  1148. icon: require('@/assets/img/small-marker.png'),
  1149. anchor: 'bottom-center',
  1150. offset: new AMap.Pixel(-5, -6)
  1151. });
  1152. that.smallMarker.setLabel({
  1153. direction: 'right',
  1154. offset: new AMap.Pixel(-230, -160), //设置文本标注偏移量
  1155. content: smallLabel //设置文本标注内容
  1156. });
  1157. // that.smallMarker.setMap(that.map);
  1158. that.smallMarkers.push(that.smallMarker);
  1159. smallClassPolygon.setOptions({
  1160. fillOpacity: 0.7,
  1161. fillColor: 'yellow'
  1162. });
  1163. });
  1164. smallClassPolygon.on('mouseout', () => {
  1165. // if (that.smallMarker) {
  1166. // that.smallMarker.setMap(null);
  1167. // that.smallMarker = null;
  1168. // }
  1169. smallClassPolygon.setOptions({
  1170. fillOpacity: 0,
  1171. fillColor: '#ccebc5'
  1172. });
  1173. });
  1174. }
  1175. }
  1176. // this.map.add(that.smallClassPolygon);
  1177. this.map.on('rightclick', function (e) {
  1178. that.map.remove(that.smallMarkers);
  1179. });
  1180. });
  1181. }
  1182. },
  1183. imgClick() {
  1184. document.getElementsByTagName('div')[0].addEventListener('click', (e) => {
  1185. if (e.target.id === 'markerLabel') {
  1186. this.imgDialogVisible = true;
  1187. this.dialogImageUrl = e.target.currentSrc;
  1188. }
  1189. });
  1190. },
  1191. // 获取样地数据
  1192. getForestSample(page) {
  1193. forestSample({
  1194. cityId: this.$store.state.addr.selectCity.areaId,
  1195. countyId: this.$store.state.addr.selectDistrict.areaId
  1196. // townId: this.$store.state.addr.selectStreet.areaId
  1197. }).then((res) => {
  1198. let sampleMarker = require('@/assets/img/sample-marker.png');
  1199. let iconMeta = [28, 28];
  1200. this.setMarkers(res, sampleMarker, iconMeta, page);
  1201. });
  1202. },
  1203. // 添加地图标注(样地、树种)
  1204. setMarkers(res, sampleMarker, iconMeta, page) {
  1205. let _this = this;
  1206. if (this.forestMarker) {
  1207. this.forestMarker.setMap(null);
  1208. this.forestMarker = null;
  1209. }
  1210. this.markerData = res;
  1211. let iconMarker = sampleMarker;
  1212. let iconMetaSet = iconMeta;
  1213. let sampleIcon = new AMap.Icon({
  1214. size: new AMap.Size(iconMetaSet[0], iconMetaSet[1]), // 图标尺寸
  1215. image: iconMarker,
  1216. imageSize: new AMap.Size(iconMetaSet[0], iconMetaSet[1]) // 根据所设置的大小拉伸或压缩图片
  1217. });
  1218. this.markerData.rows.forEach((item) => {
  1219. let lngLat = [item.longitude, item.latitude];
  1220. if (item.longitude && item.latitude) {
  1221. this.forestMarker = new AMap.Marker({
  1222. map: _this.map,
  1223. position: lngLat,
  1224. icon: sampleIcon,
  1225. anchor: 'bottom-center',
  1226. offset: new AMap.Pixel(0, -18)
  1227. });
  1228. if (page === 'forest') {
  1229. this.forestMarker.setLabel({
  1230. direction: 'right',
  1231. offset: new AMap.Pixel(-8, 0), //设置文本标注偏移量
  1232. content: `<div style="color:#05dfff">${item.smallNumber}-${item.sampleNumber}</div>` //设置文本标注内容
  1233. });
  1234. let clickLabel =
  1235. "<div class='info-small'>" +
  1236. "<h5 class='marker-title'>" +
  1237. item.smallNumber +
  1238. '-' +
  1239. item.sampleNumber +
  1240. '</h5>' +
  1241. "<div class='marker-content'>" +
  1242. '<p>样地号:' +
  1243. item.sampleNumber +
  1244. '</p>' +
  1245. '<p>所属小班:' +
  1246. item.smallNumber +
  1247. '</p>' +
  1248. '<p>样地蓄积:' +
  1249. item.landStock +
  1250. '</p>' +
  1251. '<p>样地株数:' +
  1252. item.landNumber +
  1253. '</p>' +
  1254. '</div>' +
  1255. '</div>';
  1256. let lastMarker = new AMap.Marker({
  1257. position: lngLat,
  1258. icon: sampleIcon,
  1259. anchor: 'bottom-center',
  1260. offset: new AMap.Pixel(0, -18)
  1261. });
  1262. lastMarker.setLabel({
  1263. zIndex: 120,
  1264. direction: 'top',
  1265. offset: new AMap.Pixel(-4, 0), //设置文本标注偏移量
  1266. content: clickLabel //设置文本标注内容
  1267. });
  1268. this.forestMarker.on('click', function (e) {
  1269. _this.map.add(lastMarker);
  1270. });
  1271. this.forestMarker.on('mouseout', function (e) {
  1272. _this.map.remove(lastMarker);
  1273. });
  1274. } else if (page === 'treeSpecies') {
  1275. this.forestMarker.setLabel({
  1276. direction: 'top',
  1277. offset: new AMap.Pixel(0, 8), //设置文本标注偏移量
  1278. content: `<div class="label-treecomp">${item.treeComp}<span class="smallH">${item.smallNumber}</span></div>` //设置文本标注内容
  1279. });
  1280. }
  1281. // this.map.add(this.forestMarker);
  1282. // forestMarker
  1283. this.forestMarkerArr.push(this.forestMarker);
  1284. }
  1285. });
  1286. },
  1287. addTreeSpeciesPolygon() {
  1288. let that = this;
  1289. that.smallClassMapArr.forEach((item) => {
  1290. let polyData = JSON.parse(item.mapInfo);
  1291. for (let elementLs in polyData.features) {
  1292. let polygonColor = '';
  1293. this.treePlant.forEach((tree) => {
  1294. if (tree.plantName == item.superTree && item.superTree == '硬阔') {
  1295. polygonColor = '#00da85';
  1296. } else if (
  1297. tree.plantName == item.superTree &&
  1298. item.superTree == '软阔'
  1299. ) {
  1300. polygonColor = '#009bfd';
  1301. } else if (
  1302. tree.plantName == item.superTree &&
  1303. item.superTree == '杉木'
  1304. ) {
  1305. polygonColor = '#eca62d';
  1306. } else if (
  1307. tree.plantName == item.superTree &&
  1308. item.superTree == '马尾松'
  1309. ) {
  1310. polygonColor = '#b82dec';
  1311. }
  1312. });
  1313. let polygon = new AMap.Polygon({
  1314. map: that.map,
  1315. path: polyData.features[elementLs].geometry.coordinates,
  1316. strokeOpacity: 1,
  1317. fillOpacity: 0.6,
  1318. strokeColor: 'red',
  1319. strokeWeight: 2,
  1320. zIndex: 999,
  1321. cursor: 'pointer',
  1322. fillColor: polygonColor
  1323. });
  1324. this.treesPolygonArr.push(polygon);
  1325. if (item.longitude && item.latitude) {
  1326. var lanLatArr = [];
  1327. polygon.on('click', (e) => {
  1328. lanLatArr = [item.longitude, item.latitude];
  1329. let treeSmallLabel =
  1330. "<div class='info-small'>" +
  1331. "<h5 class='marker-title'>小班" +
  1332. item.smallNumber +
  1333. '</h5>' +
  1334. "<div class='marker-content'>" +
  1335. '<p>树种组成:' +
  1336. item.treeComp +
  1337. '</p>' +
  1338. '<p>树种结构:' +
  1339. item.treeStruct +
  1340. '</p>' +
  1341. '<p>优势树种:' +
  1342. item.superTree +
  1343. '</p>' +
  1344. '<p>优势树种平均胸径:' +
  1345. item.superTreeDbh +
  1346. '厘米' +
  1347. '</p>' +
  1348. '<p>优势树种平均高:' +
  1349. item.superTreeHigh +
  1350. '米' +
  1351. '</p>' +
  1352. '<p>位置:' +
  1353. item.countyName +
  1354. item.townName +
  1355. item.villageName +
  1356. '</p>' +
  1357. '</div>' +
  1358. '</div>';
  1359. that.smallMarker = new AMap.Marker({
  1360. map: that.map,
  1361. position: lanLatArr,
  1362. icon: require('@/assets/img/small-marker.png'),
  1363. anchor: 'bottom-center',
  1364. offset: new AMap.Pixel(0, 0)
  1365. });
  1366. that.smallMarker.setLabel({
  1367. direction: 'top',
  1368. offset: new AMap.Pixel(-10, 0), //设置文本标注偏移量
  1369. content: treeSmallLabel //设置文本标注内容
  1370. });
  1371. that.treeCompMarkers.push(that.smallMarker);
  1372. });
  1373. polygon.on('mouseout', () => {
  1374. that.map.remove(that.treeCompMarkers);
  1375. });
  1376. }
  1377. }
  1378. });
  1379. },
  1380. // 获取小班列表
  1381. getRightScrollData(page) {
  1382. rightScrollData({
  1383. cityId: this.$store.state.addr.selectCity.areaId,
  1384. countyId: this.$store.state.addr.selectDistrict.areaId
  1385. // townId: this.$store.state.addr.selectStreet.areaId
  1386. }).then((res) => {
  1387. let sampleMarker = require('@/assets/img/sanjiaod.png');
  1388. let iconMeta = [16, 10];
  1389. this.setMarkers(res, sampleMarker, iconMeta, page);
  1390. });
  1391. },
  1392. // 事件信息
  1393. getEven() {
  1394. let _this = this;
  1395. alarmDataApi().then((res) => {
  1396. res.data.forEach((item) => {
  1397. let lanLatArr = [item.longitude, item.latitude];
  1398. let baseIcon = '';
  1399. let fireIcon = require('@/assets/img/fire.png');
  1400. let cutTreeIcon = require('@/assets/img/cutTree.png');
  1401. let insectpestIcon = require('@/assets/img/insectpest.png');
  1402. if (item.eventType == 1) {
  1403. item.eventContLabel = '火灾';
  1404. baseIcon = fireIcon;
  1405. } else if (item.eventType == 2) {
  1406. item.eventContLabel = '砍伐';
  1407. baseIcon = cutTreeIcon;
  1408. } else if (item.eventType == 3) {
  1409. item.eventContLabel = '病虫害';
  1410. baseIcon = insectpestIcon;
  1411. }
  1412. _this.smallMarker = new AMap.Marker({
  1413. map: _this.map,
  1414. position: lanLatArr,
  1415. icon: baseIcon,
  1416. anchor: 'bottom-center',
  1417. offset: new AMap.Pixel(0, 0),
  1418. zIndex: 999
  1419. });
  1420. _this.eventMarkersArr.push(_this.smallMarker);
  1421. _this.smallMarker.on('click', function (e) {
  1422. let treeSmallLabel =
  1423. "<div class='info-small'>" +
  1424. "<h5 class='marker-title'>最新事件" +
  1425. '</h5>' +
  1426. "<div class='marker-content'>" +
  1427. '<p>事件类型:' +
  1428. item.eventContLabel +
  1429. '</p>' +
  1430. '<p>上报时间:' +
  1431. item.createTime +
  1432. '</p>' +
  1433. '<p>上报人:' +
  1434. item.createBy +
  1435. '</p>' +
  1436. '<p>位置:' +
  1437. item.cityName +
  1438. item.countyName +
  1439. item.townName +
  1440. item.villageName +
  1441. '</p>' +
  1442. '</div>' +
  1443. '</div>';
  1444. _this.eventMarker = new AMap.Marker({
  1445. position: lanLatArr,
  1446. icon: baseIcon,
  1447. anchor: 'bottom-center',
  1448. offset: new AMap.Pixel(0, 0),
  1449. zIndex: 999
  1450. });
  1451. _this.eventMarker.setLabel({
  1452. direction: 'top',
  1453. offset: new AMap.Pixel(-10, 0), //设置文本标注偏移量
  1454. content: treeSmallLabel //设置文本标注内容
  1455. });
  1456. _this.map.add(_this.eventMarker);
  1457. });
  1458. _this.smallMarker.on('mouseout', function (e) {
  1459. if (!_this.eventMarker) {
  1460. return;
  1461. } else {
  1462. _this.map.remove(_this.eventMarker);
  1463. }
  1464. });
  1465. });
  1466. });
  1467. },
  1468. // 林业经济
  1469. getEconomics() {
  1470. this.smallClassMapArr.forEach((item) => {
  1471. let polyData = JSON.parse(item.mapInfo);
  1472. for (let elementLs in polyData.features) {
  1473. let polygon = new AMap.Polygon({
  1474. map: this.map,
  1475. path: polyData.features[elementLs].geometry.coordinates,
  1476. strokeOpacity: 1,
  1477. fillOpacity: 0,
  1478. strokeColor: 'red',
  1479. strokeWeight: 2,
  1480. zIndex: 999,
  1481. cursor: 'pointer'
  1482. });
  1483. this.economicsArr.push(polygon);
  1484. polygon.on('mouseover', (e) => {
  1485. polygon.setOptions({
  1486. fillOpacity: 0.7,
  1487. fillColor: 'yellow'
  1488. });
  1489. });
  1490. polygon.on('mouseout', () => {
  1491. polygon.setOptions({
  1492. fillOpacity: 0,
  1493. fillColor: '#ccebc5'
  1494. });
  1495. });
  1496. }
  1497. });
  1498. financeBasePlant({
  1499. cityId: this.$store.state.addr.selectCity.areaId,
  1500. countyId: this.$store.state.addr.selectDistrict.areaId
  1501. // townId: this.$store.state.addr.selectStreet.areaId
  1502. }).then((res) => {
  1503. let economicsList = [];
  1504. let baseList = [];
  1505. res.rows.forEach((element) => {
  1506. economicsList.push({
  1507. longitude: element.cateLongitude,
  1508. latitude: element.cateLatitude,
  1509. icon: element.image
  1510. });
  1511. baseList.push({
  1512. baseId: element.baseId,
  1513. baseName: element.baseName,
  1514. longitude: element.baseLongitude,
  1515. latitude: element.baseLatitude
  1516. });
  1517. });
  1518. economicsList.forEach((item) => {
  1519. let lanLatArr = [item.longitude, item.latitude];
  1520. let beeIcon = item.icon;
  1521. let iconMeta = [82, 26];
  1522. let sampleIcon = new AMap.Icon({
  1523. size: new AMap.Size(iconMeta[0], iconMeta[1]), // 图标尺寸
  1524. image: beeIcon,
  1525. imageSize: new AMap.Size(iconMeta[0], iconMeta[1]) // 根据所设置的大小拉伸或压缩图片
  1526. });
  1527. this.smallMarker = new AMap.Marker({
  1528. map: this.map,
  1529. position: lanLatArr,
  1530. icon: sampleIcon,
  1531. anchor: 'bottom-center',
  1532. offset: new AMap.Pixel(0, 0)
  1533. });
  1534. this.economicsArr.push(this.smallMarker);
  1535. // this.smallMarker.setMap(this.map);
  1536. });
  1537. baseList.forEach((element) => {
  1538. let lanLatArr = [element.longitude, element.latitude];
  1539. let baseIcon = require('@/assets/img/postion.png');
  1540. let iconMeta = [20, 29];
  1541. let sampleIcon = new AMap.Icon({
  1542. size: new AMap.Size(iconMeta[0], iconMeta[1]), // 图标尺寸
  1543. image: baseIcon,
  1544. imageSize: new AMap.Size(iconMeta[0], iconMeta[1]) // 根据所设置的大小拉伸或压缩图片
  1545. });
  1546. this.baseMarker = new AMap.Marker({
  1547. map: this.map,
  1548. position: lanLatArr,
  1549. icon: sampleIcon,
  1550. anchor: 'bottom-center',
  1551. offset: new AMap.Pixel(0, 0)
  1552. });
  1553. this.baseMarker.setLabel({
  1554. direction: 'right',
  1555. offset: new AMap.Pixel(0, 0), //设置文本标注偏移量
  1556. content: `<div>${element.baseName}</div>` //设置文本标注内容
  1557. });
  1558. this.baseMarkerArr.push(this.baseMarker);
  1559. this.baseMarker.on('click', function (e) {
  1560. financeBaseDetail({ baseId: element.baseId }).then((res) => {
  1561. if (res.code == 200) {
  1562. let treeSmallLabel =
  1563. "<div class='info-small'>" +
  1564. "<h5 class='marker-title'>" +
  1565. res.data.baseName +
  1566. '</h5>' +
  1567. "<div class='marker-content'>" +
  1568. '<p>基地名称:' +
  1569. res.data.baseName +
  1570. '</p>' +
  1571. '<p>种植/养殖/加工作物:' +
  1572. res.data.cropName +
  1573. '</p>' +
  1574. '<p>占地面积:' +
  1575. res.data.baseArea +
  1576. '亩' +
  1577. '</p>' +
  1578. '<p>位置:' +
  1579. res.data.cityName +
  1580. res.data.countyName +
  1581. res.data.townName +
  1582. '</p>' +
  1583. '</div>' +
  1584. '</div>';
  1585. baseMarker.setLabel({
  1586. direction: 'top',
  1587. offset: new AMap.Pixel(0, 0), //设置文本标注偏移量
  1588. content: treeSmallLabel //设置文本标注内容
  1589. });
  1590. }
  1591. });
  1592. });
  1593. this.baseMarker.on('mouseout', function (e) {
  1594. baseMarker.setLabel({
  1595. direction: 'right',
  1596. offset: new AMap.Pixel(0, 0), //设置文本标注偏移量
  1597. content: `<div>${element.baseName}</div>` //设置文本标注内容
  1598. });
  1599. });
  1600. });
  1601. });
  1602. },
  1603. getTreePlant() {
  1604. treePlant().then((res) => {
  1605. this.treePlant = res.rows;
  1606. });
  1607. }
  1608. }
  1609. };
  1610. </script>
  1611. <style lang='scss' scoped>
  1612. #container {
  1613. width: 100%;
  1614. height: 100vh;
  1615. /deep/ .tdt-pane {
  1616. z-index: auto;
  1617. }
  1618. }
  1619. /deep/ .amap-marker-content {
  1620. .tipMarker {
  1621. color: #555;
  1622. background-color: rgba(255, 254, 239, 0.8);
  1623. border: 1px solid #7e7e7e;
  1624. padding: 2px 6px;
  1625. font-size: 12px;
  1626. white-space: nowrap;
  1627. display: inline-block;
  1628. &:before,
  1629. &:after {
  1630. content: '';
  1631. display: block;
  1632. position: absolute;
  1633. margin: auto;
  1634. width: 0;
  1635. height: 0;
  1636. border: solid transparent;
  1637. border-width: 5px 5px;
  1638. }
  1639. &.top {
  1640. transform: translate(-50%, -110%);
  1641. &:before,
  1642. &:after {
  1643. bottom: -9px;
  1644. left: 0;
  1645. right: 0;
  1646. border-top-color: rgba(255, 254, 239, 0.8);
  1647. }
  1648. &:before {
  1649. bottom: -10px;
  1650. border-top-color: #7e7e7e;
  1651. }
  1652. }
  1653. }
  1654. }
  1655. /deep/ .amap-logo,
  1656. .amap-copyright {
  1657. display: block !important;
  1658. visibility: inherit !important;
  1659. }
  1660. /deep/ .amap-icon img {
  1661. max-width: 3rem !important;
  1662. max-height: 3rem !important;
  1663. }
  1664. /deep/ .info-small {
  1665. background-image: url('../assets/img/small-label.png');
  1666. background-repeat: no-repeat;
  1667. background-size: 100% 100%;
  1668. width: 18rem;
  1669. // height: 10rem;
  1670. color: #fff;
  1671. .marker-title {
  1672. margin: 0 auto;
  1673. line-height: 30px;
  1674. }
  1675. .marker-content {
  1676. padding: 0 20px 10px 20px;
  1677. p {
  1678. text-align: left;
  1679. font-size: 12px;
  1680. margin: 0;
  1681. line-height: 28px;
  1682. }
  1683. }
  1684. }
  1685. /deep/ .info-details {
  1686. background-image: url('../assets/img/small-label.png');
  1687. background-repeat: no-repeat;
  1688. background-size: 100% 100%;
  1689. width: 26rem;
  1690. padding-bottom: 13px;
  1691. // height: 10rem;
  1692. color: #fff;
  1693. .marker-title {
  1694. margin: 0 auto;
  1695. line-height: 50px;
  1696. }
  1697. .marker-content {
  1698. display: flex;
  1699. justify-content: space-between;
  1700. padding: 0 20px 0 20px;
  1701. .marker-span {
  1702. display: block;
  1703. }
  1704. p {
  1705. text-align: left;
  1706. font-size: 12px;
  1707. margin: 0;
  1708. line-height: 18px;
  1709. }
  1710. }
  1711. .imgList {
  1712. display: block;
  1713. text-align: left;
  1714. padding: 0 20px;
  1715. .marker-span {
  1716. display: block;
  1717. }
  1718. .marker-imgs {
  1719. display: block;
  1720. line-height: 18px !important;
  1721. img {
  1722. width: 40px;
  1723. height: 40px;
  1724. margin: 0 4px;
  1725. cursor: pointer;
  1726. }
  1727. }
  1728. }
  1729. }
  1730. /deep/ .amap-marker-label {
  1731. border: 0;
  1732. background-color: transparent;
  1733. }
  1734. #mask {
  1735. width: 100%;
  1736. height: 100vh;
  1737. box-shadow: inset 0px 0px 10vw 8vw rgba(0, 10, 34, 0.54);
  1738. position: fixed;
  1739. left: 0;
  1740. right: 0;
  1741. bottom: 0;
  1742. top: 0;
  1743. pointer-events: none;
  1744. }
  1745. @keyframes imageAnimation_32630606 {
  1746. 0% {
  1747. // opacity: 0;
  1748. transform: none;
  1749. }
  1750. 34% {
  1751. // opacity: 1;
  1752. transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg) scaleX(1) scaleY(1)
  1753. translate3d(34vw, 0px, 0px);
  1754. }
  1755. 67% {
  1756. // opacity: 1;
  1757. transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg) scaleX(1) scaleY(1)
  1758. translate3d(67vw, 0px, 0px);
  1759. }
  1760. 100% {
  1761. // opacity: 0;
  1762. transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg) scaleX(1) scaleY(1)
  1763. translate3d(160vw, 0px, 0px);
  1764. }
  1765. }
  1766. .yun-wrap {
  1767. position: fixed;
  1768. left: 0;
  1769. top: 350px;
  1770. width: 100vw;
  1771. pointer-events: none;
  1772. }
  1773. .yun {
  1774. position: fixed;
  1775. left: -500px;
  1776. animation-name: imageAnimation_32630606;
  1777. animation-iteration-count: infinite;
  1778. animation-timing-function: linear;
  1779. animation-duration: 110s;
  1780. animation-delay: 0s;
  1781. -webkit-user-drag: none;
  1782. filter: none;
  1783. pointer-events: none;
  1784. }
  1785. .yun2 {
  1786. bottom: 20px;
  1787. animation-duration: 90s;
  1788. animation-delay: 10s;
  1789. }
  1790. .yun3 {
  1791. top: 100px;
  1792. animation-duration: 120s;
  1793. animation-delay: 15s;
  1794. }
  1795. /deep/ .label-treecomp {
  1796. position: relative;
  1797. background-color: #05dfff;
  1798. color: #fff;
  1799. padding: 6px 10px;
  1800. border-radius: 8px;
  1801. font-size: 14px;
  1802. text-align: center;
  1803. &::before {
  1804. position: absolute;
  1805. top: 26px;
  1806. left: 42%;
  1807. content: '';
  1808. width: 0px;
  1809. height: 0px;
  1810. border: 6px solid transparent;
  1811. border-top-color: #05dfff;
  1812. }
  1813. .smallH {
  1814. position: absolute;
  1815. top: 34px;
  1816. z-index: 99;
  1817. display: block;
  1818. color: #05dfff;
  1819. text-align: center;
  1820. font-size: 14px;
  1821. // left: 38%;
  1822. left: 0;
  1823. width: 100%;
  1824. }
  1825. }
  1826. </style>