高德地图开放平台api---基础功能

1.地图初始化

 1 const that = this;
 2         AMapUI.loadUI(["geo/DistrictCluster", "control/BasicControl", "overlay/SimpleMarker"],
 3           function (DistrictCluster, BasicControl, SimpleMarker) {
 4             that.map = new AMap.Map('map', {
 5               scrollWheel: true,
 6               resizeEnable: false,
 7               zoom: that.myzoom,
 8               center: ['118.757996','30.945667']
 9             })
10             // 信息窗体
11             that.infoPopup = new AMap.InfoWindow({
12               offset: new AMap.Pixel(5, -10)
13             })
14         // 添加坐标点
15             that.addMarks()            
16           }
17         );
View Code

2.单个坐标点添加

let marker = new AMap.Marker({
     position: pos,  
     icon: new AMap.Icon({
         image:'/static/images/location.png',
         size: new AMap.Size(30, 30),
          imageSize: new AMap.Size(30, 30)
        }),
        extData: {}, // 可添加额外信息
    });
this.map.add(marker )
View Code

3.多个坐标点添加

that.bounds.forEach(item => {
        let marker = ''       
        marker = new AMap.Marker({
              position: [item.o, item.a],  
              icon: new AMap.Icon({
                image:'/static/images/location-red.png',
                size: new AMap.Size(30, 30),
                imageSize: new AMap.Size(30, 30)
              }),
              extData: [item.o, item.a],
            });
         markers.push(marker)
        // 给坐标点添加鼠标点击事件
         marker.on("click", function (e) {
            let pos = e.target.getExtData()
            that.markerClickEvent()
          }, marker)
        })
 that.map && that.map.add(markers)
View Code

4.点击坐标点弹出信息窗体

let content = '<div class="supv-point-pos">' +
          '<p class="supv-pop-title">场所名称:' + that.usePlaceName + '</p>'+
          '<p class="supv-pop-title">距离电梯间距:' + distance + '米</p>'+
        '</div>'
        that.infoPopup.setContent(content)
        that.infoPopup.open(that.map, e.target.getPosition())
View Code

5.两点间距离试算

let pos1 = marker1.getPosition()
let pos2 = marker1.getPosition()
let distance = Math.round(pos1.distance(pos2))
View Code

6.更新锚点坐标

updateLocateMarker(lng, lat){
   this.positionMarker && this.positionMarker.start([lng, lat])
   this.map.setZoomAndCenter(this.zoom,[lng,lat])
 },
View Code

 

 

高德地图开发中的注意点:

1.系统引入高德地图后,会发现多了很多http://vdata.amap.com/nebula/v3 的请求,可采用如下方法,禁用浏览器发送相关请求

let map = new AMap.Map('mapId', {                
    layers: [new AMap.TileLayer()] // 禁用实时交通图层
})

 

posted @ 2023-03-15 17:33  cmwang2017  阅读(65)  评论(0编辑  收藏  举报