[使用openlayers 3加载osm文件

问题描述 投票:3回答:1

我正在使用openlayers 3(http://openlayers.org/),并且我试图在地图中加载osm文件。在旧版本的openlayers中,此任务非常简单(http://wiki.openstreetmap.org/wiki/OpenLayers_osm_file_example),但现在使用openlayers 3,我无法做类似的事情。

有任何建议吗?

maps openstreetmap openlayers-3
1个回答
0
投票

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

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

OpenLayers(开放式街道地图)在代码中使用以下两个文件...

<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>
© www.soinside.com 2019 - 2024. All rights reserved.