高德地图的基本使用

第一次使用高德地图

首先是显示地图

在public目录下引入高德地图
在这里插入图片描述
然后开始

<div class="box-card_content">
     <div id="map"></div>
</div>
.box-card_content {
  width: 100%;
  height: 690px;
  overflow-y: auto;
  overflow-x: hidden;
}
#map {
  height: 100%;
}

在methods中定义,mounted中加载

mounted() {
    this.mapInit()
  },
methods:{
	mapInit() {
      this.map = new AMap.Map('map', {
        zoom: 11, //级别
        center: [108.886319, 34.210983], //中心点坐标
        resizeEnable: true,
      })
    },
}

效果
在这里插入图片描述

地图上显示marker标记

methods:{
	mapInit() {
      this.map = new AMap.Map('map', {
        zoom: 11, //级别
        center: [108.886319, 34.210983], //中心点坐标
        resizeEnable: true,
      })
    },
    showMarker(){
        var that = this
    	var marker = new AMap.Marker({
    	// 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
          position: new AMap.LngLat(108.94705, 34.259429), 
          title: '车车',
          //图片可以放入public目录下,不写icon默认官方蓝点
          icon: 'http://。。。。/car.png',
        })
        //也可以定义多个marker,放入数组
        var markerList = [marker]
        that.map.add(markerList)
    }
}

在这里插入图片描述

点击marker显示信息窗口

showMarker(){
		var that = this 
    	var marker = new AMap.Marker({
    	// 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
          position: new AMap.LngLat(108.94705, 34.259429), 
          title: '车车',
          //图片可以放入public目录下,不写icon默认官方蓝点
          icon: 'http://。。。。/car.png',
        })
        //也可以定义多个marker,放入数组
        var markerList = [marker]
        that.map.add(markerList)
		
		//图标注册点击事件,点击显示信息窗体
        AMap.event.addListener(marker, 'click', function () {
          var infoWindow = new AMap.InfoWindow({
            isCustom: false, //使用自定义窗体
            content: `
            <div style="padding:5px;">
                <div>所属公司:xxx</div>
                <div>接收时间:2020</div>
                <div>速度:125km/h</div>
            </div>
          `,
            offset: new AMap.Pixel(0, -20),
          })
          infoWindow.open(that.map, [108.94705, 34.259429]) //后面的参数指的是经纬度,在此显示窗口
        })
    }

在这里插入图片描述

轨迹回放

data(){
	return{
		speed: 200,
		lineArr: [
          [116.478935, 39.997761],
          [116.478939, 39.997825],
          [116.478912, 39.998549],
          [116.478912, 39.998549],
          [116.478998, 39.998555],
          [116.478998, 39.998555],
          [116.479282, 39.99856],
          [116.479658, 39.998528],
          [116.480151, 39.998453],
          [116.480784, 39.998302],
          [116.480784, 39.998302],
          [116.481149, 39.998184],
          [116.481573, 39.997997],
          [116.481863, 39.997846],
          [116.482072, 39.997718],
          [116.482362, 39.997718],
          [116.483633, 39.998935],
          [116.48367, 39.998968],
          [116.484648, 39.999861],
        ],
	}
}
mounted(){
	this.mapInit()
}
methods:{
	mapInit() {
        this.map = new AMap.Map('map', {
          zoom: 17, //级别
          center: [116.397428, 39.90923], //中心点坐标
          resizeEnable: true,
        })
  
        this.marker = new AMap.Marker({
          map: this.map,
          position: [116.478935, 39.997761],
          icon: 'https://webapi.amap.com/images/car.png',
          offset: new AMap.Pixel(-26, -13),
          autoRotation: true,
          angle: -90,
        })
  
        var polyline = new AMap.Polyline({
          map: this.map,
          path: this.lineArr,
          showDir: true,
          strokeColor: '#28F', //线颜色
          // strokeOpacity: 1,     //线透明度
          strokeWeight: 6, //线宽
          // strokeStyle: "solid"  //线样式
        })
        var passedPolyline = new AMap.Polyline({
          map: this.map,
          // path: lineArr,
          strokeColor: '#AF5', //线颜色
          // strokeOpacity: 1,     //线透明度
          strokeWeight: 6, //线宽
          // strokeStyle: "solid"  //线样式
        })
        this.marker.on('moving', function (e) {
          passedPolyline.setPath(e.passedPath)
        })
        this.map.setFitView()
        this.marker.moveAlong(this.lineArr, this.speed)
      },
}

在这里插入图片描述
默认加载后走完

//开始,暂停,继续,停止
marker.moveAlong()
marker.stopMove()
marker.pauseMove()
marker.resumeMove()

用轨迹回放可以做到开始暂停等控制操作,也可以用定义的speed做到倍速的控制

marker.moveAlong(this.lineArr, this.speed * 2)

但是需求是要有一个进度条来控制,轨迹回放不如轨迹巡航更方便
进度条控制:
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值