Chargermap.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  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. 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. // console.log('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. console.log('定位成功信息:', data.addressComponent.city);
  104. self.city = data.addressComponent.city;
  105. }
  106. function onError (data) {
  107. // 定位出错
  108. // console.log('定位失败错误:', 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. //console.log('通过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. console.log('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. console.log(lnglatXY);
  153. console.log(status, result);
  154. if (status === 'complete' && result.info === 'OK') {
  155. var address = result.regeocode.formattedAddress;
  156. console.log('当前位置'+JSON.stringify(lnglatXY)+address);
  157. //_this.message= address;
  158. } else {
  159. //_this.message= '无法获取定位';
  160. }
  161. });
  162. });
  163. }).catch(error => {
  164. console.log(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. console.log(result)
  184. console.log(result.routes[0].time)//秒
  185. console.log(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. // console.log('endLst'+JSON.stringify(endLst));
  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. AMap.plugin('AMap.Driving', function() {
  213. var driving = new AMap.Driving({
  214. // 驾车路线规划策略,AMap.DrivingPolicy.LEAST_TIME是最快捷模式
  215. policy: AMap.DrivingPolicy.LEAST_TIME
  216. })
  217. for(let i=0;i< endLst.length;i++)
  218. {
  219. let item = endLst[i];
  220. let endLngLat = [item.longitude,item.latitude]
  221. driving.search(startLngLat, endLngLat, function (status, result) {
  222. endLst[i].distance = result.routes[0].distance/1000.0;
  223. endLst[i].time = result.routes[0].time/60.0;
  224. })
  225. }
  226. }) */
  227. },
  228. updateCharger(pos){
  229. console.log('更新充电桩1'+JSON.stringify(pos) )
  230. // let index = this.chargerList.findIndex(item => item.info.latitude === pos.latitude && item.info.longitude === pos.longitude);
  231. //let index = this.chargerList.findIndex(item => (Math.abs(item.info.longitude-pos.longitude)<0.000001 && Math.abs(item.info.longitude - pos.latitude)<0.000001));
  232. let index = this.chargerList.findIndex(item => item.info.id === pos.id);
  233. // console.log('更新充电桩['+ index + ']'+JSON.stringify(pos))
  234. let colorBg = '#00BAC8';//#00b962
  235. if(this.chargerList[index].info.type =='快充'){
  236. colorBg = '#8486FF'
  237. }else if(this.chargerList[index].info.type =='慢充'){
  238. colorBg = '#00b962'
  239. }
  240. // console.log('colorBg'+colorBg)
  241. // console.log('更新充电桩2'+JSON.stringify(this.chargerList[index].info))
  242. if(index>=0){
  243. let station_icon2 = "width: 100px;height: 36px;line-height: 20px;border-radius: 50px;background-color: " + colorBg +";text-align: center;display: flex;";
  244. 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 +" ;";
  245. let content = "<div style='" + station_icon2 + "'>";
  246. 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>";
  247. content+="<div style='color: #ffffff;line-height: 14px;padding: 4px;font-size: 14px'>";
  248. content+="<div style='"+corner2+"'></div>";
  249. content+="<div class=''>";
  250. if(pos.price != null)
  251. content+= "¥" + pos.price.toString();
  252. if(pos.costPrice != null)
  253. content+= "¥" + pos.costPrice.toString();
  254. content+="</div>";
  255. content+="<div class=''>";
  256. if(pos.idleNum != null)
  257. content+="空闲" + pos.idleNum.toString();
  258. if(pos.availableNum != null)
  259. content+="空闲" + pos.availableNum.toString();
  260. content+="</div>"
  261. content+="</div>";
  262. content+="</div>";
  263. // console.log('找到充电桩[]'+content)
  264. //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>";
  265. this.chargerList[index].info.selected = true;
  266. this.chargerList[index].marker.setContent(content);
  267. }
  268. for(let i = 0;i < this.chargerList.length;i++){
  269. if(index == i)
  270. continue;
  271. if(this.chargerList[i].info.selected != null &&
  272. this.chargerList[i].info.selected)
  273. {
  274. let station_icon = "width: 36px;height: 36px;line-height: 36px;text-align: center;border: 1px solid " + colorBg +"; color: " + colorBg +"; border-radius: 999px;";
  275. 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 +" ;";
  276. let content = "<div style='"+station_icon+";background-color: #fff;' ><text class='iconfont' >&#xe606;</text><div style='" + corner+"'></div></div>"
  277. //let content = "<img src='"+this.chargerIcon+"' style='height: 40px;width: 40px' />";
  278. this.chargerList[i].marker.setContent(content);
  279. this.chargerList[i].info.selected = false;
  280. console.log('restore'+JSON.stringify(this.chargerList[i].info))
  281. }
  282. }
  283. },
  284. addCharger(pos) {
  285. let colorBg = '#00BAC8';//#00b962
  286. if(pos.type =='快充'){
  287. colorBg = '#8486FF'
  288. }else if(pos.type =='慢充'){
  289. colorBg = '#00b962'
  290. }
  291. // console.log('添加充电桩'+JSON.stringify(pos))
  292. //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>";
  293. let station_icon = "width: 36px;height: 36px;line-height: 36px;text-align: center;border: 1px solid "+ colorBg+"; color: "+ colorBg+"; border-radius: 999px;";
  294. 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+" ;";
  295. let content = "<div style='"+station_icon+";background:#fff;' ><text class='iconfont' >&#xe606;</text><div style='" + corner+"'></div></div>"
  296. let marker = new AMap.Marker({
  297. content: content,//"<img src='"+this.chargerIcon+"' style='height: 40px;width: 40px' />",
  298. //icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",
  299. position: [pos.longitude,pos.latitude],
  300. offset: new AMap.Pixel(-13, -30),
  301. zIndex:900,
  302. autoRotation: true,
  303. });
  304. marker.setMap(this.mapcharger);
  305. this.myEmit("charger",marker,pos)
  306. this.chargerList.push({marker:marker,info:pos});
  307. },
  308. addPerson(pos) {
  309. console.log('addPerson'+JSON.stringify(pos))
  310. 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;'>";
  311. content += "<div class='iconfont' style='color: #1677ff; font-size: 14px' >&#xe634;</div>";
  312. content += "</div>";
  313. let marker = new AMap.Marker({
  314. content: content,//"<div class='iconfont' style='color: #1677ff; font-size: 14px' >&#xe634;</div>",//<img src='"+this.personIcon+"' style='height: 40px;width: 40px' />",
  315. //content:"<div>xxxxxxxxxxxxxxxxxxxxxx</div>",
  316. //icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",
  317. position: [pos.longitude,pos.latitude],
  318. offset: new AMap.Pixel(-13, -30),
  319. zIndex:900,
  320. autoRotation: true,
  321. });
  322. marker.setMap(this.mapcharger);
  323. this.myEmit("person",marker,pos)
  324. //this.chargerList.push(marker)
  325. },
  326. /*
  327. addPosition() {
  328. console.log('addPosition'+JSON.stringify(pos))
  329. let marker = new AMap.Marker({
  330. content: "<img src='"+this.positionIcon+"' style='height: 40px;width: 40px' />",
  331. //icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",
  332. //position: [pos.longitude,pos.latitude],
  333. offset: new AMap.Pixel(20, 220),
  334. zIndex:900,
  335. autoRotation: true,
  336. });
  337. marker.setMap(this.mapcharger);
  338. //this.myEmit("person",marker,pos)
  339. //this.chargerList.push(marker)
  340. },*/
  341. setChargerList(sz){
  342. if(this.AMap==null){
  343. return
  344. }
  345. //this.getLocation();
  346. for(var i in this.chargerList){
  347. if(this.chargerList[i].marker){
  348. this.chargerList[i].marker.setMap(null);
  349. }
  350. this.mapcharger.remove(this.chargerList[i]);
  351. }
  352. this.chargerList=[]
  353. for(var i in sz){
  354. var ob=sz[i];
  355. this.addCharger(ob);
  356. /*var ob1 = new AMap.Marker({
  357. position: new AMap.LngLat(ob.longitude,ob.latitude), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
  358. title: '北京'
  359. });
  360. this.mapcharger.add(ob1);*/
  361. /*
  362. var ob1=new AMap.Marker({
  363. map: this.mapcharger,
  364. position: [ob.longitude,ob.latitude],
  365. //offset: new AMap.Pixel(-5, -5),
  366. //offset: new AMap.Pixel(-18, -40),
  367. content:"<img src='"+icon0+"' style='height: 40px;width: 40px' />",
  368. title:'test111111111111111',
  369. zIndex:900,
  370. autoRotation: true,
  371. });
  372. this.myEmit("car",ob1,ob)
  373. */
  374. //this.mapcharger.add(ob1);
  375. }
  376. },
  377. myEmit(type,ob1,obj){
  378. var _this=this;
  379. AMap.event.addListener(ob1, 'click', function(e) {
  380. _this.$emit('clickMap',{
  381. type:type,
  382. obj:obj
  383. })
  384. })
  385. },
  386. setMyStyle(s){
  387. this.myStyle=s;
  388. },
  389. checkCenter(item){
  390. let pos = this.mapcharger.getCenter();
  391. if(pos.lng == item.longitude && pos.lat == item.latitude){
  392. console.log('setCenter pos '+JSON.stringify(pos))
  393. console.log('setCenter item '+JSON.stringify(item))
  394. this.listenMove();
  395. }else{
  396. console.log('setCenter pos1 '+JSON.stringify(pos))
  397. console.log('setCenter item1 '+JSON.stringify(item))
  398. setTimeout(() => {
  399. this.checkCenter(item);
  400. }, 1000)
  401. }
  402. },
  403. setCenter(item){
  404. // this.enableMove(false);
  405. this.removeMove();
  406. // console.log('setCenter'+JSON.stringify(item))
  407. if(this.mapcharger){
  408. this.mapcharger.setCenter([item.longitude,item.latitude]);
  409. this.checkCenter(item);
  410. // this.listenMove();
  411. // this.enableMove(true);
  412. return true
  413. }else{
  414. // this.listenMove();
  415. // this.enableMove(true);
  416. return false
  417. }
  418. },
  419. setPerson(ob,bl){
  420. console.log('setPerson1'+JSON.stringify(ob))
  421. if(this.AMap==null){
  422. return
  423. }
  424. // console.log('setPerson2')
  425. this.info.longitude=ob.longitude
  426. this.info.latitude=ob.latitude
  427. if(!this.info.ob){
  428. this.addPerson(ob)
  429. //this.info.ob.setMap(this.mapcharger);
  430. //console.log('setMap xxx ')
  431. //this.mapbus.setCenter([this.info.longitude,this.info.latitude]); //设置地图中心点
  432. if(!bl){
  433. let posCenter= [ this.info.longitude,this.info.latitude];
  434. // console.log('center'+JSON.stringify(posCenter))
  435. //this.mapcharger.setZoom(9)
  436. //this.mapcharger.setCenter([112.28541,30.308354])
  437. //this.mapcharger.setCenter([121.504919,31.351083])
  438. this.mapcharger.setCenter(posCenter); //设置地图中心点
  439. }
  440. }else{
  441. // this.info.ob.setPosition( [this.info.longitude,this.info.latitude]);
  442. }
  443. },
  444. logMapInfo() {
  445. var posCenter = this.mapcharger.getCenter();
  446. // console.log('center'+JSON.stringify(posCenter));
  447. var limitBounds = this.mapcharger.getBounds();
  448. let pos = {center:posCenter,bounds:limitBounds};
  449. return pos;
  450. },
  451. init(){
  452. _self = this;
  453. // console.log('init')
  454. var _this = this;
  455. // this.positionIcon = require('@/static/img/location.png')
  456. // this.personIcon = require("@/static/img/charger_selected.png")
  457. // this.chargerIcon = require("@/static/img/charger.png");
  458. // this.chargerSelectedIcon = require("@/static/img/charger_selected_circle.png");
  459. MapLoader().then(AMap => {
  460. this.AMap=AMap;
  461. _this.mapcharger && _this.mapcharger.destroy();
  462. //使用地图容器ID创建
  463. _this.mapcharger=new AMap.Map("container", {
  464. resizeEnable: true,
  465. dragEnable : true,
  466. center: [this.longitude, this.latitude],
  467. zoom: 13
  468. });
  469. //_this.mapcharger.setMapStyle('amap://styles/macaron');
  470. _this.mapcharger.setMapStyle('amap://styles/f9b17f73bb4576ab1894c29fe9d03c6c');
  471. /*
  472. new SimpleMarker({
  473. iconLabel: '2',
  474. //自定义图标节点(img)的属性
  475. iconStyle: {
  476. src: '@/static/img/location.png',
  477. style: {
  478. width: '20px',
  479. height: '30px'
  480. }
  481. },
  482. //设置基点偏移
  483. offset: new AMap.Pixel(-10, -30),
  484. map: map,
  485. showPositionPoint: true,
  486. position: lngLats[1],
  487. zIndex: 200
  488. });
  489. */
  490. /*
  491. _this.mapcharger.plugin('AMap.Geolocation', function () {
  492. var geolocation = new AMap.Geolocation({
  493. enableHighAccuracy: true,
  494. timeout: 10000,
  495. buttonOffset: new AMap.Pixel(10, 220),
  496. zoomToAccuracy: true,
  497. buttonPosition: 'RB'
  498. });
  499. _this.mapcharger.center = geolocation;
  500. _this.mapcharger.addControl(geolocation);//地图控件右下角显示当前位置
  501. });
  502. _this.mapcharger.plugin(["AMap.ToolBar"],function(){
  503. //加载工具条
  504. var tool = new AMap.ToolBar({
  505. locate:true,
  506. direction:false,
  507. ruler:false,
  508. liteStyle:true,
  509. useNative:true,
  510. // autoPosition:true,
  511. // locationMarker:
  512. });
  513. _this.mapcharger.addControl(tool);
  514. });*/
  515. /*
  516. _this.mapcharger.plugin(["AMap.ControlBar"],function(){
  517. var controlBar = new AMap.ControlBar({
  518. showZoomBar:true,
  519. showControlButton:true,
  520. position:{top:'10px',right:'10px'}
  521. })
  522. _this.mapcharger.addControl(controlBar)
  523. });*/
  524. var clickHandler = function(e) {
  525. _this.$emit('onClicked',e);
  526. console.log('您在[ '+e.lnglat.getLng()+','+e.lnglat.getLat()+' ]的位置点击了地图!');
  527. };
  528. /*
  529. var mapMovestart = function(){
  530. console.log('movestart')
  531. }
  532. var mapMove = function(){
  533. //console.log('mapMove')
  534. }
  535. var mapMoveend = function(){
  536. let pos = _this.logMapInfo();
  537. _this.$emit('onMoveEnd',pos);
  538. // console.log('mapMoveend')
  539. }
  540. _this.mapMovestart = mapMovestart;
  541. _this.mapMove = mapMove;
  542. _this.mapMoveend = mapMoveend;
  543. */
  544. _this.mapcharger.on('click', clickHandler);
  545. _this.$emit('onload')
  546. //_this.addPosition();
  547. _this.listenMove();
  548. }, e => {
  549. //_this.mui.toast('地图加载失败');
  550. console.log('地图加载失败', e)
  551. })
  552. },
  553. removeMove(){
  554. var _this = this;
  555. //this.enabledMove = false;
  556. _this.mapcharger.off('movestart', mapMovestart);
  557. _this.mapcharger.off('mapmove', mapMove);
  558. _this.mapcharger.off('moveend', mapMoveend);
  559. },
  560. enableMove(enable){
  561. this.enabledMove = enable;
  562. },
  563. listenMove(){
  564. var _this = this;
  565. /*var mapMovestart = function(){
  566. if(!_this.enabledMove)
  567. return;
  568. console.log('movestart')
  569. }
  570. var mapMove = function(){
  571. if(!_this.enabledMove)
  572. return;
  573. //console.log('mapMove')
  574. }
  575. var mapMoveend = function(){
  576. let pos = _this.logMapInfo();
  577. if(!_this.enabledMove)
  578. return;
  579. _this.$emit('onMoveEnd',pos);
  580. }*/
  581. // console.log('listenMove')
  582. _this.mapcharger.on('movestart', mapMovestart);
  583. _this.mapcharger.on('mapmove', mapMove);
  584. _this.mapcharger.on('moveend',mapMoveend);
  585. },
  586. navigate(startLngLat,endLngLat){
  587. console.log('start'+JSON.stringify(startLngLat))
  588. console.log('end'+JSON.stringify(endLngLat))
  589. AMap.plugin('AMap.Driving', function() {
  590. var driving = new AMap.Driving({
  591. // 驾车路线规划策略,AMap.DrivingPolicy.LEAST_TIME是最快捷模式
  592. policy: AMap.DrivingPolicy.LEAST_TIME
  593. })
  594. // var startLngLat = [116.379028, 39.865042]
  595. // var endLngLat = [116.427281, 39.903719]
  596. driving.search(startLngLat, endLngLat, function (status, result) {
  597. console.log('status'+JSON.stringify(result))
  598. // 未出错时,result即是对应的路线规划方案
  599. })
  600. })
  601. },
  602. initMap(point,stationList,startend){
  603. console.log('初始化地图'+this.longitude+this.latitude)
  604. var _this = this;
  605. this.covers=point;
  606. this.startend=startend;
  607. MapLoader().then(AMap => {
  608. this.AMap=AMap;
  609. _this.mapcharger && _this.mapcharger.destroy();
  610. _this.mapcharger=new AMap.Map("container", {
  611. resizeEnable: true,
  612. center: [this.longitude, this.latitude],
  613. //center: [116.397428, 39.90923],
  614. zoom: 14
  615. });
  616. var lineArr=[]
  617. this.$emit('onload')
  618. }, e => {
  619. //_this.mui.toast('地图加载失败');
  620. console.log('地图加载失败', e)
  621. })
  622. },
  623. }
  624. }
  625. </script>
  626. <style scoped>
  627. /*去除下标*/
  628. .amap-logo{
  629. display: none;
  630. }
  631. .amap-copyright{
  632. opacity:0;
  633. font-size: 1px;
  634. }
  635. .input-card {
  636. display: flex;
  637. flex-direction: column;
  638. min-width: 0;
  639. word-wrap: break-word;
  640. background-color: #fff;
  641. background-clip: border-box;
  642. border-radius: .25rem;
  643. width: 22rem;
  644. border-width: 0;
  645. border-radius: 0.4rem;
  646. box-shadow: 0 2px 6px 0 rgba(114, 124, 245, .5);
  647. position: fixed;
  648. bottom: 1rem;
  649. right: 1rem;
  650. -ms-flex: 1 1 auto;
  651. flex: 1 1 auto;
  652. padding: 0.75rem 0.75rem;
  653. }
  654. .station-icon {
  655. width: 36px;
  656. height: 36px;
  657. line-height: 36px;
  658. text-align: center;
  659. border: 1px solid rgba(133, 140, 255, 100);
  660. color: #b58cff;
  661. border-radius: 999px;
  662. position: absolute;
  663. top: 89px;
  664. left: 38px;
  665. }
  666. .corner{
  667. width: 0;
  668. height: 0;
  669. position: absolute;
  670. top: 34px;
  671. left: 0;
  672. right: 0;
  673. margin: auto;
  674. border-bottom: 4px solid transparent;
  675. border-left: 4px solid transparent;
  676. border-right: 4px solid transparent;
  677. border-top: 6px solid #b58cff ;
  678. }
  679. .station-icon2 {
  680. width: 100px;
  681. height: 36px;
  682. line-height: 20px;
  683. border-radius: 50px;
  684. background-color: rgba(0, 185, 98, 100);
  685. text-align: center;
  686. display: flex;
  687. position: absolute;
  688. top: 191px;
  689. left: 168px;
  690. }
  691. .icon2-left{
  692. width: 36px;
  693. height: 36px;
  694. line-height: 36px;
  695. text-align: center;
  696. border: 1px solid rgba(0, 185, 98, 100);
  697. border-radius: 999px;
  698. background-color: #fff;
  699. color: #00b962;
  700. }
  701. .icon2-right{
  702. color: #ffffff;
  703. line-height: 14px;
  704. padding: 4px;
  705. }
  706. .corner2{
  707. width: 0;
  708. height: 0;
  709. position: absolute;
  710. top: 36px;
  711. left: 0;
  712. right: 0;
  713. margin: auto;
  714. border-bottom: 6px solid transparent;
  715. border-left: 6px solid transparent;
  716. border-right: 6px solid transparent;
  717. border-top: 8px solid #00b962 ;
  718. }
  719. </style>