高德地圖繪制多邊形圈范圍的例子+獲取圈的范圍經緯度


直接上代碼

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <style>
    html,
    body,
    #container {
      width: 100%;
      height: 100%;
    }
    </style>
    <title>多邊形的繪制和編輯</title>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
    <script src="https://webapi.amap.com/maps?v=1.4.15&key=你自己申請的key&plugin=AMap.PolyEditor"></script>
    <script src="https://a.amap.com/jsapi_demos/static/demo-center/js/demoutils.js"></script>
</head>
<body>
<div id="container"></div>
<div class="input-card" style="width: 120px">
   <button class="btn" onclick="polyEditor.open()" style="margin-bottom: 5px">開始編輯</button> 
   <button class="btn" onclick="polyEditor.close()">結束編輯</button> 
</div>
<script type="text/javascript">
    var map = new AMap.Map("container", {
        center: [116.400274, 39.905812],
        zoom: 14
    });

    var path = [
        [116.403322, 39.920255],
        [116.410703, 39.897555],
        [116.402292, 39.892353],
        [116.389846, 39.891365]
    ]

    var polygon = new AMap.Polygon({
        path: path,
        strokeColor: "#FF33FF", 
        strokeWeight: 6,
        strokeOpacity: 0.2,
        fillOpacity: 0.4,
        fillColor: '#1791fc',
        zIndex: 50,
    })

    map.add(polygon)
    // 縮放地圖到合適的視野級別
    map.setFitView([ polygon ])

    var polyEditor = new AMap.PolyEditor(map, polygon)

    polyEditor.on('addnode', function(event) {
        log.info('觸發事件:addnode')
    })

    polyEditor.on('adjust', function(event) {
        log.info('觸發事件:adjust')
    })

    polyEditor.on('removenode', function(event) {
        log.info('觸發事件:removenode')
    })

    polyEditor.on('end', function(event) {
        log.info('觸發事件: end')
        //獲取 結束后觸發
        console.info("end",event.target.w.path);
        // event.target 即為編輯后的多邊形對象
    })
</script>
</body>
</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM