3

我正在使用 openlayers 3 ( http://openlayers.org/ ),我正在尝试在我的地图中加载一个 osm 文件。在旧版本的 openlayers 中,这个任务非常简单(http://wiki.openstreetmap.org/wiki/OpenLayers_osm_file_example)但是现在使用 openlayers 3 我不能做类似的事情。

有什么建议吗?

4

1 回答 1

0

一个简单的“OpenLayers 3”(开放街道地图)示例

如果您尝试使用 OpenLayers 3,您可以尝试使用https://openlayers.org/en/latest/doc/quickstart.html示例,它在本地运行得非常好,并且是相当简单的 JavaScript。

OpenLayers(Open Street Maps)在代码中使用了以下两个文件...

<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v6.1.1/build/ol.js"></script>
<link rel="stylesheet"
href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v6.1.1/css/ol.css">

https://openlayers.org/en/latest/doc/quickstart.html

如果您需要在计算机上进行本地测试,这是上面示例中的代码。

<!doctype html>
<html lang="en">
  <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.1.1/css/ol.css" type="text/css">
    <style>
      .map {
        height: 400px;
        width: 100%;
      }
    </style>
    <script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.1.1/build/ol.js"></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',
        layers: [
          new ol.layer.Tile({
            source: new ol.source.OSM()
          })
        ],
        view: new ol.View({
          center: ol.proj.fromLonLat([37.41, 8.82]),
          zoom: 4
        })
      });
    </script>
  </body>
</html>
于 2019-12-08T23:55:17.057 回答