3

按照switch2osm.org 上的指南,我能够让我自己的 OSM tile 服务器运行。

我确实使用 webbrowser 验证了我的 OSM 磁贴服务器的状态。例如在http://localhost/osm_tiles/0/0/0.png我得到小图片 od world。Evertthing 似乎在我的服务器端工作。

连接到在线地图资源的铯也可以正常工作。

当我尝试将 Cesium 连接到本地 OSM 服务器时,会出现问题。在 Firefox 控制台中,我收到此错误:

““发生错误:获取图像瓦片失败 X:1 Y:1 级别:1。” Cesium.js:381:25514 ““发生错误:无法获取图像平铺 X:1 Y:0 级别:1。” Cesium.js:381:25514 ““出现错误:获取图像瓦片 X:0 Y:0 级别:1 失败。” Cesium.js:381:25514 ““发生错误:无法获取图像平铺 X:0 Y:1 级别:1。” 铯.js:381:25514

我被这个问题困扰了几天。搜索网络并没有为我提供任何有用的线索。

这是我正在运行 Cesium 的网页的源代码:

<!DOCTYPE html>
<html lang="en">
<head>
<!-- Use correct character set. -->
<meta charset="utf-8">
<!-- Tell IE to use the latest, best version (or Chrome Frame if pre-IE11). -->
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<!-- Make the application on mobile take up the full browser screen and disable user scaling. -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<title>Hello World!</title>
<script src="../Build/Cesium/Cesium.js"></script>
<style>
  @import url(../Build/Cesium/Widgets/widgets.css);
  html, body, #cesiumContainer {
      width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
  }
</style>
</head>
<body>
<div id="cesiumContainer"></div>
<script>

//Initialize the viewer widget with several custom options and mixins.
var viewer = new Cesium.Viewer('cesiumContainer', {
//Hide the base layer picker
baseLayerPicker : false,
//Use OpenStreetMaps
imageryProvider : new Cesium.OpenStreetMapImageryProvider({
    url : 'http://localhost/osm_tiles/'
  //url : '//a.tile.openstreetmap.org/'
}),

// Show Columbus View map with Web Mercator projection
//    mapProjection : new Cesium.WebMercatorProjection()
});

//Add basic drag and drop functionality
viewer.extend(Cesium.viewerDragDropMixin);

//Show a pop-up alert if we encounter an error when processing a dropped file
viewer.dropError.addEventListener(function(dropHandler, name, error) {
console.log(error);
window.alert(error);
});
</script>
</body>
</html>
4

2 回答 2

2

您是否在您的磁贴服务器上启用了 CORS(跨域资源共享)?源定义为 URI 方案、主机名和端口号。即使您的 tileserver 和 Cesium 都在 localhost 上运行,您需要配置服务器以提供 CORS 标头,以便 Cesium 使用图像。有关如何在 osm apache 服务器上配置 CORS 的说明,请参阅http://enable-cors.org/server_apache.html 。

于 2015-03-12T00:34:05.137 回答
0

我仍然遇到这个问题(在Cesium 邮件列表中报告了同样的问题),我正在使用 Python 的 SimpleHTTPServer 来提供磁贴。当我切换到启用 CORS 的网络服务器时,问题就消失了。

真正令人困惑的是,普通的 SimpleHTTPServer(非 CORS)正在打印来自 Cesium 的带有 HTTP 200 成功代码的请求,因此它似乎正在为 Cesium 的请求提供服务,但 Cesium 会报告您发现的错误。切换到 CORS 仍然是解决方案。

于 2015-11-29T14:47:24.147 回答