openlayers,创建map

ol.Map 是openlayers核心的部分

    此处引用openlayers官网上quirk start 源码

    

<!doctype html>
<html lang="en"> 
  <head>
    <link rel="stylesheet" href="https://openlayers.org/en/v4.2.0/css/ol.css" type="text/css">
    <style>
      .map {   //设置放置map的div的大小
        height: 400px;
        width: 100%;
      }
    </style>       
    <script src="https://openlayers.org/en/v4.2.0/build/ol.js" type="text/javascript"></script>          
    <title>OpenLayers example</title>
  </head>
  <body>
    <h2>My Map</h2>
    <div id="map" class="map"></div>
    <script type="text/javascript">
      var map = new ol.Map({
        target: 'map',  //对应的是插入map的div的id
        layers: [       //定义图层数组
          new ol.layer.Tile({   //创建地图层,底层
            source: new ol.source.OSM()   //设置地图层的source
          })
        ],
        view: new ol.View({
          center: ol.proj.fromLonLat([37.41, 8.82]),  //确定显示地图的中心点坐标
          zoom: 4                                     //设置地图放大倍数
        })
      });
    </script>
  </body>
</html>


相应的官网资料:点击打开链接


转载自:https://blog.csdn.net/Liluoqaq/article/details/75043687

You may also like...

退出移动版