我'm trying to create map based web app which user can set landmark on the provided map. Boundaries of map is limited to a small city, and the client computer is always offline, no internet access at all. After a whole day of googling I'已经发现OpenLayers和OpenStreetMap的组合是一个不错的选择 .
以下示例由 OpenLayers 网站提供:
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="http://openlayers.org/en/v3.0.0/css/ol.css" type="text/css">
<style>
.map {
height: 400px;
width: 100%;
}
</style>
<script src="http://openlayers.org/en/v3.0.0/build/ol.js" type="text/javascript"></script>
<title>OpenLayers 3 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.MapQuest({layer: 'sat'})
})
],
view: new ol.View({
center: ol.proj.transform([37.41, 8.82], 'EPSG:4326', 'EPSG:3857'),
zoom: 4
})
});
</script>
</body>
</html>
这很好,但需要连接互联网的电脑 . 经过几个小时的谷歌搜索,我发现另一个website提供 .osm
格式的离线 OpenStreetMap 数据 . 现在我不知道是否可以用这些 .osm
文件提供OpenLayers,就像本地 Map 服务器一样?客户端计算机正在运行 IIS 8
1 回答
要使用OpenLayers(或Leaflet)离线显示 Map ,您需要使用栅格tiles .
.osm
文件无法直接显示,因为它包含原始矢量数据并且必须先渲染 .要生成切片,请查看Maperitive或TileMill . 然后导入country or area extract . 或者你可以set up your own rendering server,这需要更多的工作 .