amapnow.vue 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848
  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. smallClassMapFile,
  25. rightScrollData,
  26. forestSample,
  27. alarmDataApi,
  28. financeBasePlant,
  29. financeBaseDetail,
  30. farmInfo,
  31. smallClassDetail,
  32. treePlant
  33. } from '@/service/index.js';
  34. import axios from 'axios';
  35. export default {
  36. name: 'Mapview',
  37. data() {
  38. return {
  39. imgDialogVisible: false,
  40. dialogImageUrl: null,
  41. AMap: null,
  42. map: null,
  43. lngLat: [106.628201, 26.646694],
  44. adName: '贵州省',
  45. mapLevel: 'province',
  46. adcode: '贵州省',
  47. parentId: '520000',
  48. province: '',
  49. zoom: 8,
  50. districtExplorer: null,
  51. tipMarker: null,
  52. $tipMarkerContent: null,
  53. currentAreaNode: null,
  54. cityMarkerArr: [],
  55. eventMarker: null,
  56. baseMarker: null,
  57. streetMarkerArr: [],
  58. leftPage: 'forest',
  59. putPolygonData: [],
  60. //乡镇边界
  61. townPolygons: [],
  62. // 基地详情
  63. baseMarkers: [],
  64. // 小班详情
  65. smallMarkers: [],
  66. // 时间详情
  67. eventMarkers: [],
  68. // 林场
  69. treesMarkerArr: [],
  70. // 小班边界
  71. smallClassMapArr: [],
  72. // 作物
  73. economicsArr: [],
  74. // 基地定位
  75. baseMarkerArr: [],
  76. // 时间信息
  77. eventMarkersArr: [],
  78. // 样地、小班
  79. forestMarkerArr: [],
  80. // 样地号
  81. smallClassNArr: [],
  82. // 森林资源小班边界
  83. smallClassPolygonArr: [],
  84. // 林木结构小班边界
  85. treesPolygonArr: [],
  86. treeCompMarkers: [],
  87. townPolygonArr: [],
  88. economicsArr: [],
  89. selectData: {},
  90. districtData: {},
  91. streetData: {}
  92. };
  93. },
  94. watch: {
  95. '$store.state.addr.parentId': {
  96. handler(val) {
  97. // 加载小班边界
  98. this.getSmallClass();
  99. this.parentId = val;
  100. if (this.$store.state.addr.mapLevel == 'street') {
  101. this.parentId = val.substring(0, 6);
  102. if (this.map) {
  103. this.switch2AreaNode(
  104. this.parentId,
  105. this.$store.state.addr.mapLevel,
  106. this.$store.state.addr.selectCity,
  107. this.leftPage
  108. );
  109. }
  110. }
  111. if (this.$store.state.addr.mapLevel != 'street') {
  112. this.selectData = this.$store.state.addr.selectCity;
  113. this.districtData = this.$store.state.addr.selectDistrict;
  114. this.streetData = this.$store.state.addr.selectStreet;
  115. if (this.map) {
  116. this.switch2AreaNode(
  117. this.parentId,
  118. this.$store.state.addr.mapLevel,
  119. this.$store.state.addr.selectCity,
  120. this.leftPage
  121. );
  122. }
  123. if (
  124. this.polygon ||
  125. this.streetMarkerArr ||
  126. this.townPolygons ||
  127. this.forestMarkerArr ||
  128. this.smallClassNArr ||
  129. this.forestMarkerArr ||
  130. this.townPolygonArr
  131. ) {
  132. this.map.remove(this.polygon);
  133. this.map.remove(this.streetMarkerArr);
  134. this.map.remove(this.townPolygons);
  135. this.map.remove(this.forestMarkerArr);
  136. this.map.remove(this.smallClassNArr);
  137. this.map.remove(this.forestMarkerArr);
  138. this.map.remove(this.townPolygonArr);
  139. }
  140. }
  141. }
  142. },
  143. '$store.state.addr.selectStreet'(val) {
  144. if (val.label && val.value && val.areaId) {
  145. this.map.remove(this.polygon);
  146. let labelTown = val.label;
  147. this.map.setCity(labelTown);
  148. }
  149. },
  150. '$store.state.addr.page': {
  151. handler(val) {
  152. this.leftPage = val;
  153. if (!this.parentId) {
  154. this.parentId = '520000';
  155. this.$store.state.addr.parentName = '贵州省';
  156. }
  157. if (this.parentId) {
  158. this.getSmallClass(val);
  159. this.mapPolygon();
  160. }
  161. if (val != 'forest') {
  162. this.map.remove(this.forestMarkerArr);
  163. this.map.remove(this.smallClassNArr);
  164. this.map.remove(this.smallClassPolygonArr);
  165. }
  166. if (val != 'treeSpecies') {
  167. this.map.remove(this.forestMarkerArr);
  168. this.map.remove(this.treesPolygonArr);
  169. }
  170. if (val != 'economics') {
  171. this.map.remove(this.economicsArr);
  172. this.map.remove(this.baseMarkerArr);
  173. }
  174. if (val != 'event') {
  175. this.map.remove(this.eventMarkersArr);
  176. }
  177. }
  178. },
  179. '$store.state.addr.smallClassSearch': {
  180. deep: true,
  181. immediate: true,
  182. handler: function (val, oldVal) {
  183. let _this = this;
  184. if (val) {
  185. if (val.longitude && val.latitude && !val.name) {
  186. let lanLatArr = [val.longitude, val.latitude];
  187. let imgList = [];
  188. if (val.imageList.length > 0) {
  189. val.imageList.forEach((element) => {
  190. imgList.push(`<img id="markerLabel" src="${element.image}"/>`);
  191. });
  192. } else {
  193. imgList.push('暂无图片');
  194. }
  195. this.imgClick();
  196. let smallLabel =
  197. "<div class='info-details'>" +
  198. "<h5 class='marker-title'>" +
  199. val.countyName +
  200. '-' +
  201. val.smallNumber +
  202. '</h5>' +
  203. "<div class='marker-content'>" +
  204. '<div>' +
  205. '<p>小班号:' +
  206. val.smallNumber +
  207. '</p>' +
  208. '<p>样地数:' +
  209. val.sampleCount +
  210. '</p>' +
  211. '<p>小班蓄积量:' +
  212. val.smallClassStock +
  213. '(立方米)' +
  214. '</p>' +
  215. '<p>小班占地面积:' +
  216. val.landArea +
  217. '(亩)' +
  218. '</p>' +
  219. '<p>小班树种组成:' +
  220. val.treeComp +
  221. '</p>' +
  222. '<p>地类:' +
  223. val.landType +
  224. '</p>' +
  225. '<p>林地权属:' +
  226. val.landOwner +
  227. '</p>' +
  228. '<p>林木权属:' +
  229. val.forestOwner +
  230. '</p>' +
  231. '<p>林种:' +
  232. val.forestClass +
  233. '</p>' +
  234. '<p>树种结构:' +
  235. val.treeStruct +
  236. '</p>' +
  237. '</div>' +
  238. '<div>' +
  239. '<p>起源:' +
  240. val.origin +
  241. '</p>' +
  242. '<p>优势树种:' +
  243. val.superTree +
  244. '</p>' +
  245. '<p>主要灌木名称:' +
  246. val.shrubName +
  247. '</p>' +
  248. '<p>地貌:' +
  249. val.landForm +
  250. '</p>' +
  251. '<p>海拔:' +
  252. val.altitude +
  253. '</p>' +
  254. '<p>坡位:' +
  255. val.slopePosit +
  256. '</p>' +
  257. '<p>坡向:' +
  258. val.slopeDirect +
  259. '</p>' +
  260. '<p>坡形:' +
  261. val.slopeForm +
  262. '</p>' +
  263. '<p>坡度:' +
  264. val.slope +
  265. '</p>' +
  266. '<p>森林健康度:' +
  267. val.forestHealth +
  268. '</p>' +
  269. '</div>' +
  270. '</div>' +
  271. '<div class="imgList">' +
  272. "<span class='marker-span'>图片:</span>" +
  273. '<div class="marker-imgs">' +
  274. imgList +
  275. '</div>' +
  276. '</div>' +
  277. '</div>';
  278. this.smallMarker = new AMap.Marker({
  279. map: this.map,
  280. position: lanLatArr,
  281. icon: require('@/assets/img/small-marker.png'),
  282. anchor: 'bottom-center',
  283. offset: new AMap.Pixel(0, 0),
  284. zIndex: 9999
  285. });
  286. this.smallMarker.setLabel({
  287. direction: 'right',
  288. offset: new AMap.Pixel(-230, -160), //设置文本标注偏移量
  289. content: smallLabel //设置文本标注内容
  290. });
  291. this.smallMarkers.push(_this.smallMarker);
  292. } else if (val.name == false && this.smallMarker) {
  293. this.map.on('rightclick', function (e) {
  294. _this.map.remove(_this.smallMarkers);
  295. });
  296. }
  297. }
  298. }
  299. },
  300. '$store.state.addr.eventData': {
  301. deep: true,
  302. immediate: true,
  303. handler: function (val, oldVal) {
  304. let _this = this;
  305. if (val) {
  306. if (val.longitude && val.latitude && !val.name) {
  307. let lanLatArr = [val.longitude, val.latitude];
  308. let baseIcon = '';
  309. let fireIcon = require('@/assets/img/fire.png');
  310. let cutTreeIcon = require('@/assets/img/cutTree.png');
  311. let insectpestIcon = require('@/assets/img/insectpest.png');
  312. if (val.eventType == 1) {
  313. val.eventContLabel = '火灾';
  314. baseIcon = fireIcon;
  315. } else if (val.eventType == 2) {
  316. val.eventContLabel = '砍伐';
  317. baseIcon = cutTreeIcon;
  318. } else if (val.eventType == 3) {
  319. val.eventContLabel = '病虫害';
  320. baseIcon = insectpestIcon;
  321. } else if (val.eventType == 4) {
  322. val.eventContLabel = '偷盗林木';
  323. }
  324. let treeSmallLabel =
  325. "<div class='info-small'>" +
  326. "<h5 class='marker-title'>历史事件" +
  327. '</h5>' +
  328. "<div class='marker-content'>" +
  329. '<p>事件类型:' +
  330. val.eventContLabel +
  331. '</p>' +
  332. '<p>上报时间:' +
  333. val.createTime +
  334. '</p>' +
  335. '<p>上报人:' +
  336. val.createBy +
  337. '</p>' +
  338. '<p>位置:' +
  339. val.cityName +
  340. val.countyName +
  341. val.townName +
  342. val.villageName +
  343. '</p>' +
  344. '</div>' +
  345. '</div>';
  346. this.eventMarker = new AMap.Marker({
  347. map: this.map,
  348. position: lanLatArr,
  349. icon: baseIcon,
  350. anchor: 'bottom-center',
  351. offset: new AMap.Pixel(0, 0),
  352. zIndex: 9999
  353. });
  354. this.eventMarker.setLabel({
  355. direction: 'top',
  356. offset: new AMap.Pixel(-10, 0), //设置文本标注偏移量
  357. content: treeSmallLabel //设置文本标注内容
  358. });
  359. this.eventMarkers.push(this.eventMarker);
  360. // this.map.add(this.eventMarker);
  361. } else if (val.name == false && this.eventMarker) {
  362. this.map.on('rightclick', function (e) {
  363. _this.map.remove(_this.eventMarkers);
  364. });
  365. }
  366. }
  367. }
  368. },
  369. '$store.state.addr.baseDetail': {
  370. deep: true,
  371. immediate: true,
  372. handler: function (val, oldVal) {
  373. let _this = this;
  374. if (val) {
  375. if (val.baseLongitude && val.baseLatitude && !val.name) {
  376. let lanLatArr = [val.baseLongitude, val.baseLatitude];
  377. let treeSmallLabel =
  378. "<div class='info-small'>" +
  379. "<h5 class='marker-title'>" +
  380. val.baseName +
  381. '</h5>' +
  382. "<div class='marker-content'>" +
  383. '<p>基地名称:' +
  384. val.baseName +
  385. '</p>' +
  386. '<p>种植/养殖/加工作物:' +
  387. val.cropName +
  388. '</p>' +
  389. '<p>占地面积:' +
  390. val.baseArea +
  391. '亩' +
  392. '</p>' +
  393. '<p>位置:' +
  394. val.cityName +
  395. val.countyName +
  396. val.townName +
  397. '</p>' +
  398. '</div>' +
  399. '</div>';
  400. this.baseMarker = new AMap.Marker({
  401. map: this.map,
  402. position: lanLatArr,
  403. icon: require('@/assets/img/small-marker.png'),
  404. anchor: 'bottom-center',
  405. offset: new AMap.Pixel(0, 0),
  406. zIndex: 9999
  407. });
  408. this.baseMarker.setLabel({
  409. direction: 'top',
  410. offset: new AMap.Pixel(0, 0), //设置文本标注偏移量
  411. content: treeSmallLabel //设置文本标注内容
  412. });
  413. this.baseMarkers.push(_this.baseMarker);
  414. } else if (val.name == false && _this.baseMarker) {
  415. this.map.on('rightclick', function (e) {
  416. _this.map.remove(_this.baseMarkers);
  417. });
  418. }
  419. }
  420. }
  421. }
  422. },
  423. computed: {
  424. ...mapGetters(['vuexCityList', 'vuexDistrictList', 'vuexStreetList']),
  425. ...mapState(['selectCity', 'selectDistrict', 'selectStreet'])
  426. },
  427. created() {
  428. this.getTreePlant();
  429. },
  430. mounted() {
  431. this.initAMap();
  432. // 加载小班边界
  433. this.getSmallClass();
  434. },
  435. methods: {
  436. ...mapMutations([
  437. 'changeSelectCity',
  438. 'changeSelectDistrict',
  439. 'changeSelectStreet',
  440. 'changeSelectAddr'
  441. ]),
  442. initAMap() {
  443. window._AMapSecurityConfig = {
  444. securityJsCode: 'e6666dfe93e7d3c6f3a5dc35cad6befb' // 密钥
  445. };
  446. let _this = this;
  447. AMapLoader.load({
  448. key: 'f79d862df9288710e3dce6591af9dff1', //设置您的key
  449. version: '2.0',
  450. plugins: [
  451. 'AMap.ToolBar',
  452. 'AMap.Driving',
  453. 'AMap.DistrictSearch',
  454. 'AMap.MapboxVectorTileLayer'
  455. ],
  456. Loca: {
  457. version: '2.0'
  458. },
  459. AMapUI: {
  460. version: '1.1',
  461. plugins: ['overlay/SimpleMarker']
  462. },
  463. features: ['road', 'bg', 'building']
  464. }).then((AMap) => {
  465. _this.AMap = AMap;
  466. _this.map = new AMap.Map('container', {
  467. viewMode: '3D',
  468. zoom: _this.zoom,
  469. center: _this.lngLat,
  470. pitch: 45,
  471. terrain: true,
  472. features: ['road', 'bg', 'building'],
  473. layers: [new AMap.TileLayer.Satellite()]
  474. });
  475. AMapUI.load(
  476. ['ui/geo/DistrictExplorer', 'ui/geo/DistrictCluster', 'lib/$'],
  477. function (DistrictExplorer, DistrictCluster, $) {
  478. window.DistrictCluster = DistrictCluster;
  479. _this.loadMapData(DistrictExplorer, $);
  480. }
  481. );
  482. _this.map.on('rightclick', function (e) {
  483. if (_this.smallMarkers.length > 0) {
  484. _this.map.remove(_this.smallMarkers);
  485. }
  486. // if (_this.treeCompMarkers.length > 0) {
  487. // _this.map.remove(_this.treeCompMarkers);
  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. async getSmallClass() {
  957. let that = this;
  958. that.smallClassMapArr = [];
  959. let params = {
  960. cityId: that.$store.state.addr.selectCity.areaId,
  961. countyId: that.$store.state.addr.selectDistrict.areaId
  962. // townId: this.$store.state.addr.selectStreet.areaId
  963. };
  964. if (that.smallClassPolygonArr.length > 0) {
  965. that.map.remove(that.smallClassPolygonArr);
  966. }
  967. if (that.treesPolygonArr.length > 0) {
  968. that.map.remove(that.treesPolygonArr);
  969. }
  970. let pageData = {
  971. pageNum: 0,
  972. pageSize: 25
  973. };
  974. let mapLevel = that.$store.state.addr.mapLevel;
  975. let res = await smallClassMap({ ...params, ...pageData });
  976. if (res.code == 200) {
  977. const total = res.total;
  978. const totalPage = Math.ceil(total / pageData.pageSize);
  979. const render = (page, mapLevel) => {
  980. if (page >= totalPage) return;
  981. requestAnimationFrame(() => {
  982. render(page + 1, mapLevel);
  983. pageData.pageNum = page;
  984. smallClassMap({ ...params, ...pageData }).then((response) => {
  985. if (response.code == 200) {
  986. response.rows.forEach((item) => {
  987. if (item.smallId != null) {
  988. }
  989. // this.smallClassMapArr.push(item);
  990. if (that.leftPage === 'forest') {
  991. this.addForestPolygon(item);
  992. } else if (this.leftPage === 'treeSpecies') {
  993. this.addTreeSpeciesPolygon(item);
  994. }
  995. });
  996. }
  997. });
  998. });
  999. };
  1000. render(pageData.pageNum, mapLevel);
  1001. }
  1002. },
  1003. mapPolygon() {
  1004. if (this.smallClassMapArr) {
  1005. if (this.leftPage === 'forest') {
  1006. // this.addForestPolygon(this.smallClassMapArr);
  1007. if (
  1008. this.$store.state.addr.mapLevel == 'district' ||
  1009. this.$store.state.addr.mapLevel == 'street'
  1010. ) {
  1011. this.getForestSample(this.leftPage);
  1012. }
  1013. } else if (this.leftPage === 'treeSpecies') {
  1014. // this.addTreeSpeciesPolygon();
  1015. if (
  1016. this.$store.state.addr.mapLevel == 'district' ||
  1017. this.$store.state.addr.mapLevel == 'street'
  1018. ) {
  1019. this.getRightScrollData(this.leftPage);
  1020. }
  1021. } else if (this.leftPage === 'economics') {
  1022. this.getEconomics();
  1023. } else if (this.leftPage === 'event') {
  1024. this.getEven();
  1025. }
  1026. }
  1027. },
  1028. addForestPolygon(item) {
  1029. let that = this;
  1030. if (item) {
  1031. // smallClassMapArr.forEach((item) => {
  1032. let polyData = JSON.parse(item.mapInfo);
  1033. for (let elementLs in polyData.features) {
  1034. let smallClassPolygon = new AMap.Polygon({
  1035. map: that.map,
  1036. path: polyData.features[elementLs].geometry.coordinates,
  1037. strokeOpacity: 1,
  1038. fillOpacity: 0,
  1039. strokeColor: 'red',
  1040. strokeWeight: 2,
  1041. zIndex: 999,
  1042. cursor: 'pointer',
  1043. fillColor: ''
  1044. });
  1045. this.smallClassPolygonArr.push(smallClassPolygon);
  1046. smallClassPolygon.on('click', (e) => {
  1047. let imgList = [];
  1048. if (item.imageList.length > 0) {
  1049. item.imageList.forEach((element) => {
  1050. imgList.push(`<img id="markerLabel" src="${element.image}"/>`);
  1051. });
  1052. } else {
  1053. imgList.push('暂无图片');
  1054. }
  1055. this.imgClick();
  1056. let smallLabel =
  1057. "<div class='info-details'>" +
  1058. "<h5 class='marker-title'>" +
  1059. item.countyName +
  1060. '-' +
  1061. item.smallNumber +
  1062. '</h5>' +
  1063. "<div class='marker-content'>" +
  1064. '<div>' +
  1065. '<p>小班号:' +
  1066. item.smallNumber +
  1067. '</p>' +
  1068. '<p>样地数:' +
  1069. item.sampleCount +
  1070. '</p>' +
  1071. '<p>小班蓄积量:' +
  1072. item.smallClassStock +
  1073. '(立方米)' +
  1074. '</p>' +
  1075. '<p>小班占地面积:' +
  1076. item.landArea +
  1077. '(亩)' +
  1078. '</p>' +
  1079. '<p>小班树种组成:' +
  1080. item.treeComp +
  1081. '</p>' +
  1082. '<p>地类:' +
  1083. item.landType +
  1084. '</p>' +
  1085. '<p>林地权属:' +
  1086. item.landOwner +
  1087. '</p>' +
  1088. '<p>林木权属:' +
  1089. item.forestOwner +
  1090. '</p>' +
  1091. '<p>林种:' +
  1092. item.forestClass +
  1093. '</p>' +
  1094. '<p>树种结构:' +
  1095. item.treeStruct +
  1096. '</p>' +
  1097. '</div>' +
  1098. '<div>' +
  1099. '<p>起源:' +
  1100. item.origin +
  1101. '</p>' +
  1102. '<p>优势树种:' +
  1103. item.superTree +
  1104. '</p>' +
  1105. '<p>主要灌木名称:' +
  1106. item.shrubName +
  1107. '</p>' +
  1108. '<p>地貌:' +
  1109. item.landForm +
  1110. '</p>' +
  1111. '<p>海拔:' +
  1112. item.altitude +
  1113. '</p>' +
  1114. '<p>坡位:' +
  1115. item.slopePosit +
  1116. '</p>' +
  1117. '<p>坡向:' +
  1118. item.slopeDirect +
  1119. '</p>' +
  1120. '<p>坡形:' +
  1121. item.slopeForm +
  1122. '</p>' +
  1123. '<p>坡度:' +
  1124. item.slope +
  1125. '</p>' +
  1126. '<p>森林健康度:' +
  1127. item.forestHealth +
  1128. '</p>' +
  1129. '</div>' +
  1130. '</div>' +
  1131. '<div class="imgList">' +
  1132. "<span class='marker-span'>图片:</span>" +
  1133. '<div class="marker-imgs">' +
  1134. imgList +
  1135. '</div>' +
  1136. '</div>' +
  1137. '</div>';
  1138. that.smallMarker = new AMap.Marker({
  1139. map: that.map,
  1140. position: lanLatArr,
  1141. icon: require('@/assets/img/small-marker.png'),
  1142. anchor: 'bottom-center',
  1143. offset: new AMap.Pixel(-5, -6)
  1144. });
  1145. that.smallMarker.setLabel({
  1146. direction: 'right',
  1147. offset: new AMap.Pixel(-230, -160), //设置文本标注偏移量
  1148. content: smallLabel //设置文本标注内容
  1149. });
  1150. // that.smallMarker.setMap(that.map);
  1151. that.smallMarkers.push(that.smallMarker);
  1152. smallClassPolygon.setOptions({
  1153. fillOpacity: 0.7,
  1154. fillColor: 'yellow'
  1155. });
  1156. });
  1157. smallClassPolygon.on('mouseout', () => {
  1158. smallClassPolygon.setOptions({
  1159. fillOpacity: 0,
  1160. fillColor: '#ccebc5'
  1161. });
  1162. });
  1163. }
  1164. if (item.longitude && item.latitude) {
  1165. var lanLatArr = [];
  1166. lanLatArr = [item.longitude, item.latitude];
  1167. if (
  1168. this.$store.state.addr.mapLevel == 'district' ||
  1169. this.$store.state.addr.mapLevel == 'street'
  1170. ) {
  1171. this.smallClassN = new AMap.Text({
  1172. map: this.map,
  1173. position: lanLatArr,
  1174. text: item.smallNumber,
  1175. anchor: 'bottom-center',
  1176. offset: new AMap.Pixel(0, 8),
  1177. style: {
  1178. 'background-color': 'transparent',
  1179. border: 'none',
  1180. color: '#05dfff',
  1181. fontSize: '12px'
  1182. }
  1183. });
  1184. this.smallClassNArr.push(this.smallClassN);
  1185. }
  1186. }
  1187. // this.map.add(that.smallClassPolygon);
  1188. // });
  1189. }
  1190. },
  1191. imgClick() {
  1192. document.getElementsByTagName('div')[0].addEventListener('click', (e) => {
  1193. if (e.target.id === 'markerLabel') {
  1194. this.imgDialogVisible = true;
  1195. this.dialogImageUrl = e.target.currentSrc;
  1196. }
  1197. });
  1198. },
  1199. // 获取样地数据
  1200. getForestSample(page) {
  1201. forestSample({
  1202. cityId: this.$store.state.addr.selectCity.areaId,
  1203. countyId: this.$store.state.addr.selectDistrict.areaId
  1204. // townId: this.$store.state.addr.selectStreet.areaId
  1205. }).then((res) => {
  1206. let sampleMarker = require('@/assets/img/sample-marker.png');
  1207. let iconMeta = [28, 28];
  1208. this.setMarkers(res, sampleMarker, iconMeta, page);
  1209. });
  1210. },
  1211. // 添加地图标注(样地、树种)
  1212. setMarkers(res, sampleMarker, iconMeta, page) {
  1213. let _this = this;
  1214. if (this.forestMarker) {
  1215. this.forestMarker.setMap(null);
  1216. this.forestMarker = null;
  1217. }
  1218. this.markerData = res;
  1219. let iconMarker = sampleMarker;
  1220. let iconMetaSet = iconMeta;
  1221. let sampleIcon = new AMap.Icon({
  1222. size: new AMap.Size(iconMetaSet[0], iconMetaSet[1]), // 图标尺寸
  1223. image: iconMarker,
  1224. imageSize: new AMap.Size(iconMetaSet[0], iconMetaSet[1]) // 根据所设置的大小拉伸或压缩图片
  1225. });
  1226. this.markerData.rows.forEach((item) => {
  1227. let lngLat = [item.longitude, item.latitude];
  1228. if (item.longitude && item.latitude) {
  1229. this.forestMarker = new AMap.Marker({
  1230. map: _this.map,
  1231. position: lngLat,
  1232. icon: sampleIcon,
  1233. anchor: 'bottom-center',
  1234. offset: new AMap.Pixel(0, -18)
  1235. });
  1236. if (page === 'forest') {
  1237. this.forestMarker.setLabel({
  1238. direction: 'right',
  1239. offset: new AMap.Pixel(-8, 0), //设置文本标注偏移量
  1240. content: `<div style="color:#05dfff">${item.smallNumber}-${item.sampleNumber}</div>` //设置文本标注内容
  1241. });
  1242. let clickLabel =
  1243. "<div class='info-small'>" +
  1244. "<h5 class='marker-title'>" +
  1245. item.smallNumber +
  1246. '-' +
  1247. item.sampleNumber +
  1248. '</h5>' +
  1249. "<div class='marker-content'>" +
  1250. '<p>样地号:' +
  1251. item.sampleNumber +
  1252. '</p>' +
  1253. '<p>所属小班:' +
  1254. item.smallNumber +
  1255. '</p>' +
  1256. '<p>样地蓄积:' +
  1257. item.landStock +
  1258. '</p>' +
  1259. '<p>样地株数:' +
  1260. item.landNumber +
  1261. '</p>' +
  1262. '</div>' +
  1263. '</div>';
  1264. let lastMarker = new AMap.Marker({
  1265. position: lngLat,
  1266. icon: sampleIcon,
  1267. anchor: 'bottom-center',
  1268. offset: new AMap.Pixel(0, -18)
  1269. });
  1270. lastMarker.setLabel({
  1271. zIndex: 120,
  1272. direction: 'top',
  1273. offset: new AMap.Pixel(-4, 0), //设置文本标注偏移量
  1274. content: clickLabel //设置文本标注内容
  1275. });
  1276. this.forestMarker.on('click', function (e) {
  1277. _this.map.add(lastMarker);
  1278. });
  1279. this.forestMarker.on('mouseout', function (e) {
  1280. _this.map.remove(lastMarker);
  1281. });
  1282. } else if (page === 'treeSpecies') {
  1283. this.forestMarker.setLabel({
  1284. direction: 'top',
  1285. offset: new AMap.Pixel(0, 8), //设置文本标注偏移量
  1286. content: `<div class="label-treecomp">${item.treeComp}<span class="smallH">${item.smallNumber}</span></div>` //设置文本标注内容
  1287. });
  1288. }
  1289. // this.map.add(this.forestMarker);
  1290. // forestMarker
  1291. this.forestMarkerArr.push(this.forestMarker);
  1292. }
  1293. });
  1294. },
  1295. addTreeSpeciesPolygon(item) {
  1296. let that = this;
  1297. // that.smallClassMapArr.forEach((item) => {
  1298. let polyData = JSON.parse(item.mapInfo);
  1299. for (let elementLs in polyData.features) {
  1300. let polygonColor = '';
  1301. this.treePlant.forEach((tree) => {
  1302. if (tree.plantName == item.superTree && item.superTree == '硬阔') {
  1303. polygonColor = '#00da85';
  1304. } else if (
  1305. tree.plantName == item.superTree &&
  1306. item.superTree == '软阔'
  1307. ) {
  1308. polygonColor = '#009bfd';
  1309. } else if (
  1310. tree.plantName == item.superTree &&
  1311. item.superTree == '杉木'
  1312. ) {
  1313. polygonColor = '#eca62d';
  1314. } else if (
  1315. tree.plantName == item.superTree &&
  1316. item.superTree == '马尾松'
  1317. ) {
  1318. polygonColor = '#b82dec';
  1319. }
  1320. });
  1321. let polygon = new AMap.Polygon({
  1322. map: that.map,
  1323. path: polyData.features[elementLs].geometry.coordinates,
  1324. strokeOpacity: 1,
  1325. fillOpacity: 0.6,
  1326. strokeColor: 'red',
  1327. strokeWeight: 2,
  1328. zIndex: 999,
  1329. cursor: 'pointer',
  1330. fillColor: polygonColor
  1331. });
  1332. this.treesPolygonArr.push(polygon);
  1333. if (item.longitude && item.latitude) {
  1334. var lanLatArr = [];
  1335. polygon.on('click', (e) => {
  1336. lanLatArr = [item.longitude, item.latitude];
  1337. let treeSmallLabel =
  1338. "<div class='info-small'>" +
  1339. "<h5 class='marker-title'>小班" +
  1340. item.smallNumber +
  1341. '</h5>' +
  1342. "<div class='marker-content'>" +
  1343. '<p>树种组成:' +
  1344. item.treeComp +
  1345. '</p>' +
  1346. '<p>树种结构:' +
  1347. item.treeStruct +
  1348. '</p>' +
  1349. '<p>优势树种:' +
  1350. item.superTree +
  1351. '</p>' +
  1352. '<p>优势树种平均胸径:' +
  1353. item.superTreeDbh +
  1354. '厘米' +
  1355. '</p>' +
  1356. '<p>优势树种平均高:' +
  1357. item.superTreeHigh +
  1358. '米' +
  1359. '</p>' +
  1360. '<p>位置:' +
  1361. item.countyName +
  1362. item.townName +
  1363. item.villageName +
  1364. '</p>' +
  1365. '</div>' +
  1366. '</div>';
  1367. that.smallMarker = new AMap.Marker({
  1368. map: that.map,
  1369. position: lanLatArr,
  1370. icon: require('@/assets/img/small-marker.png'),
  1371. anchor: 'bottom-center',
  1372. offset: new AMap.Pixel(0, 0)
  1373. });
  1374. that.smallMarker.setLabel({
  1375. direction: 'top',
  1376. offset: new AMap.Pixel(-10, 0), //设置文本标注偏移量
  1377. content: treeSmallLabel //设置文本标注内容
  1378. });
  1379. that.treeCompMarkers.push(that.smallMarker);
  1380. });
  1381. that.map.on('rightclick', function (e) {
  1382. if (that.treeCompMarkers.length > 0) {
  1383. that.map.remove(that.treeCompMarkers);
  1384. }
  1385. });
  1386. }
  1387. }
  1388. // });
  1389. },
  1390. // 获取小班列表
  1391. getRightScrollData(page) {
  1392. rightScrollData({
  1393. cityId: this.$store.state.addr.selectCity.areaId,
  1394. countyId: this.$store.state.addr.selectDistrict.areaId
  1395. // townId: this.$store.state.addr.selectStreet.areaId
  1396. }).then((res) => {
  1397. let sampleMarker = require('@/assets/img/sanjiaod.png');
  1398. let iconMeta = [16, 10];
  1399. this.setMarkers(res, sampleMarker, iconMeta, page);
  1400. });
  1401. },
  1402. // 事件信息
  1403. getEven() {
  1404. let _this = this;
  1405. alarmDataApi().then((res) => {
  1406. res.data.forEach((item) => {
  1407. let lanLatArr = [item.longitude, item.latitude];
  1408. let baseIcon = '';
  1409. let fireIcon = require('@/assets/img/fire.png');
  1410. let cutTreeIcon = require('@/assets/img/cutTree.png');
  1411. let insectpestIcon = require('@/assets/img/insectpest.png');
  1412. if (item.eventType == 1) {
  1413. item.eventContLabel = '火灾';
  1414. baseIcon = fireIcon;
  1415. } else if (item.eventType == 2) {
  1416. item.eventContLabel = '砍伐';
  1417. baseIcon = cutTreeIcon;
  1418. } else if (item.eventType == 3) {
  1419. item.eventContLabel = '病虫害';
  1420. baseIcon = insectpestIcon;
  1421. }else if (item.eventType == 4) {
  1422. item.eventContLabel = '偷盗林木';
  1423. baseIcon = cutTreeIcon;
  1424. }
  1425. _this.smallMarker = new AMap.Marker({
  1426. map: _this.map,
  1427. position: lanLatArr,
  1428. icon: baseIcon,
  1429. anchor: 'bottom-center',
  1430. offset: new AMap.Pixel(0, 0),
  1431. zIndex: 999
  1432. });
  1433. _this.eventMarkersArr.push(_this.smallMarker);
  1434. _this.smallMarker.on('click', function (e) {
  1435. let treeSmallLabel =
  1436. "<div class='info-small'>" +
  1437. "<h5 class='marker-title'>最新事件" +
  1438. '</h5>' +
  1439. "<div class='marker-content'>" +
  1440. '<p>事件类型:' +
  1441. item.eventContLabel +
  1442. '</p>' +
  1443. '<p>上报时间:' +
  1444. item.createTime +
  1445. '</p>' +
  1446. '<p>上报人:' +
  1447. item.createBy +
  1448. '</p>' +
  1449. '<p>位置:' +
  1450. item.cityName +
  1451. item.countyName +
  1452. item.townName +
  1453. item.villageName +
  1454. '</p>' +
  1455. '</div>' +
  1456. '</div>';
  1457. _this.eventMarker = new AMap.Marker({
  1458. position: lanLatArr,
  1459. icon: baseIcon,
  1460. anchor: 'bottom-center',
  1461. offset: new AMap.Pixel(0, 0),
  1462. zIndex: 999
  1463. });
  1464. _this.eventMarker.setLabel({
  1465. direction: 'top',
  1466. offset: new AMap.Pixel(-10, 0), //设置文本标注偏移量
  1467. content: treeSmallLabel //设置文本标注内容
  1468. });
  1469. _this.map.add(_this.eventMarker);
  1470. });
  1471. _this.smallMarker.on('mouseout', function (e) {
  1472. if (!_this.eventMarker) {
  1473. return;
  1474. } else {
  1475. _this.map.remove(_this.eventMarker);
  1476. }
  1477. });
  1478. });
  1479. });
  1480. },
  1481. // 林业经济
  1482. getEconomics() {
  1483. let _this = this;
  1484. financeBasePlant({
  1485. cityId: this.$store.state.addr.selectCity.areaId,
  1486. countyId: this.$store.state.addr.selectDistrict.areaId
  1487. // townId: this.$store.state.addr.selectStreet.areaId
  1488. }).then((res) => {
  1489. let economicsList = [];
  1490. let baseList = [];
  1491. res.rows.forEach((element) => {
  1492. economicsList.push({
  1493. longitude: element.cateLongitude,
  1494. latitude: element.cateLatitude,
  1495. icon: element.image
  1496. });
  1497. baseList.push({
  1498. baseId: element.baseId,
  1499. baseName: element.baseName,
  1500. longitude: element.baseLongitude,
  1501. latitude: element.baseLatitude
  1502. });
  1503. });
  1504. economicsList.forEach((item) => {
  1505. let lanLatArr = [item.longitude, item.latitude];
  1506. let beeIcon = item.icon;
  1507. let iconMeta = [82, 26];
  1508. let sampleIcon = new AMap.Icon({
  1509. size: new AMap.Size(iconMeta[0], iconMeta[1]), // 图标尺寸
  1510. image: beeIcon,
  1511. imageSize: new AMap.Size(iconMeta[0], iconMeta[1]) // 根据所设置的大小拉伸或压缩图片
  1512. });
  1513. this.smallMarker = new AMap.Marker({
  1514. map: _this.map,
  1515. position: lanLatArr,
  1516. icon: sampleIcon,
  1517. anchor: 'bottom-center',
  1518. offset: new AMap.Pixel(0, 0)
  1519. });
  1520. this.economicsArr.push(this.smallMarker);
  1521. // this.smallMarker.setMap(this.map);
  1522. });
  1523. baseList.forEach((element) => {
  1524. let lanLatArr = [element.longitude, element.latitude];
  1525. let baseIcon = require('@/assets/img/postion.png');
  1526. let iconMeta = [20, 29];
  1527. let sampleIcon = new AMap.Icon({
  1528. size: new AMap.Size(iconMeta[0], iconMeta[1]), // 图标尺寸
  1529. image: baseIcon,
  1530. imageSize: new AMap.Size(iconMeta[0], iconMeta[1]) // 根据所设置的大小拉伸或压缩图片
  1531. });
  1532. this.baseMarker = new AMap.Marker({
  1533. map: this.map,
  1534. position: lanLatArr,
  1535. icon: sampleIcon,
  1536. anchor: 'bottom-center',
  1537. offset: new AMap.Pixel(0, 0)
  1538. });
  1539. this.baseMarker.setLabel({
  1540. direction: 'right',
  1541. offset: new AMap.Pixel(0, 0), //设置文本标注偏移量
  1542. content: `<div>${element.baseName}</div>` //设置文本标注内容
  1543. });
  1544. this.baseMarkerArr.push(this.baseMarker);
  1545. this.baseMarker.on('click', function (e) {
  1546. financeBaseDetail({ baseId: element.baseId }).then((res) => {
  1547. if (res.code == 200) {
  1548. let treeSmallLabel =
  1549. "<div class='info-small'>" +
  1550. "<h5 class='marker-title'>" +
  1551. res.data.baseName +
  1552. '</h5>' +
  1553. "<div class='marker-content'>" +
  1554. '<p>基地名称:' +
  1555. res.data.baseName +
  1556. '</p>' +
  1557. '<p>种植/养殖/加工作物:' +
  1558. res.data.cropName +
  1559. '</p>' +
  1560. '<p>占地面积:' +
  1561. res.data.baseArea +
  1562. '亩' +
  1563. '</p>' +
  1564. '<p>位置:' +
  1565. res.data.cityName +
  1566. res.data.countyName +
  1567. res.data.townName +
  1568. '</p>' +
  1569. '</div>' +
  1570. '</div>';
  1571. _this.baseMarker.setLabel({
  1572. direction: 'top',
  1573. offset: new AMap.Pixel(0, 0), //设置文本标注偏移量
  1574. content: treeSmallLabel //设置文本标注内容
  1575. });
  1576. }
  1577. });
  1578. });
  1579. this.baseMarker.on('mouseout', function (e) {
  1580. _this.baseMarker.setLabel({
  1581. direction: 'right',
  1582. offset: new AMap.Pixel(0, 0), //设置文本标注偏移量
  1583. content: `<div>${element.baseName}</div>` //设置文本标注内容
  1584. });
  1585. });
  1586. });
  1587. });
  1588. },
  1589. getTreePlant() {
  1590. treePlant().then((res) => {
  1591. this.treePlant = res.rows;
  1592. });
  1593. }
  1594. }
  1595. };
  1596. </script>
  1597. <style lang='scss' scoped>
  1598. #container {
  1599. width: 100%;
  1600. height: 100vh;
  1601. /deep/ .tdt-pane {
  1602. z-index: auto;
  1603. }
  1604. }
  1605. /deep/ .amap-marker-content {
  1606. .tipMarker {
  1607. color: #555;
  1608. background-color: rgba(255, 254, 239, 0.8);
  1609. border: 1px solid #7e7e7e;
  1610. padding: 2px 6px;
  1611. font-size: 12px;
  1612. white-space: nowrap;
  1613. display: inline-block;
  1614. &:before,
  1615. &:after {
  1616. content: '';
  1617. display: block;
  1618. position: absolute;
  1619. margin: auto;
  1620. width: 0;
  1621. height: 0;
  1622. border: solid transparent;
  1623. border-width: 5px 5px;
  1624. }
  1625. &.top {
  1626. transform: translate(-50%, -110%);
  1627. &:before,
  1628. &:after {
  1629. bottom: -9px;
  1630. left: 0;
  1631. right: 0;
  1632. border-top-color: rgba(255, 254, 239, 0.8);
  1633. }
  1634. &:before {
  1635. bottom: -10px;
  1636. border-top-color: #7e7e7e;
  1637. }
  1638. }
  1639. }
  1640. }
  1641. /deep/ .amap-logo,
  1642. .amap-copyright {
  1643. display: block !important;
  1644. visibility: inherit !important;
  1645. }
  1646. /deep/ .amap-icon img {
  1647. max-width: 3rem !important;
  1648. max-height: 3rem !important;
  1649. }
  1650. /deep/ .info-small {
  1651. background-image: url('../assets/img/small-label.png');
  1652. background-repeat: no-repeat;
  1653. background-size: 100% 100%;
  1654. width: 18rem;
  1655. // height: 10rem;
  1656. color: #fff;
  1657. .marker-title {
  1658. margin: 0 auto;
  1659. line-height: 30px;
  1660. }
  1661. .marker-content {
  1662. padding: 0 20px 10px 20px;
  1663. p {
  1664. text-align: left;
  1665. font-size: 12px;
  1666. margin: 0;
  1667. line-height: 28px;
  1668. }
  1669. }
  1670. }
  1671. /deep/ .info-details {
  1672. background-image: url('../assets/img/small-label.png');
  1673. background-repeat: no-repeat;
  1674. background-size: 100% 100%;
  1675. width: 26rem;
  1676. padding-bottom: 13px;
  1677. // height: 10rem;
  1678. color: #fff;
  1679. .marker-title {
  1680. margin: 0 auto;
  1681. line-height: 50px;
  1682. }
  1683. .marker-content {
  1684. display: flex;
  1685. justify-content: space-between;
  1686. padding: 0 20px 0 20px;
  1687. .marker-span {
  1688. display: block;
  1689. }
  1690. p {
  1691. text-align: left;
  1692. font-size: 12px;
  1693. margin: 0;
  1694. line-height: 18px;
  1695. }
  1696. }
  1697. .imgList {
  1698. display: block;
  1699. text-align: left;
  1700. padding: 0 20px;
  1701. .marker-span {
  1702. display: block;
  1703. }
  1704. .marker-imgs {
  1705. display: block;
  1706. line-height: 18px !important;
  1707. width: 376px;
  1708. overflow: auto;
  1709. img {
  1710. width: 40px;
  1711. height: 40px;
  1712. margin: 0 4px;
  1713. cursor: pointer;
  1714. }
  1715. }
  1716. .marker-imgs::-webkit-scrollbar {
  1717. background: transparent;
  1718. opacity: 0.6px;
  1719. width: 10px;
  1720. height: 8px;
  1721. }
  1722. .marker-imgs::-webkit-scrollbar-thumb {
  1723. background: rgba($color: #07a2eb8e, $alpha: 0.6);
  1724. border-radius: 20px;
  1725. -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  1726. }
  1727. .marker-imgs::-webkit-scrollbar-track {
  1728. /*滚动条里面轨道*/
  1729. -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  1730. border-radius: 10px;
  1731. background: transparent;
  1732. }
  1733. }
  1734. }
  1735. /deep/ .amap-marker-label {
  1736. border: 0;
  1737. background-color: transparent;
  1738. }
  1739. #mask {
  1740. width: 100%;
  1741. height: 100vh;
  1742. box-shadow: inset 0px 0px 10vw 8vw rgba(0, 10, 34, 0.54);
  1743. position: fixed;
  1744. left: 0;
  1745. right: 0;
  1746. bottom: 0;
  1747. top: 0;
  1748. pointer-events: none;
  1749. }
  1750. @keyframes imageAnimation_32630606 {
  1751. 0% {
  1752. // opacity: 0;
  1753. transform: none;
  1754. }
  1755. 34% {
  1756. // opacity: 1;
  1757. transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg) scaleX(1) scaleY(1)
  1758. translate3d(34vw, 0px, 0px);
  1759. }
  1760. 67% {
  1761. // opacity: 1;
  1762. transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg) scaleX(1) scaleY(1)
  1763. translate3d(67vw, 0px, 0px);
  1764. }
  1765. 100% {
  1766. // opacity: 0;
  1767. transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg) scaleX(1) scaleY(1)
  1768. translate3d(160vw, 0px, 0px);
  1769. }
  1770. }
  1771. .yun-wrap {
  1772. position: fixed;
  1773. left: 0;
  1774. top: 350px;
  1775. width: 100vw;
  1776. pointer-events: none;
  1777. }
  1778. .yun {
  1779. position: fixed;
  1780. left: -500px;
  1781. animation-name: imageAnimation_32630606;
  1782. animation-iteration-count: infinite;
  1783. animation-timing-function: linear;
  1784. animation-duration: 110s;
  1785. animation-delay: 0s;
  1786. -webkit-user-drag: none;
  1787. filter: none;
  1788. pointer-events: none;
  1789. }
  1790. .yun2 {
  1791. bottom: 20px;
  1792. animation-duration: 90s;
  1793. animation-delay: 10s;
  1794. }
  1795. .yun3 {
  1796. top: 100px;
  1797. animation-duration: 120s;
  1798. animation-delay: 15s;
  1799. }
  1800. /deep/ .label-treecomp {
  1801. position: relative;
  1802. background-color: #05dfff;
  1803. color: #fff;
  1804. padding: 6px 10px;
  1805. border-radius: 8px;
  1806. font-size: 14px;
  1807. text-align: center;
  1808. &::before {
  1809. position: absolute;
  1810. top: 26px;
  1811. left: 42%;
  1812. content: '';
  1813. width: 0px;
  1814. height: 0px;
  1815. border: 6px solid transparent;
  1816. border-top-color: #05dfff;
  1817. }
  1818. .smallH {
  1819. position: absolute;
  1820. top: 34px;
  1821. z-index: 99;
  1822. display: block;
  1823. color: #05dfff;
  1824. text-align: center;
  1825. font-size: 14px;
  1826. // left: 38%;
  1827. left: 0;
  1828. width: 100%;
  1829. }
  1830. }
  1831. </style>