高德地图api使用Demo

 card.vue

<template>
  <div class="mapContainer">
      <div id="container">
      </div>
  </div>
</template>

<script>
 
  export default {
      components: {},
      data() {
          return {
              scrollH: 130,         
              heightData: '400px',
              zoom: 11,
              center: [116.244694, 39.517344],
              window: '',
              polygons: [],
              district: null,
              markers: [{
                  'cityName': '广州市',
                  'indexDay': '10',
                  'longitude': '113.25951799999996',
                  'latitude': '23.13171999000008'
              },
              {
                  'cityName': '韶关市',
                  'indexDay': '21',
                  'longitude': '113.59213880000004',
                  'latitude': '24.814891530000125'
              },
              {
                  'cityName': '深圳市',
                  'indexDay': '31',
                  'longitude': '114.0527770000001',
                  'latitude': '22.54555998000012'
              },
              {
                  'cityName': '珠海市',
                  'indexDay': '45',
                  'longitude': '113.57185000000004',
                  'latitude': '22.27383999'
              }]
          }
      },
      onLoad() {
      },
      mounted: function () {
          setTimeout(() => {
              this.drawBounds();
          }, 200);
      },
      methods: {
        addClickHandler(equiId,equiName,marker){
            console.log(marker)
            marker.on('click',function(){
                console.log(marker)
            })
      },
          drawBounds() {
              var _this = this
              // 创建地图实例
              var map = new AMap.Map('container', {
                  zoom: 7,
                  center: [113.57941, 23.10247],
                  resizeEnable: true
                  // mapStyle: 'amap://styles/自定义样式id'
              });
              map.clearMap();  // 清除地图覆盖物
              var marker = [];
              this.markers.forEach(function (marker, index) {
                  const backgroundColor = marker.indexDay < 20 ? '#FF8100' : (marker.indexDay < 30 ? '#8D3ECD' : (marker.indexDay < 40 ? '#2DCD72' : (marker.indexDay < 50 ? '#ff0000' : '#990000')))
                  const content = `<div style="display: flex;
                                    justify-content: center;
                                    align-items: center;
                                    border-radius: 2px;
                                    padding:2px 5px;
                                    font-size: 12px;
                                    color: #FFFFFF;
                                    box-shadow: 2px 2px 4px 0 rgba(0,0,0,0.30);
                                    background-color: ${backgroundColor};">
                                    <div> ${marker.indexDay} </div>
                         </div>`
                  var _marker =new AMap.Marker({
                      map: map,
                      position: [marker.longitude, marker.latitude],
                      offset: new AMap.Pixel(-13, -30),
                      content: content
                  });
                  _this.addClickHandler('equiId', 'equiName', _marker)
              });
          }
      }
  }

</script>

<style>
  html,
  body,
  #container,
  uni-page-body,
  .mapContainer {
      height: 100%;
      width: 100%;
  }
</style>

main.js

import AMap from 'vue-amap'
Vue.use(AMap);
  // 初始化vue-amap
AMap.initAMapApiLoader({
  // 高德key
  key: '',
  // 插件集合 (插件按需引入)
  plugin: ['AMap.Geolocation','Geolocation','AMap.DistrictSearch'],
  v: '1.4.4'
})

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值