高德地图在marker里设置自定义属性

转载 2020-05-25 19:28 Java 29
javascript 复制代码
var map = new AMap.Map('container', {
        resizeEnable: true,
        zoom:11,
        center: [116.397428, 39.90923]//默认的地图中心经纬度
    });

//  在地图上设置marker点
var markerTemp = new AMap.Marker({
    position : [lng,lat],    //  里面是经纬度
    offset : new AMap.Pixel(-21,-21),//偏移量,默认以marker左上角位置为基准点
    map : map
});

//  给marker里设置自定义属性
markerTemp.id = "123";


//  给marker添加点击事件,获取获取e对象
  AMap.event.addListener(auto, "select", select);
    function select(e) {
    //  获取存入的id
     console.log(e.target.id);
        var lng = e.poi.location.lng;
        var lat = e.poi.location.lat;
        console.log(e.poi.location.lng);
        if (e.poi && e.poi.location) {
            map.setZoom(15);
            map.setCenter(e.poi.location);
            addMarker(lng,lat);
        }
    }
点赞
收藏
关注
转发
本文作者: Veddy
版权声明: 本博客所有文章除特别声明外,均采用 CC BY 4.0 CN协议进行许可。转载请署名作者且注明文章出处。
文章目录