Chargermap.vue 23 KB

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