繁体   English   中英

Cesium:使用自己的OpenStreetMap服务器。 :'无法获取图像图块'错误

[英]Cesium : Using own OpenStreetMap server. : 'Failed to obtain image tile' Error

在switch2osm.org的指南之后我能够运行我自己的OSM 贴服务器。

我确实使用webrowser验证了我的OSM磁贴服务器的状态。 例如,在http://localhost/osm_tiles/0/0/0.png,我得到了小图片od世界。 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。“ Cesium.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>

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM