maps - 使用 openlayers 3 加载 osm 文件

标签 maps openstreetmap openlayers-3

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

有什么建议吗?

最佳答案

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

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

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

<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>

关于maps - 使用 openlayers 3 加载 osm 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26662788/

相关文章:

android - 带有 IntentChooser 的导航应用程序——这是同一个查询吗?

javascript - 谷歌地图 - setIcon 代码使标记消失

postgresql - 使用 osm2pgsql 将 .pbf 转换为 postgresql(磁盘空间不足)

javascript - OpenLayers 3 弹出窗口?

openstreetmap - Openstreetmap API - Openlayers/MapQuest

ios - 长按删除 Google map GMSMarker

c++ - 使用 map 的 Dijkstra 算法未正确添加值

android - Linux - 如何使用 Gradle 为 android studio 安装 osmdroid 库?

lua - 如何在 OSRM 配置文件中使用外部数据

javascript - 在 OpenLayers map 中显示多边形