indexMap.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <style lang='scss' scoped>
  2. .mapContent {
  3. position: relative;
  4. margin-top: 10px;
  5. .center-add {
  6. position: absolute;
  7. top: 0;
  8. bottom: 0;
  9. left: 0;
  10. right: 0;
  11. margin: auto;
  12. z-index: 999;
  13. width: 30px;
  14. height: 30px;
  15. }
  16. }
  17. #mapContainer {
  18. width: 100%;
  19. height: 506px;
  20. }
  21. #tip {
  22. position: absolute;
  23. top: -45px;
  24. display: flex;
  25. }
  26. #tip .el-input {
  27. // width: 179px;
  28. margin-right: 0px;
  29. }
  30. #tip .el-select {
  31. margin-right: 10px;
  32. }
  33. #tip .el-select {
  34. width: 179px;
  35. }
  36. #tip .el-textarea {
  37. width: 179px;
  38. /deep/ .el-textarea__inner {
  39. height: 40px;
  40. resize: none;
  41. }
  42. }
  43. .el-button--primary {
  44. background-color: #5878e8;
  45. border-color: #5878e8;
  46. }
  47. .el-button--default {
  48. color: #5878e8;
  49. border-color: #5473e8;
  50. }
  51. .address {
  52. display: flex;
  53. align-items: center;
  54. margin-right: 20px;
  55. // position:absolute;
  56. // top: -35px;
  57. .address-input {
  58. display: inline-block;
  59. width: 480px;
  60. }
  61. }
  62. </style>
  63. <template>
  64. <div class="mapContent">
  65. <div id="mapContainer"></div>
  66. </div>
  67. </template>
  68. <script>
  69. import {
  70. regionData,
  71. CodeToText,
  72. TextToCode
  73. } from 'element-china-area-data'
  74. import image from '../../../public/img/ic_locationmarker.jpg'
  75. import AMapLoader from '@amap/amap-jsapi-loader';
  76. export default {
  77. data() {
  78. return {
  79. map: null,
  80. provinces: [],
  81. province: '',
  82. districts: [],
  83. district: '',
  84. citys: [],
  85. city: '',
  86. polygons: [],
  87. selectedOptions1: [],
  88. areacode: '',
  89. address: '',
  90. objPoint: [],
  91. markers: [],
  92. zoomEnable: true,
  93. dragEnable: true,
  94. status: true,
  95. center: '',
  96. }
  97. },
  98. props: ['flagVisible', 'position', 'selectedOptions', 'isShowaddress', 'type'],
  99. computed: {
  100. showFlag() {
  101. return this.flagVisible
  102. },
  103. },
  104. watch: {},
  105. async created() {
  106. // // 已载入高德地图API,则直接初始化地图
  107. // if (window.AMap && window.AMapUI && window.Loca) {
  108. // this.loadmap()
  109. // // 未载入高德地图API,则先载入API再初始化
  110. // } else {
  111. // this.remoteLoad()
  112. // // await remoteLoad(`https://webapi.amap.com/maps?v=2.0&key=211dd6f989e719022aaf47ddb0659c47&plugin=AMap.Scale,AMap.ToolBar`)
  113. // // await remoteLoad('https://webapi.amap.com/loca?v=2.0.0&key=211dd6f989e719022aaf47ddb0659c47')
  114. // }
  115. },
  116. mounted() {
  117. AMapLoader.reset();
  118. AMapLoader.load({
  119. "key": "211dd6f989e719022aaf47ddb0659c47", // 申请好的Web端开发者Key,首次调用 load 时必填
  120. "version": "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
  121. "plugins": ['plugin=AMap.Scale', 'AMap.ToolBar'],
  122. "Loca": { // 是否加载 Loca, 缺省不加载
  123. "version": '2.0.0' // Loca 版本,缺省 1.3.2
  124. },
  125. }).then((AMap) => {
  126. this.loadmap()
  127. }).catch(e => {
  128. console.log(e);
  129. })
  130. },
  131. methods: {
  132. loadmap(val) {
  133. var map = new AMap.Map('mapContainer', {
  134. zoom: 5.29,
  135. showLabel: true,
  136. viewMode: '3D',
  137. pitch: 0, //地圖仰角
  138. center: [104.780269, 34.955403],
  139. mapStyle: 'amap://styles/dark',
  140. buildingAnimation: false,
  141. showIndoorMap: false,
  142. });
  143. var loca = new Loca.Container({
  144. map,
  145. });
  146. // 呼吸点
  147. var scatter = new Loca.ScatterLayer({
  148. loca,
  149. zIndex: 10,
  150. opacity: 0.6,
  151. visible: true,
  152. zooms: [2, 22],
  153. });
  154. var pointGeo = new Loca.GeoJSONSource({
  155. url: 'https://a.amap.com/Loca/static/loca-v2/demos/mock_data/pulselink-china-city-point.json',
  156. });
  157. scatter.setSource(pointGeo);
  158. scatter.setStyle({
  159. unit: 'meter',
  160. size: [100000, 100000],
  161. borderWidth: 0,
  162. texture: 'https://a.amap.com/Loca/static/loca-v2/demos/images/breath_red.png',
  163. duration: 2000,
  164. animate: true,
  165. });
  166. loca.add(scatter);
  167. // 弧线
  168. var pulseLink = new Loca.PulseLinkLayer({
  169. // loca,
  170. zIndex: 10,
  171. opacity: 1,
  172. visible: true,
  173. zooms: [2, 22],
  174. depth: true,
  175. });
  176. var geo = new Loca.GeoJSONSource({
  177. url: 'https://a.amap.com/Loca/static/loca-v2/demos/mock_data/data-line-out.json',
  178. });
  179. pulseLink.setSource(geo);
  180. pulseLink.setStyle({
  181. unit: 'meter',
  182. dash: [40000, 0, 40000, 0],
  183. lineWidth: function () {
  184. return [20000, 1000];
  185. },
  186. height: function (index, feat) {
  187. return feat.distance / 3 + 10;
  188. },
  189. // altitude: 1000,
  190. smoothSteps: 30,
  191. speed: function (index, prop) {
  192. return 1000 + Math.random() * 200000;
  193. },
  194. flowLength: 100000,
  195. lineColors: function (index, feat) {
  196. return ['#ebf0f700'];
  197. },
  198. maxHeightScale: 0.3, // 弧顶位置比例
  199. headColor: '#75d1f4',
  200. trailColor: 'rgba(255, 255,0,0)',
  201. });
  202. loca.add(pulseLink);
  203. loca.animate.start();
  204. // 点击事件处理
  205. var clickInfo = new AMap.Marker({
  206. anchor: 'bottom-center',
  207. position: [116.396923, 39.918203, 0],
  208. });
  209. clickInfo.setMap(map);
  210. clickInfo.hide();
  211. map.on("click", function (e) {
  212. var feat = pulseLink.queryFeature(e.pixel.toArray());
  213. if (feat) {
  214. clickInfo.show();
  215. var props = feat.properties;
  216. clickInfo.setPosition(feat.coordinates[1]);
  217. clickInfo.setContent(
  218. '<div style="text-align: center; height: 20px; width: 150px; color:#fff; font-size: 14px;">' +
  219. '速率: ' + feat.properties['ratio'] +
  220. '</div>'
  221. );
  222. } else {
  223. clickInfo.hide();
  224. }
  225. });
  226. }
  227. },
  228. }
  229. </script>