高德地图 JS API示例-矢量图形- › 多边形的绘制和编辑

高德地图 JS API示例-矢量图形- › 多边形的绘制和编辑

<!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">
    <title>矩形的绘制和编辑</title>
    <style>
      html,
      body,
      #container {
        width: 100%;
        height: 100%;
      }
    </style>
    <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.RectangleEditor"></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="rectangleEditor.open()" style="margin-bottom: 5px">开始编辑</button> 
   <button class="btn" onclick="rectangleEditor.close()">结束编辑</button> 
</div>
<script>
    var map = new AMap.Map('container', {
        center: [ 116.387175, 39.876405 ],
        zoom: 13
    });

    var southWest = new AMap.LngLat(116.356449, 39.859008)
    var northEast = new AMap.LngLat(116.417901, 39.893797)

    var bounds = new AMap.Bounds(southWest, northEast)

    var rectangle = new AMap.Rectangle({
        bounds: bounds,
        strokeColor:'red',
        strokeWeight: 6,
        strokeOpacity:0.5,
        strokeDasharray: [30,10],
        // strokeStyle还支持 solid
        strokeStyle: 'dashed',
        fillColor:'blue',
        fillOpacity:0.5,
        cursor:'pointer',
        zIndex:50,
    })

    rectangle.setMap(map)
    // 缩放地图到合适的视野级别
    map.setFitView([ rectangle ])

    var rectangleEditor = new AMap.RectangleEditor(map, rectangle)

    rectangleEditor.on('adjust', function(event) {
        log.info('触发事件:adjust')
    })

    rectangleEditor.on('end', function(event) {
        log.info('触发事件: end')
        // event.target 即为编辑后的矩形对象
    })

</script>
</body>
</html>
0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x