Pis*_*3.0 78 javascript api maps openstreetmap
有没有办法在页面中嵌入/混搭OpenStreetMap(就像Google Maps API的工作方式一样)?
我需要在页面内部显示带有一些标记的地图,并允许拖动/缩放,可能是路由.我怀疑会有一些Javascript API,但我似乎无法找到它.
lha*_*hne 61
您需要使用一些JavaScript来显示您的地图.OpenLayers是这方面的首选.
有一个例子在http://wiki.openstreetmap.org/wiki/OpenLayers_Simple_Example和更高级的东西
http://wiki.openstreetmap.org/wiki/OpenLayers_Marker
和
http://wiki.openstreetmap.org/wiki/Openlayers_POI_layer_example
tot*_*dli 16
单击"运行代码片段"以查看带有标记的嵌入式OpenStreetMap滑动贴图.这是用Leaflet创建的.
// Where you want to render the map.
var element = document.getElementById('osm-map');
// Height has to be set. You can do this in CSS too.
element.style = 'height:300px;';
// Create Leaflet map on map element.
var map = L.map(element);
// Add OSM tile leayer to the Leaflet map.
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
// Target's GPS coordinates.
var target = L.latLng('47.50737', '19.04611');
// Set map's center to target with zoom 14.
map.setView(target, 14);
// Place a marker on the same location.
L.marker(target).addTo(map);Run Code Online (Sandbox Code Playgroud)
<script src="https://unpkg.com/leaflet@1.0.1/dist/leaflet.js"></script>
<link href="https://unpkg.com/leaflet@1.0.1/dist/leaflet.css" rel="stylesheet"/>
<div id="osm-map"></div>Run Code Online (Sandbox Code Playgroud)
注意:
我在这里使用了Leaflet的CDN版本,但您可以下载这些文件,以便您可以在自己的主机上提供服务.
如果您只是想在网页上嵌入 OSM 地图,最简单的方法是直接从 OSM 网站获取 iframe 代码:
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"
src="https://www.openstreetmap.org/export/embed.html?bbox=-62.04673002474011%2C16.95487694424327%2C-61.60521696321666%2C17.196751341562923&layer=mapnik"
style="border: 1px solid black"></iframe>
<br/><small><a href="https://www.openstreetmap.org/#map=12/17.0759/-61.8260">View Larger Map</a></small>Run Code Online (Sandbox Code Playgroud)
如果您想做更详细的事情,请参阅 OSM wiki“部署您自己的 Slippy Map ”。
我还将了解CloudMade的开发人员工具.它们提供了一个风格优美的OSM基础地图服务,一个OpenLayers插件,甚至是他们自己的轻量级,非常快速的JavaScript映射客户端.它们还托管自己的路由服务,您可以将其作为可能的要求.他们有很好的文档和示例.
| 归档时间: |
|
| 查看次数: |
103506 次 |
| 最近记录: |