indexMap.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. AMapLoader.reset();
  107. // debugger
  108. // 已载入高德地图API,则直接初始化地图
  109. if ( window.Loca) {
  110. this.loadmap()
  111. // 未载入高德地图API,则先载入API再初始化
  112. } else {
  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. this.remoteLoad()
  116. }
  117. },
  118. mounted() {
  119. this.loadmap()
  120. },
  121. methods: {
  122. remoteLoad(){
  123. // debugger
  124. // delete window.AMap;
  125. // let scriptElement1 = document.createElement('script')
  126. // scriptElement1.src =
  127. // "https://webapi.amap.com/maps?v=2.0&key=211dd6f989e719022aaf47ddb0659c47&plugin=AMap.Scale,AMap.ToolBar"
  128. // document.body.appendChild(scriptElement1)
  129. // let scriptElement2 = document.createElement('script')
  130. // scriptElement2.src = "https://webapi.amap.com/loca?v=2.0.0&key=211dd6f989e719022aaf47ddb0659c47"
  131. // document.body.appendChild(scriptElement2)
  132. // this.loadmap()
  133. // window.Loca = Loca
  134. // console.log(Loca)
  135. },
  136. loadmap(val) {
  137. AMapLoader.load({ //首次调用 load
  138. key:'211dd6f989e719022aaf47ddb0659c47',//首次load key为必填
  139. version:'2.0',
  140. Loca:{
  141. version: '2.0.0',
  142. }
  143. }).then((AMap)=>{
  144. map = new AMap.Map('mapContainer',{
  145. zoom: 5,
  146. });
  147. var layer = new Loca.PointLayer({
  148. map: map,
  149. });
  150. layer.setData(districts, {
  151. // 指定经纬度所在字段
  152. lnglat: 'center'
  153. });
  154. layer.setOptions({
  155. style: {
  156. // 圆形半径,单位像素
  157. radius: 15,
  158. // 填充颜色
  159. color: '#07E8E4',
  160. // 描边颜色
  161. borderColor: '#5DFBF9',
  162. // 描边宽度,单位像素
  163. borderWidth: 1,
  164. // 透明度 [0-1]
  165. opacity: 0.9,
  166. }
  167. });
  168. layer.render();
  169. }).catch((e)=>{
  170. console.log(e);
  171. });
  172. // setTimeout(() => {
  173. // // debugger
  174. // var map = new AMap.Map('mapContainer', {
  175. // zoom: 5.29,
  176. // // showLabel: false,
  177. // // viewMode: '3D',
  178. // pitch: 48,
  179. // center: [104.780269, 34.955403],
  180. // mapStyle: 'amap://styles/dark',
  181. // });
  182. // var loca = new Loca.Container({
  183. // map,
  184. // });
  185. // // 颜色配置
  186. // var headColors = ['#ECFFB1', '#146968', '#146968', '#146968', '#146968', '#146968', '#146968', '#146968'];
  187. // var trailColors = [
  188. // 'rgba(255,178,6, 0.2)',
  189. // 'rgba(255,178,6, 0.2)',
  190. // 'rgba(20,105,104, 0.2)',
  191. // 'rgba(20,105,104, 0.2)',
  192. // 'rgba(20,105,104, 0.2)',
  193. // 'rgba(20,105,104, 0.2)',
  194. // 'rgba(20,105,104, 0.2)',
  195. // 'rgba(20,105,104, 0.2)',
  196. // ];
  197. // // 进入北京方向的线
  198. // var inLineSource = new Loca.GeoJSONSource({
  199. // url: 'https://a.amap.com/Loca/static/loca-v2/demos/mock_data/data-line-in.json',
  200. // });
  201. // var inLinelayer = new Loca.PulseLineLayer({
  202. // // loca,
  203. // zIndex: 11,
  204. // opacity: 1,
  205. // visible: true,
  206. // zooms: [2, 22],
  207. // });
  208. // inLinelayer.setStyle({
  209. // altitude: 0,
  210. // lineWidth: (_, feature) => feature.properties.lineWidthRatio * 4 + 1,
  211. // headColor: (_, feature) => headColors[feature.properties.type],
  212. // trailColor: (_, feature) => trailColors[feature.properties.type],
  213. // interval: 0.5,
  214. // duration: 2000,
  215. // });
  216. // inLinelayer.setSource(inLineSource);
  217. // loca.add(inLinelayer);
  218. // // 出北京方向的线
  219. // var outLineSource = new Loca.GeoJSONSource({
  220. // url: 'https://a.amap.com/Loca/static/loca-v2/demos/mock_data/data-line-out.json',
  221. // });
  222. // var outLinelayer = new Loca.PulseLineLayer({
  223. // // loca,
  224. // zIndex: 11,
  225. // opacity: 1,
  226. // visible: true,
  227. // zooms: [2, 22],
  228. // });
  229. // outLinelayer.setStyle({
  230. // altitude: 0,
  231. // lineWidth: (_, feature) => feature.properties.lineWidthRatio * 1 + 3,
  232. // headColor: (_, feature) => headColors[feature.properties.type],
  233. // trailColor: (_, feature) => trailColors[feature.properties.type],
  234. // interval: 0.25,
  235. // duration: 5000,
  236. // });
  237. // outLinelayer.setSource(outLineSource);
  238. // loca.add(outLinelayer);
  239. // // 下方呼吸点层
  240. // var scatter = new Loca.ScatterLayer({
  241. // loca,
  242. // zIndex: 10,
  243. // opacity: 1,
  244. // visible: true,
  245. // zooms: [2, 22],
  246. // });
  247. // var scatterGeo = new Loca.GeoJSONSource({
  248. // url: 'https://a.amap.com/Loca/static/loca-v2/demos/mock_data/data-scatter.json',
  249. // });
  250. // scatter.setSource(scatterGeo);
  251. // scatter.setStyle({
  252. // unit: 'px',
  253. // size: (_, feature) => {
  254. // var size = feature.properties.lineWidthRatio * 2 + 30;
  255. // return [size, size];
  256. // },
  257. // borderWidth: 0,
  258. // texture: 'https://a.amap.com/Loca/static/loca-v2/demos/images/breath_yellow.png',
  259. // duration: 2000,
  260. // animate: true,
  261. // });
  262. // loca.add(scatter);
  263. // loca.animate.start();
  264. // }, 500)
  265. }
  266. },
  267. }
  268. </script>