123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <template>
- <view>
- <view id="container" style="width: 100%; height: 240px;"></view>
-
- </view>
- </template>
- <script>
- import MapLoader from '@/utils/AMap'
- export default {
- name:"Carmap",
- data() {
- return {
- longitude: 112.276527,
- latitude: 30.306427,
- AMap:null,
- //车的位置
- car: {
- obj:null,
- longitude: '',
- latitude: '',
- },
-
- //个人
- info: {
- obj:null,
- init: false,
- longitude: '',
- latitude: '',
- },
- mapbus:null,
- startend: [{
- longitude:112.279274,
- latitude:30.303273,
- name:''
- }, {
- longitude:112.273867,
- latitude:30.309817,
- name:''
- }],
- covers: [
- {
- longitude:112.273867,
- latitude:30.309817,
- },{
- longitude:112.280261,
- latitude:30.3041,
- },{
- longitude:112.279274,
- latitude:30.303273,
- }
- ]
- };
- },
- methods:{
- setCar(ob){
- if(this.AMap==null){
- return
- }
- this.car.longitude=ob.longitude
- this.car.latitude=ob.latitude
- if(!this.car.ob){
-
- var icon0 = require("@/static/img/icon-busPosition.png");
-
- this.car.ob= new AMap.Marker({
- map: this.mapbus,
- position: [this.car.longitude,this.car.latitude],
- offset: new AMap.Pixel(-5, -5),
-
- content:"<img src='"+icon0+"' style='height: 30px;width: 30px' />",
-
- zIndex:999,
- autoRotation: true,
- });
-
- }else{
- this.car.ob.setPosition( [this.car.longitude,this.car.latitude]);
- }
-
-
- },
- setPerson(ob){
- if(this.AMap==null){
- return
- }
-
- this.info.longitude=ob.longitude
- this.info.latitude=ob.latitude
- if(!this.info.ob){
-
- var icon0 = require("@/static/img/icon-userPosition.png");
-
-
- this.info.ob= new AMap.Marker({
- map: this.mapbus,
- position: [this.info.longitude,this.info.latitude],
- offset: new AMap.Pixel(-5, -5),
- content:"<img src='"+icon0+"' style='height: 30px;width: 30px' />",
-
- zIndex:999,
- autoRotation: true,
- });
- //this.mapbus.setCenter([this.info.longitude,this.info.latitude]); //设置地图中心点
- this.mapbus.setCenter([ this.info.longitude,this.info.latitude]); //设置地图中心点
- }else{
- this.info.ob.setPosition( [this.info.longitude,this.info.latitude]);
- }
-
-
- },
- initMap(point,stationList,startend){
- var _this = this;
- this.covers=point;
- this.startend=startend;
- MapLoader().then(AMap => {
-
- this.AMap=AMap;
- _this.mapbus && _this.mapbus.destroy();
-
- _this.mapbus=new AMap.Map("container", {
- resizeEnable: true,
- center: [this.longitude, this.latitude],
- zoom: 14
- });
- var lineArr=[]
- var icon0 = require("@/static/img/map_0.png");
- var icon1 = require("@/static/img/map_1.png");
- var icon2 = require("@/static/img/map_2.png");
- new AMap.Marker({
- map: _this.mapbus,
- position: [_this.startend[0].longitude,_this.startend[0].latitude],
- content:"<img src='"+icon0+"' style='height: 30px;width: 30px' />",
- offset: new AMap.Pixel(-15, -30),
- zIndex:999,
- autoRotation: true,
- });
- new AMap.Marker({
- map: _this.mapbus,
- position: [_this.startend[1].longitude,_this.startend[1].latitude],
- content:"<img src='"+icon2+"' style='height: 30px;width: 30px' />",
- offset: new AMap.Pixel(-15, -30),
- zIndex:999,
- autoRotation: true,
- });
- for(var i in _this.covers){
- var point=_this.covers[i]
- lineArr.push([point.longitude,point.latitude])
-
- }
- for(var i in stationList){
- var point=stationList[i]
- new AMap.Marker({
- map: _this.mapbus,
- position: [point.longitude,point.latitude],
- offset: new AMap.Pixel(-5, -5),
- content:"<img src='"+icon1+"' style='height: 10px;width: 10px' />",
- zIndex:999,
- autoRotation: true,
- });
- }
- var polyline = new AMap.Polyline({
- map: _this.mapbus,
- path: lineArr,
- showDir: true,
- strokeColor: "#28F", //线颜色
- // strokeOpacity: 1, //线透明度
- strokeWeight: 3, //线宽
- //strokeStyle: "solid" //线样式
- });
-
- }, e => {
- //_this.mui.toast('地图加载失败');
- console.log('地图加载失败', e)
- })
- },
- }
- }
- </script>
- <style>
- </style>
|