gpt4 book ai didi

maps - 使用 openlayers 3 加载 osm 文件

转载 作者:行者123 更新时间:2023-12-02 04:52:26 26 4
gpt4 key购买 nike

我正在使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com