Cesium学习An error occurred while rendering

Posted hankern

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Cesium学习An error occurred while rendering相关的知识,希望对你有一定的参考价值。

基于Cesium1.68进行学习。

在Firefox、chrome中运行下面文件都会遇到问题。

<!DOCTYPE html>
<html lang="en">
<head>
  <!-- Use correct character set. -->
  <meta charset="utf-8">
  <!-- Tell IE to use the latest, best version. -->
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <!-- 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>
    var viewer = new Cesium.Viewer('cesiumContainer');
  </script>
</body>
</html>

 

An error occurred while rendering. Rendering has stopped.
SecurityError: The operation is insecure.
Texture@file:///E:/Download/Cesium-1.68/Build/Cesium/Cesium.js:1:844528
Material.prototype.update@file:///E:/Download/Cesium-1.68/Build/Cesium/Cesium.js:1:870427
EllipsoidPrimitive.prototype.update@file:///E:/Download/Cesium-1.68/Build/Cesium/Cesium.js:1:2534538
Moon.prototype.update@file:///E:/Download/Cesium-1.68/Build/Cesium/Cesium.js:1:2767305
Scene.prototype.updateEnvironment@file:///E:/Download/Cesium-1.68/Build/Cesium/Cesium.js:1:3035366
render@file:///E:/Download/Cesium-1.68/Build/Cesium/Cesium.js:1:3038869
tryAndCatchError@file:///E:/Download/Cesium-1.68/Build/Cesium/Cesium.js:1:3039129
Scene.prototype.render@file:///E:/Download/Cesium-1.68/Build/Cesium/Cesium.js:1:3040991
CesiumWidget.prototype.render@file:///E:/Download/Cesium-1.68/Build/Cesium/Cesium.js:1:3284455
e@file:///E:/Download/Cesium-1.68/Build/Cesium/Cesium.js:1:3270826

解决办法:

搭建网络服务器,不要在浏览器中直接打开html文件

 

 

建立web服务器

为了运行Cesium项目, 我们需要一个本地的web服务器来发布我们的文件. 这里我们将使用Node.js做为服务器. 如果你已经有一个自己想使用web服务器, 那也是可以的. Cesium对服务端是没有要求的, 它完全是一个客户端. 这意味着任何可以承载静态内容的web服务器都可以托管Cesium.(eclipse动态web项目, HBuilder都可以发布这个工程)

用Node.js设置web服务器很简单,只需要3步:

    1.从官网https://nodejs.org/en/下载Node.js, 你可以使用默认的安装设置.

    2.使用cmd命令行进入Cesium工程的根目录, 通过执行 npm install 来下载和安装需要的模块. 这会在Cesium工程的根目录创建一个‘node_modules’文件夹.

目录下多了一个node_modules文件夹

    3.在Cesium工程的根目录, 通过cmd执行node server.js来启动web服务器.

然后通过http://localhost:8080/访问

 

 

待继续分析列表:

1、Cesium与osgEarth对比分析((一)中问题)

2、如何加载googleearth的数据((一)中问题)

3、Cesium是否有帧循环((一)中问题)

 

 

以上是关于Cesium学习An error occurred while rendering的主要内容,如果未能解决你的问题,请参考以下文章