高德地圖 Javascript API 入門(四)

高德地圖 Javascript API 入門(四)

地圖覆蓋物

覆蓋物

類名 說明 是否插件
AMap.Marker 點標記
AMap.Icon 覆蓋物>點標記>複雜點標記對象,對普通點標記Marker 的擴展
AMap.Polyline 覆蓋物>折線
AMap.Polygon 覆蓋物>多邊形
AMap.Circle 覆蓋物>圓
AMap.GroundImage 圖片覆蓋物
AMap.ContextMenu 地圖右鍵菜單
#### 點標記 JS
var marker=new AMap.Marker({
        map:map,
        position:new AMap.LngLat(112.736465,37.696495)
    });

預覽spa

iamge

自定義點標記插件

JS3d

var marker=new AMap.Marker({
        map:map,
        position:new AMap.LngLat(112.736465,37.696495),
        icon:new AMap.Icon({
            image:"https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2803620233,1906638381&fm=23&gp=0.jpg",
            size:[72,72],
            imageSize:[36,36]
        }),
        draggable:true,
        raiseOnDrag:true,
        shape:new AMap.MarkerShape({
            type:"circle",
            coords:[112.736465,37.696495,100]
        }),
        label:{
            content:"label",
            offset:new AMap.Pixel(0,-36)
        }
    });

預覽code

image

多邊形

JS對象

var lineArr=[
        [112.49157,37.897392],
        [112.602806,37.898747],
        [112.608643,37.797355],
        [112.49775,37.79627]
    ];
    var polygon=new AMap.Polygon({
        map:map,
        path:lineArr
    });

預覽blog

image

右鍵菜單

JSseo

var contextmenu=new AMap.ContextMenu();
    var pos=[];
    // 添加右鍵菜單內容項
    contextmenu.addItem("放大",function () {
        map.zoomIn();
    },0);
    contextmenu.addItem("縮小",function () {
        map.zoomOut();
    },1);
    contextmenu.addItem("添加點標記",function () {
        var marker=new AMap.Marker({
            map:map,
            position:pos
        });
    },2);
    // 監聽鼠標右擊事件
    map.on("rightclick",function (e) {
        contextmenu.open(map,e.lnglat);
        pos=e.lnglat;
    });

預覽事件

image

信息窗體

信息窗體

JS圖片

var infowindow=new AMap.InfoWindow({
        isCustom:false,
        content:"<h3>Hello,Yuanping</h3>",
        offset:new AMap.Pixel(0,-36),
        showShadow:true,
        closeWhenClickMap:true,
        autoMove:true
    });
    infowindow.open(map,new AMap.LngLat(112.736465,38.696495));

預覽ip

image

小練習

鼠標劃過山西大劇院時,彈出信息窗體

JS

// 座標
    var lineArr=[
        [112.532802,37.808395],
        [112.533049,37.808395],
        [112.533124,37.808476],
        [112.533521,37.808459],
        [112.533558,37.808391],
        [112.533832,37.808391],
        [112.533848,37.80792],
        [112.534159,37.807959],
        [112.534159,37.80748],
        [112.533826,37.807514],
        [112.533832,37.807179],
        [112.533966,37.806848],
        [112.533376,37.806683],
        [112.533054,37.806687],
        [112.532684,37.806878],
        [112.53278,37.807191],
        [112.532796,37.80745],
        [112.532013,37.807285],
        [112.532019,37.808213],
        [112.532796,37.808018],
        [112.532818,37.808412]
    ];
    // 實例化Polygon類
    var polygon=new AMap.Polygon({
        map:map,
        path:lineArr
    });
    // 適應窗口
    map.setFitView();
    // 實例化信息窗體類
    var infowindow=new AMap.InfoWindow({
        content:"<h3>太原市</h3><p>山西大劇院</p>",
        closeWhenClickMap:true
    });
    // 監聽鼠標移入、移除事件
    polygon.on("mouseover",function (e) {
        infowindow.open(map,map.getCenter());
    }).on("mouseout",function () {
        infowindow.close();
    });

預覽

image


參考來源:http://lbs.amap.com/
做者:Yangfan

相關文章
相關標籤/搜索