amapnow.vue 36 KB

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