其他分享
首页 > 其他分享> > Openlayers案例2——addLayer动态加载OSM地图

Openlayers案例2——addLayer动态加载OSM地图

作者:互联网

Openlayers案例2——addLayer动态加载OSM地图

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>addLayer动态加载OSM地图</title>
  <link rel="stylesheet" href="openlayers/css/ol.css">
  <script src="openlayers/build/ol.js"></script>
  <style>
    #map {
      height: 100%;
      width: 100%;
      position: absolute;
    }
  </style>
</head>

<body>
  <div id="map"></div>

  <script>
    var map = new ol.Map({
      target: 'map',
      layers: [], // 创建图层容器,但不添加图层数据
      view: new ol.View({
        center: [0, 0],
        zoom: 2,
      })
    });

    var tileLayer = new ol.layer.Tile({
      source: new ol.source.OSM(),
    }); // 创建图层数据
    map.addLayer(tileLayer); // 图层添加至地图
  </script>
</body>

</html>

标签:map,ol,Openlayers,new,OSM,图层,addLayer
来源: https://blog.csdn.net/peanut2/article/details/113358931