amap.vue 49 KB

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