高德地图 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 {
      width: 100%;
      height: 100%;
    }

    #map-features .input-item {
      height: 2rem;
    }
  </style>
</head>

<body>
  <div id="container"></div>
  <div class="input-card" style="width:19rem">
    <h4>设置地图显示要素(Features)</h4>
    <div id="map-features">
      <div class="input-item">
        <input type='checkbox' name='mapStyle' value='bg' checked>
        <span class="input-text">区域面(bg)</span>
      </div>
      <div class="input-item">
        <input type='checkbox' name='mapStyle' value='road' checked>
        <span class="input-text">道路(road)</span>
      </div>
      <div class="input-item">
        <input type='checkbox' name='mapStyle' value='building' checked>
        <span class="input-text">建筑物(building)</span>
      </div>
      <div class="input-item">
        <input type='checkbox' name='mapStyle' value='point' checked>
        <span class="input-text">标注(point)</span>
      </div>
    </div>
  </div>
  <script src="https://cache.amap.com/lbs/static/es5.min.js"></script>
  <script src="https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值"></script>
  <script>
    //初始化地图
    var map = new AMap.Map('container', {
      zoom: 17,
      center: [116.408075, 39.950187],
      features: ['bg', 'road', 'building', 'point']
    });

    //设置地图显示要素
    function setMapFeatures() {
      var features = [];
      var inputs = document.querySelectorAll("#map-features input");
      inputs.forEach(function(input) {
        if (input.checked) {
          features.push(input.value);
        }
      });
      map.setFeatures(features);
    }

    //绑定checkbox点击事件
    var inputs = document.querySelectorAll("#map-features input");
    inputs.forEach(function(checkbox) {
      checkbox.onclick = setMapFeatures;
    });
  </script>
</body>

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