vue 高德地图 实时路况

先放效果图

 

1、准备工作

 路况信息只需要使用web端即可实现

 

2、代码部分

(1)在/public/index.html中引入

<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=准备工作中添加的key"></script>

(2)在需要用到地图的页面中

<template>
  <div class="traffic-congestion-data-container">
    <div id="amap-container" class="amap-container" />
  </div>
</template>
<script>
export default {
  data() {
    return {
      longAndLat: [108.94703, 34.25943]
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      var map = new AMap.Map('amap-container', {
        // 地图中心位置
        center: this.longAndLat,
        resizeEnable: true,
        // 主题色
        mapStyle: 'amap://styles/darkblue',
        // 地图层级
        zoom: 12
      })
      // 实时路况图层
      var trafficLayer = new AMap.TileLayer.Traffic({
        zIndex: 10,
        zooms: [7, 20]
      })
      trafficLayer.setMap(map)
    }
  }
}
</script>

官方给出了11中主题样式,没有满足需求的也可自定义主题

标准:normal

幻影黑:dark

月光银:light

远山黛:whitesmoke

草色青:fresh

雅士灰:grey

涂鸦:graffiti

马卡龙:macaron

靛青蓝:blue

极夜蓝:darkblue

酱籽:wine

(3)隐藏高德地图左下角logo,在/public/index.html中写入样式

<style type="text/css">
    .amap-logo{
        display: none;
        opacity:0 !important;
    }
    .amap-copyright {
        opacity:0;
    }
</style>

最后附上官方示例地址:实时路况图层-高德官方图层-示例中心-JS API 2.0 示例 | 高德地图API

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值