amap.vue 39 KB

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