Cesium学习(一)An error occurred while rendering

在学习Cesium 1.68过程中,在Firefox和Chrome浏览器运行时遇到问题。解决方法是搭建本地Web服务器,不直接通过浏览器打开HTML文件。通过Node.js简单三步设置Web服务器:安装Node.js,执行npm install,然后运行node server.js启动服务器,通过http://localhost:8080/访问。后续将分析Cesium与osgEarth对比、加载Google Earth数据以及Cesium的帧循环问题。
部署运行你感兴趣的模型镜像

基于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是否有帧循环((一)中问题)

 

 

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值