indexMap.vue 6.5 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. // debugger
  107. // // 已载入高德地图API,则直接初始化地图
  108. // if (window.AMap && window.AMapUI && window.Loca) {
  109. // this.loadmap()
  110. // // 未载入高德地图API,则先载入API再初始化
  111. // } else {
  112. // this.remoteLoad()
  113. // // await remoteLoad(`https://webapi.amap.com/maps?v=2.0&key=211dd6f989e719022aaf47ddb0659c47&plugin=AMap.Scale,AMap.ToolBar`)
  114. // // await remoteLoad('https://webapi.amap.com/loca?v=2.0.0&key=211dd6f989e719022aaf47ddb0659c47')
  115. // }
  116. },
  117. mounted() {
  118. AMapLoader.reset();
  119. delete window.AMap;
  120. AMapLoader.load({
  121. "key": "211dd6f989e719022aaf47ddb0659c47", // 申请好的Web端开发者Key,首次调用 load 时必填
  122. "version": "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
  123. "plugins": ['plugin=AMap.Scale', 'AMap.ToolBar'],
  124. "Loca": { // 是否加载 Loca, 缺省不加载
  125. "version": '2.0.0' // Loca 版本,缺省 1.3.2
  126. },
  127. }).then((AMap) => {
  128. this.loadmap()
  129. }).catch(e => {
  130. console.log(e);
  131. })
  132. },
  133. methods: {
  134. loadmap(val) {
  135. var map = new AMap.Map('mapContainer', {
  136. zoom: 5.29,
  137. showLabel: false,
  138. viewMode: '3D',
  139. pitch: 48,
  140. center: [104.780269, 34.955403],
  141. mapStyle: 'amap://styles/dark',
  142. });
  143. var loca = new Loca.Container({
  144. map,
  145. });
  146. // 颜色配置
  147. var headColors = ['#ECFFB1', '#146968', '#146968', '#146968', '#146968', '#146968', '#146968', '#146968'];
  148. var trailColors = [
  149. 'rgba(255,178,6, 0.2)',
  150. 'rgba(255,178,6, 0.2)',
  151. 'rgba(20,105,104, 0.2)',
  152. 'rgba(20,105,104, 0.2)',
  153. 'rgba(20,105,104, 0.2)',
  154. 'rgba(20,105,104, 0.2)',
  155. 'rgba(20,105,104, 0.2)',
  156. 'rgba(20,105,104, 0.2)',
  157. ];
  158. // 进入北京方向的线
  159. var inLineSource = new Loca.GeoJSONSource({
  160. url: 'https://a.amap.com/Loca/static/loca-v2/demos/mock_data/data-line-in.json',
  161. });
  162. var inLinelayer = new Loca.PulseLineLayer({
  163. // loca,
  164. zIndex: 11,
  165. opacity: 1,
  166. visible: true,
  167. zooms: [2, 22],
  168. });
  169. inLinelayer.setStyle({
  170. altitude: 0,
  171. lineWidth: (_, feature) => feature.properties.lineWidthRatio * 4 + 1,
  172. headColor: (_, feature) => headColors[feature.properties.type],
  173. trailColor: (_, feature) => trailColors[feature.properties.type],
  174. interval: 0.5,
  175. duration: 2000,
  176. });
  177. inLinelayer.setSource(inLineSource);
  178. loca.add(inLinelayer);
  179. // 出北京方向的线
  180. var outLineSource = new Loca.GeoJSONSource({
  181. url: 'https://a.amap.com/Loca/static/loca-v2/demos/mock_data/data-line-out.json',
  182. });
  183. var outLinelayer = new Loca.PulseLineLayer({
  184. // loca,
  185. zIndex: 11,
  186. opacity: 1,
  187. visible: true,
  188. zooms: [2, 22],
  189. });
  190. outLinelayer.setStyle({
  191. altitude: 0,
  192. lineWidth: (_, feature) => feature.properties.lineWidthRatio * 1 + 3,
  193. headColor: (_, feature) => headColors[feature.properties.type],
  194. trailColor: (_, feature) => trailColors[feature.properties.type],
  195. interval: 0.25,
  196. duration: 5000,
  197. });
  198. outLinelayer.setSource(outLineSource);
  199. loca.add(outLinelayer);
  200. // 下方呼吸点层
  201. var scatter = new Loca.ScatterLayer({
  202. loca,
  203. zIndex: 10,
  204. opacity: 1,
  205. visible: true,
  206. zooms: [2, 22],
  207. });
  208. var scatterGeo = new Loca.GeoJSONSource({
  209. url: 'https://a.amap.com/Loca/static/loca-v2/demos/mock_data/data-scatter.json',
  210. });
  211. scatter.setSource(scatterGeo);
  212. scatter.setStyle({
  213. unit: 'px',
  214. size: (_, feature) => {
  215. var size = feature.properties.lineWidthRatio * 2 + 30;
  216. return [size, size];
  217. },
  218. borderWidth: 0,
  219. texture: 'https://a.amap.com/Loca/static/loca-v2/demos/images/breath_yellow.png',
  220. duration: 2000,
  221. animate: true,
  222. });
  223. loca.add(scatter);
  224. loca.animate.start();
  225. }
  226. },
  227. }
  228. </script>