Chargermap.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. <template>
  2. <view >
  3. <view id="container" :style="myStyle"></view>
  4. <u-icon name="map-fill" v-if="false" class="input-card" style="width: 24rem;top: 130px;width: 20px;height: 20px;" color="#999" size="40"></u-icon>
  5. </view>
  6. </template>
  7. <script>
  8. import MapLoader from '@/utils/AMap'
  9. let _self;
  10. function mapMovestart(e) {
  11. console.log('movestart')
  12. }
  13. function mapMove(e){
  14. //console.log('mapMove')
  15. }
  16. function mapMoveend(e){
  17. //let _self = e;
  18. let pos = _self.logMapInfo();
  19. _self.$emit('onMoveEnd',pos);
  20. // console.log('mapMoveend')
  21. }
  22. export default {
  23. name:"Chargermap",
  24. data() {
  25. return {
  26. myStyle:"width: 100%; height: 1200rpx;",
  27. chargerIcon:'',
  28. chargerSelectedIcon:'',
  29. positionIcon:'',
  30. personIcon:'',
  31. longitude: 112.276527,
  32. latitude: 30.306427,
  33. AMap:null,
  34. //车的位置
  35. car: {
  36. obj:null,
  37. longitude: '',
  38. latitude: '',
  39. },
  40. down: {
  41. obj:null,
  42. longitude: '',
  43. latitude: '',
  44. },
  45. up: {
  46. obj:null,
  47. longitude: '',
  48. latitude: '',
  49. },
  50. //个人
  51. info: {
  52. obj:null,
  53. init: false,
  54. longitude: '',
  55. latitude: '',
  56. },
  57. mapcharger:null,
  58. startend: [{
  59. longitude:112.279274,
  60. latitude:30.303273,
  61. name:''
  62. }, {
  63. longitude:112.273867,
  64. latitude:30.309817,
  65. name:''
  66. }],
  67. start:{},
  68. end:{},
  69. chargerList:[],
  70. covers: [
  71. {
  72. longitude:112.273867,
  73. latitude:30.309817,
  74. },{
  75. longitude:112.280261,
  76. latitude:30.3041,
  77. },{
  78. longitude:112.279274,
  79. latitude:30.303273,
  80. }
  81. ],
  82. };
  83. },
  84. methods:{
  85. /*
  86. getLocation1() {
  87. // console.log('getLocation');
  88. const self = this;
  89. AMap.plugin('AMap.Geolocation', function () {
  90. var geolocation = new AMap.Geolocation({
  91. // 是否使用高精度定位,默认:true
  92. enableHighAccuracy: true,
  93. // 设置定位超时时间,默认:无穷大
  94. timeout: 10000
  95. });
  96. geolocation.getCurrentPosition();
  97. AMap.event.addListener(geolocation, 'complete', onComplete);
  98. AMap.event.addListener(geolocation, 'error', onError);
  99. function onComplete (data) {
  100. // data是具体的定位信息
  101. self.$emit('location',data);
  102. console.log('定位成功信息:', data.addressComponent.city);
  103. self.city = data.addressComponent.city;
  104. }
  105. function onError (data) {
  106. // 定位出错
  107. // console.log('定位失败错误:', data);
  108. // 调用IP定位
  109. let ret = { position:{longitude: 112.28468,latitude: 30.307094}};
  110. self.$emit('location',ret);
  111. //self.getLngLatLocation();
  112. }
  113. });
  114. },
  115. // 通过IP获取当前位置
  116. getLngLatLocation () {
  117. const self = this;
  118. AMap.plugin('AMap.CitySearch', function () {
  119. var citySearch = new AMap.CitySearch();
  120. citySearch.getLocalCity(function (status, result) {
  121. if (status === 'complete' && result.info === 'OK') {
  122. // 查询成功,result即为当前所在城市信息
  123. //console.log('通过ip获取当前城市:', result);
  124. // 逆向地理编码
  125. AMap.plugin('AMap.Geocoder', function () {
  126. var geocoder = new AMap.Geocoder({
  127. // city 指定进行编码查询的城市,支持传入城市名、adcode 和 citycode
  128. city: result.adcode
  129. });
  130. var lnglat = result.rectangle.split(';')[0].split(',');
  131. geocoder.getAddress(lnglat, function (status, data) {
  132. if (status === 'complete' && data.info === 'OK') {
  133. // result为对应的地理位置详细信息
  134. //self.$emit('location',data);
  135. console.log('location'+JSON.stringify(data));
  136. }
  137. });
  138. });
  139. }
  140. });
  141. });
  142. }, */
  143. getPositionByLonLats(pos) {
  144. var _this = this;
  145. MapLoader().then(AMap => {
  146. var lnglatXY =//[_this.longitude, _this.latitude]
  147. [pos.longitude, pos.latitude];
  148. AMap.service('AMap.Geocoder', function() {
  149. let geocoder = new AMap.Geocoder({});
  150. geocoder.getAddress(lnglatXY, function(status, result) {
  151. console.log(lnglatXY);
  152. console.log(status, result);
  153. if (status === 'complete' && result.info === 'OK') {
  154. var address = result.regeocode.formattedAddress;
  155. console.log('当前位置'+JSON.stringify(lnglatXY)+address);
  156. //_this.message= address;
  157. } else {
  158. //_this.message= '无法获取定位';
  159. }
  160. });
  161. });
  162. }).catch(error => {
  163. console.log(error)
  164. })
  165. },
  166. calculateDistance(startLngLat,endLngLat){
  167. var _this = this;
  168. //var endLngLat = [item.longitude,item.latitude];
  169. return new Promise((resolve, reject) => {
  170. AMap.plugin('AMap.Driving', function() {
  171. var driving = new AMap.Driving({
  172. // 驾车路线规划策略,AMap.DrivingPolicy.LEAST_TIME是最快捷模式
  173. policy: AMap.DrivingPolicy.LEAST_TIME
  174. })
  175. driving.search(startLngLat, endLngLat, function (status, result) {
  176. resolve(result.routes[0])
  177. })
  178. /*
  179. var startLngLat2 = [_this.longitude, _this.latitude]
  180. var endLngLat2 = [_this.longitude2, _this.latitude2]
  181. driving.search(startLngLat2, endLngLat2, function (status, result) {
  182. console.log(result)
  183. console.log(result.routes[0].time)//秒
  184. console.log(result.routes[0].distance)//米
  185. uni.showToast({
  186. title:result.routes[0].time+"秒,"+result.routes[0].distance+"米"
  187. })
  188. })*/
  189. })
  190. })
  191. },
  192. calcDistances(startLngLat,endLst){
  193. var _this = this;
  194. console.log('endLst'+JSON.stringify(endLst));
  195. for(let i=0;i< endLst.length;i++)
  196. {
  197. let item = endLst[i];
  198. let endLngLat = [item.longitude,item.latitude]
  199. //if(endLst[i].distance == null){
  200. var lnglat = new AMap.LngLat(startLngLat[0],startLngLat[1]);
  201. var myDistance = lnglat.distance(endLngLat);
  202. //_self.stationDetail.station.distance = myDistance/1000;
  203. //_self.stationDetail.station.time = myDistance/500;
  204. endLst[i].distance = myDistance/1000.0;
  205. endLst[i].time = myDistance/500.0;
  206. /*}else{
  207. endLst[i].time = endLst[i].distance/500.0;
  208. }*/
  209. }
  210. /*
  211. AMap.plugin('AMap.Driving', function() {
  212. var driving = new AMap.Driving({
  213. // 驾车路线规划策略,AMap.DrivingPolicy.LEAST_TIME是最快捷模式
  214. policy: AMap.DrivingPolicy.LEAST_TIME
  215. })
  216. for(let i=0;i< endLst.length;i++)
  217. {
  218. let item = endLst[i];
  219. let endLngLat = [item.longitude,item.latitude]
  220. driving.search(startLngLat, endLngLat, function (status, result) {
  221. endLst[i].distance = result.routes[0].distance/1000.0;
  222. endLst[i].time = result.routes[0].time/60.0;
  223. })
  224. }
  225. }) */
  226. },
  227. updateCharger(pos){
  228. // console.log('更新充电桩1'+JSON.stringify(pos) )
  229. // let index = this.chargerList.findIndex(item => item.info.latitude === pos.latitude && item.info.longitude === pos.longitude);
  230. //let index = this.chargerList.findIndex(item => (Math.abs(item.info.longitude-pos.longitude)<0.000001 && Math.abs(item.info.longitude - pos.latitude)<0.000001));
  231. let index = this.chargerList.findIndex(item => item.info.id === pos.id);
  232. // console.log('更新充电桩['+ index + ']'+JSON.stringify(pos))
  233. let colorBg = '#00BAC8';//#00b962
  234. if(this.chargerList[index].info.type =='快充'){
  235. colorBg = '#8486FF'
  236. }else if(this.chargerList[index].info.type =='慢充'){
  237. colorBg = '#9d9fff'
  238. }
  239. // console.log('colorBg'+colorBg)
  240. // console.log('更新充电桩2'+JSON.stringify(this.chargerList[index].info))
  241. if(index>=0){
  242. let station_icon2 = "width: 100px;height: 36px;line-height: 20px;border-radius: 50px;background-color: " + colorBg +";text-align: center;display: flex;";
  243. let corner2=" width: 0;height: 0;position: absolute;top: 36px;left: 0;right: 0;margin: auto;border-bottom: 6px solid transparent;border-left: 6px solid transparent;border-right: 6px solid transparent;border-top: 8px solid " + colorBg +" ;";
  244. let content = "<div style='" + station_icon2 + "'>";
  245. content+="<div style='width: 36px;height: 36px;line-height: 36px;text-align: center;border: 1px solid " + colorBg +";border-radius: 999px;background-color: #fff;color: " + colorBg +";' class='iconfont'>&#xe606;</div>";
  246. content+="<div style='color: #ffffff;line-height: 14px;padding: 4px;font-size: 14px'>";
  247. content+="<div style='"+corner2+"'></div>";
  248. content+="<div class=''>";
  249. if(pos.price != null)
  250. content+= "¥" + pos.price.toString();
  251. if(pos.costPrice != null)
  252. content+= "¥" + pos.costPrice.toString();
  253. content+="</div>";
  254. content+="<div class=''>";
  255. if(pos.idleNum != null)
  256. content+="空闲" + pos.idleNum.toString();
  257. if(pos.availableNum != null)
  258. content+="空闲" + pos.availableNum.toString();
  259. content+="</div>"
  260. content+="</div>";
  261. content+="</div>";
  262. // console.log('找到充电桩[]'+content)
  263. //content = "<div style='height: 40px;width: 100px;display: flex;flex-direction: row; flex-wrap: wrap; background-color: #00B962!important;border-radius: 20px;'> <div><img src='"+this.chargerSelectedIcon+"' style='idth: 40px;height: 40px'></div><div style='display: flex;flex-direction:column;color:#FFFFFF;'><div style='margin-left:10px'>¥"+ pos.price +"</div><div style='margin-left:10px'>空闲"+pos.idleNum + "</div> </div></div>";
  264. this.chargerList[index].info.selected = true;
  265. this.chargerList[index].marker.setContent(content);
  266. }
  267. for(let i = 0;i < this.chargerList.length;i++){
  268. if(index == i)
  269. continue;
  270. if(this.chargerList[i].info.selected != null &&
  271. this.chargerList[i].info.selected)
  272. {
  273. let station_icon = "width: 36px;height: 36px;line-height: 36px;text-align: center;border: 1px solid " + colorBg +"; color: " + colorBg +"; border-radius: 999px;";
  274. let corner = "width: 0;height: 0;position: absolute;top: 34px;left: 0;right: 0;margin: auto;border-bottom: 4px solid transparent;border-left: 4px solid transparent;border-right: 4px solid transparent;border-top: 6px solid " + colorBg +" ;";
  275. let content = "<div style='"+station_icon+";background-color: #fff;' ><text class='iconfont' >&#xe606;</text><div style='" + corner+"'></div></div>"
  276. //let content = "<img src='"+this.chargerIcon+"' style='height: 40px;width: 40px' />";
  277. this.chargerList[i].marker.setContent(content);
  278. this.chargerList[i].info.selected = false;
  279. console.log('restore'+JSON.stringify(this.chargerList[i].info))
  280. }
  281. }
  282. },
  283. addCharger(pos) {
  284. let colorBg = '#00BAC8';//#00b962
  285. if(pos.type =='快充'){
  286. colorBg = '#8486FF'
  287. }else if(pos.type =='慢充'){
  288. colorBg = '#9d9fff'
  289. }
  290. // console.log('添加充电桩'+JSON.stringify(pos))
  291. //let content = "<div style='height: 40px;width: 100px;display: flex;flex-direction: row; flex-wrap: wrap; background-color: #00B962!important;border-radius: 20px;'> <div><img src='"+this.chargerIcon+"' style='idth: 40px;height: 40px'></div><div style='display: flex;flex-direction:column;color:#FFFFFF'><div>¥1.5</div><div>空闲10</div> </div></div>";
  292. let station_icon = "width: 36px;height: 36px;line-height: 36px;text-align: center;border: 1px solid "+ colorBg+"; color: "+ colorBg+"; border-radius: 999px;";
  293. let corner = "width: 0;height: 0;position: absolute;top: 34px;left: 0;right: 0;margin: auto;border-bottom: 4px solid transparent;border-left: 4px solid transparent;border-right: 4px solid transparent;border-top: 6px solid "+ colorBg+" ;";
  294. let content = "<div style='"+station_icon+";background:#fff;' ><text class='iconfont' >&#xe606;</text><div style='" + corner+"'></div></div>"
  295. let marker = new AMap.Marker({
  296. content: content,//"<img src='"+this.chargerIcon+"' style='height: 40px;width: 40px' />",
  297. //icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",
  298. position: [pos.longitude,pos.latitude],
  299. offset: new AMap.Pixel(-13, -30),
  300. zIndex:900,
  301. autoRotation: true,
  302. });
  303. marker.setMap(this.mapcharger);
  304. this.myEmit("charger",marker,pos)
  305. this.chargerList.push({marker:marker,info:pos});
  306. },
  307. addPerson(pos) {
  308. console.log('addPerson'+JSON.stringify(pos))
  309. let content = "<div style='background-color: rgba(22, 119, 255, 100);text-align: center; box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 0.4); border: 2px solid rgba(255, 255, 255, 100);border-radius: 999px;'>";
  310. content += "<div class='iconfont' style='color: #1677ff; font-size: 14px' >&#xe634;</div>";
  311. content += "</div>";
  312. let marker = new AMap.Marker({
  313. content: content,//"<div class='iconfont' style='color: #1677ff; font-size: 14px' >&#xe634;</div>",//<img src='"+this.personIcon+"' style='height: 40px;width: 40px' />",
  314. //content:"<div>xxxxxxxxxxxxxxxxxxxxxx</div>",
  315. //icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",
  316. position: [pos.longitude,pos.latitude],
  317. offset: new AMap.Pixel(-13, -30),
  318. zIndex:900,
  319. autoRotation: true,
  320. });
  321. marker.setMap(this.mapcharger);
  322. this.myEmit("person",marker,pos)
  323. //this.chargerList.push(marker)
  324. },
  325. /*
  326. addPosition() {
  327. console.log('addPosition'+JSON.stringify(pos))
  328. let marker = new AMap.Marker({
  329. content: "<img src='"+this.positionIcon+"' style='height: 40px;width: 40px' />",
  330. //icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",
  331. //position: [pos.longitude,pos.latitude],
  332. offset: new AMap.Pixel(20, 220),
  333. zIndex:900,
  334. autoRotation: true,
  335. });
  336. marker.setMap(this.mapcharger);
  337. //this.myEmit("person",marker,pos)
  338. //this.chargerList.push(marker)
  339. },*/
  340. setChargerList(sz){
  341. if(this.AMap==null){
  342. return
  343. }
  344. //this.getLocation();
  345. for(var i in this.chargerList){
  346. if(this.chargerList[i].marker){
  347. this.chargerList[i].marker.setMap(null);
  348. }
  349. this.mapcharger.remove(this.chargerList[i]);
  350. }
  351. this.chargerList=[]
  352. for(var i in sz){
  353. var ob=sz[i];
  354. this.addCharger(ob);
  355. /*var ob1 = new AMap.Marker({
  356. position: new AMap.LngLat(ob.longitude,ob.latitude), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
  357. title: '北京'
  358. });
  359. this.mapcharger.add(ob1);*/
  360. /*
  361. var ob1=new AMap.Marker({
  362. map: this.mapcharger,
  363. position: [ob.longitude,ob.latitude],
  364. //offset: new AMap.Pixel(-5, -5),
  365. //offset: new AMap.Pixel(-18, -40),
  366. content:"<img src='"+icon0+"' style='height: 40px;width: 40px' />",
  367. title:'test111111111111111',
  368. zIndex:900,
  369. autoRotation: true,
  370. });
  371. this.myEmit("car",ob1,ob)
  372. */
  373. //this.mapcharger.add(ob1);
  374. }
  375. },
  376. myEmit(type,ob1,obj){
  377. var _this=this;
  378. AMap.event.addListener(ob1, 'click', function(e) {
  379. _this.$emit('clickMap',{
  380. type:type,
  381. obj:obj
  382. })
  383. })
  384. },
  385. setMyStyle(s){
  386. this.myStyle=s;
  387. },
  388. setCenter(item){
  389. this.removeMove();
  390. console.log('setCenter'+JSON.stringify(item))
  391. if(this.mapcharger){
  392. this.mapcharger.setCenter([item.longitude,item.latitude]);
  393. this.listenMove();
  394. return true
  395. }else{
  396. this.listenMove();
  397. return false
  398. }
  399. },
  400. setPerson(ob,bl){
  401. console.log('setPerson1'+JSON.stringify(ob))
  402. if(this.AMap==null){
  403. return
  404. }
  405. // console.log('setPerson2')
  406. this.info.longitude=ob.longitude
  407. this.info.latitude=ob.latitude
  408. if(!this.info.ob){
  409. this.addPerson(ob)
  410. //this.info.ob.setMap(this.mapcharger);
  411. //console.log('setMap xxx ')
  412. //this.mapbus.setCenter([this.info.longitude,this.info.latitude]); //设置地图中心点
  413. if(!bl){
  414. let posCenter= [ this.info.longitude,this.info.latitude];
  415. // console.log('center'+JSON.stringify(posCenter))
  416. //this.mapcharger.setZoom(9)
  417. //this.mapcharger.setCenter([112.28541,30.308354])
  418. //this.mapcharger.setCenter([121.504919,31.351083])
  419. this.mapcharger.setCenter(posCenter); //设置地图中心点
  420. }
  421. }else{
  422. // this.info.ob.setPosition( [this.info.longitude,this.info.latitude]);
  423. }
  424. },
  425. logMapInfo() {
  426. var posCenter = this.mapcharger.getCenter();
  427. // console.log('center'+JSON.stringify(posCenter));
  428. var limitBounds = this.mapcharger.getBounds();
  429. let pos = {center:posCenter,bounds:limitBounds};
  430. return pos;
  431. },
  432. init(){
  433. _self = this;
  434. // console.log('init')
  435. var _this = this;
  436. // this.positionIcon = require('@/static/img/location.png')
  437. // this.personIcon = require("@/static/img/charger_selected.png")
  438. // this.chargerIcon = require("@/static/img/charger.png");
  439. // this.chargerSelectedIcon = require("@/static/img/charger_selected_circle.png");
  440. MapLoader().then(AMap => {
  441. this.AMap=AMap;
  442. _this.mapcharger && _this.mapcharger.destroy();
  443. //使用地图容器ID创建
  444. _this.mapcharger=new AMap.Map("container", {
  445. resizeEnable: true,
  446. dragEnable : true,
  447. center: [this.longitude, this.latitude],
  448. zoom: 14
  449. });
  450. /*
  451. new SimpleMarker({
  452. iconLabel: '2',
  453. //自定义图标节点(img)的属性
  454. iconStyle: {
  455. src: '@/static/img/location.png',
  456. style: {
  457. width: '20px',
  458. height: '30px'
  459. }
  460. },
  461. //设置基点偏移
  462. offset: new AMap.Pixel(-10, -30),
  463. map: map,
  464. showPositionPoint: true,
  465. position: lngLats[1],
  466. zIndex: 200
  467. });
  468. */
  469. /*
  470. _this.mapcharger.plugin('AMap.Geolocation', function () {
  471. var geolocation = new AMap.Geolocation({
  472. enableHighAccuracy: true,
  473. timeout: 10000,
  474. buttonOffset: new AMap.Pixel(10, 220),
  475. zoomToAccuracy: true,
  476. buttonPosition: 'RB'
  477. });
  478. _this.mapcharger.center = geolocation;
  479. _this.mapcharger.addControl(geolocation);//地图控件右下角显示当前位置
  480. });
  481. _this.mapcharger.plugin(["AMap.ToolBar"],function(){
  482. //加载工具条
  483. var tool = new AMap.ToolBar({
  484. locate:true,
  485. direction:false,
  486. ruler:false,
  487. liteStyle:true,
  488. useNative:true,
  489. // autoPosition:true,
  490. // locationMarker:
  491. });
  492. _this.mapcharger.addControl(tool);
  493. });*/
  494. /*
  495. _this.mapcharger.plugin(["AMap.ControlBar"],function(){
  496. var controlBar = new AMap.ControlBar({
  497. showZoomBar:true,
  498. showControlButton:true,
  499. position:{top:'10px',right:'10px'}
  500. })
  501. _this.mapcharger.addControl(controlBar)
  502. });*/
  503. var clickHandler = function(e) {
  504. _this.$emit('onClicked',e);
  505. console.log('您在[ '+e.lnglat.getLng()+','+e.lnglat.getLat()+' ]的位置点击了地图!');
  506. };
  507. /*
  508. var mapMovestart = function(){
  509. console.log('movestart')
  510. }
  511. var mapMove = function(){
  512. //console.log('mapMove')
  513. }
  514. var mapMoveend = function(){
  515. let pos = _this.logMapInfo();
  516. _this.$emit('onMoveEnd',pos);
  517. // console.log('mapMoveend')
  518. }
  519. _this.mapMovestart = mapMovestart;
  520. _this.mapMove = mapMove;
  521. _this.mapMoveend = mapMoveend;
  522. */
  523. _this.mapcharger.on('click', clickHandler);
  524. _this.$emit('onload')
  525. //_this.addPosition();
  526. _this.listenMove();
  527. }, e => {
  528. //_this.mui.toast('地图加载失败');
  529. console.log('地图加载失败', e)
  530. })
  531. },
  532. removeMove(){
  533. var _this = this;
  534. _this.mapcharger.off('movestart', mapMovestart);
  535. _this.mapcharger.off('mapmove', mapMove);
  536. _this.mapcharger.off('moveend', mapMoveend);
  537. },
  538. listenMove(){
  539. var _this = this;
  540. // console.log('listenMove')
  541. _this.mapcharger.on('movestart', mapMovestart,_this);
  542. _this.mapcharger.on('mapmove', mapMove,_this);
  543. _this.mapcharger.on('moveend',mapMoveend,_this);
  544. },
  545. navigate(startLngLat,endLngLat){
  546. console.log('start'+JSON.stringify(startLngLat))
  547. console.log('end'+JSON.stringify(endLngLat))
  548. AMap.plugin('AMap.Driving', function() {
  549. var driving = new AMap.Driving({
  550. // 驾车路线规划策略,AMap.DrivingPolicy.LEAST_TIME是最快捷模式
  551. policy: AMap.DrivingPolicy.LEAST_TIME
  552. })
  553. // var startLngLat = [116.379028, 39.865042]
  554. // var endLngLat = [116.427281, 39.903719]
  555. driving.search(startLngLat, endLngLat, function (status, result) {
  556. console.log('status'+JSON.stringify(result))
  557. // 未出错时,result即是对应的路线规划方案
  558. })
  559. })
  560. },
  561. initMap(point,stationList,startend){
  562. console.log('初始化地图'+this.longitude+this.latitude)
  563. var _this = this;
  564. this.covers=point;
  565. this.startend=startend;
  566. MapLoader().then(AMap => {
  567. this.AMap=AMap;
  568. _this.mapcharger && _this.mapcharger.destroy();
  569. _this.mapcharger=new AMap.Map("container", {
  570. resizeEnable: true,
  571. center: [this.longitude, this.latitude],
  572. //center: [116.397428, 39.90923],
  573. zoom: 14
  574. });
  575. var lineArr=[]
  576. //var icon0 = require("@/static/img/map_0.png");
  577. //var icon1 = require("@/static/img/map_1.png");
  578. //var icon2 = require("@/static/img/map_2.png");
  579. /*this.start=new AMap.Marker({
  580. map: _this.mapcharger,
  581. position: [_this.startend[0].longitude,_this.startend[0].latitude],
  582. content:"<img src='"+icon0+"' style='height: 30px;width: 30px' />",
  583. offset: new AMap.Pixel(-15, -30),
  584. zIndex:99,
  585. autoRotation: true,
  586. });
  587. this.end=new AMap.Marker({
  588. map: _this.mapcharger,
  589. position: [_this.startend[1].longitude,_this.startend[1].latitude],
  590. content:"<img src='"+icon2+"' style='height: 30px;width: 30px' />",
  591. offset: new AMap.Pixel(-15, -30),
  592. zIndex:99,
  593. autoRotation: true,
  594. });
  595. for(var i in _this.covers){
  596. var point=_this.covers[i]
  597. lineArr.push([point.longitude,point.latitude])
  598. }
  599. for(var i in stationList){
  600. var point=stationList[i]
  601. var ob_point =new AMap.Marker({
  602. map: _this.mapcharger,
  603. position: [point.longitude,point.latitude],
  604. offset: new AMap.Pixel(-5, -7),
  605. content:"<img src='"+icon1+"' style='height: 10px;width: 10px' />",
  606. zIndex:99,
  607. autoRotation: true,
  608. });
  609. this.myEmit("point",ob_point,point)
  610. }
  611. var polyline = new AMap.Polyline({
  612. map: _this.mapcharger,
  613. path: lineArr,
  614. showDir: true,
  615. strokeColor: "#28F", //线颜色
  616. // strokeOpacity: 1, //线透明度
  617. strokeWeight: 3, //线宽
  618. //strokeStyle: "solid" //线样式
  619. });*/
  620. this.$emit('onload')
  621. }, e => {
  622. //_this.mui.toast('地图加载失败');
  623. console.log('地图加载失败', e)
  624. })
  625. },
  626. }
  627. }
  628. </script>
  629. <style scoped>
  630. /*去除下标*/
  631. .amap-logo{
  632. display: none;
  633. }
  634. .amap-copyright{
  635. opacity:0;
  636. font-size: 1px;
  637. }
  638. .input-card {
  639. display: flex;
  640. flex-direction: column;
  641. min-width: 0;
  642. word-wrap: break-word;
  643. background-color: #fff;
  644. background-clip: border-box;
  645. border-radius: .25rem;
  646. width: 22rem;
  647. border-width: 0;
  648. border-radius: 0.4rem;
  649. box-shadow: 0 2px 6px 0 rgba(114, 124, 245, .5);
  650. position: fixed;
  651. bottom: 1rem;
  652. right: 1rem;
  653. -ms-flex: 1 1 auto;
  654. flex: 1 1 auto;
  655. padding: 0.75rem 0.75rem;
  656. }
  657. .station-icon {
  658. width: 36px;
  659. height: 36px;
  660. line-height: 36px;
  661. text-align: center;
  662. border: 1px solid rgba(133, 140, 255, 100);
  663. color: #b58cff;
  664. border-radius: 999px;
  665. position: absolute;
  666. top: 89px;
  667. left: 38px;
  668. }
  669. .corner{
  670. width: 0;
  671. height: 0;
  672. position: absolute;
  673. top: 34px;
  674. left: 0;
  675. right: 0;
  676. margin: auto;
  677. border-bottom: 4px solid transparent;
  678. border-left: 4px solid transparent;
  679. border-right: 4px solid transparent;
  680. border-top: 6px solid #b58cff ;
  681. }
  682. .station-icon2 {
  683. width: 100px;
  684. height: 36px;
  685. line-height: 20px;
  686. border-radius: 50px;
  687. background-color: rgba(0, 185, 98, 100);
  688. text-align: center;
  689. display: flex;
  690. position: absolute;
  691. top: 191px;
  692. left: 168px;
  693. }
  694. .icon2-left{
  695. width: 36px;
  696. height: 36px;
  697. line-height: 36px;
  698. text-align: center;
  699. border: 1px solid rgba(0, 185, 98, 100);
  700. border-radius: 999px;
  701. background-color: #fff;
  702. color: #00b962;
  703. }
  704. .icon2-right{
  705. color: #ffffff;
  706. line-height: 14px;
  707. padding: 4px;
  708. }
  709. .corner2{
  710. width: 0;
  711. height: 0;
  712. position: absolute;
  713. top: 36px;
  714. left: 0;
  715. right: 0;
  716. margin: auto;
  717. border-bottom: 6px solid transparent;
  718. border-left: 6px solid transparent;
  719. border-right: 6px solid transparent;
  720. border-top: 8px solid #00b962 ;
  721. }
  722. </style>