高德地图 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>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
    <style>
        html, body, #container {
            height: 100%;
            width: 100%;
        }
    </style>
</head>
<body>
<div id="container"></div>
<div class="input-card">
    <input id="changeOverlayGroupAttr" type="button" class="btn" value="批量修改属性"/>
</div>
<script type="text/javascript"
        src="https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值"></script>
<script type="text/javascript">
    // 创建地图实例
    var map = new AMap.Map("container", {
        zoom: 14,
        center: [116.396959,39.918288],
        resizeEnable: true
    });

    var paths = [
        [new AMap.LngLat(116.367519,39.921711), new AMap.LngLat(116.414383,39.929017)],
        [new AMap.LngLat(116.370953,39.915918), new AMap.LngLat(116.429489,39.907293)]
    ];

    var polylines = [];

    for (var i = 0; i < paths.length; i++) {
        var path = paths[i];

        // 创建线实例
        var polyline = new AMap.Polyline({
            path: path,
            strokeWeight: 6,
            strokeColor: '#3366FF',
            isOutline: true,
            borderWeight: 3,
            outlineColor: '#ffeeff'
        });

        polylines.push(polyline);
    }

    var overlayGroups = new AMap.OverlayGroup(polylines);

    map.add(overlayGroups);

    // 批量改变 overlaygroup 内覆盖物的属性
    function changeAttribute (){

        overlayGroups.setOptions({
            strokeColor: '#ffeeff',
            outlineColor: '#3366FF'
        });
    }

    // 绑定获取覆盖物事件
    document.getElementById("changeOverlayGroupAttr").onclick = changeAttribute;
</script>
</body>
</html>
0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x