【问题标题】:Unable to determine Cesium base URL automatically (Typescript)无法自动确定 Cesium 基本 URL(Typescript)
【发布时间】:2019-11-22 08:58:54
【问题描述】:

我正在尝试为 react typescript 设置 cesium 和 resium,但在最初的步骤中遇到了困难。我目前正在参考以下resium website 的步骤,从这里我已经安装了软件包并尝试根据以下steps 设置webpack。根据步骤,我安装了以下软件包

  • npm install copy-webpack-plugin html-webpack-plugin html-webpack-include-assets-plugin
  • npm install cesium resium

还展示了以下example,因此我尝试尽可能地模仿设置,在我的根目录中创建和调整以下文件

  • webpack.config.js
  • package.json(添加脚本)

完成后,我将webpack.config.js 中的以下设置CESIUM_BASE_URL: JSON.stringify("/cesium") 更改为指向我的python 服务器(https://localhost:5000) 以获得必要的磁贴。

有了这个,我预计该错误至少会消失,或者甚至可能会说明另一个错误,例如“找不到资产 XXX”。但是声明DeveloperError: Unable to determine Cesium base URL automatically, try defining a global variable called CESIUM_BASE_URL 的错误仍然存​​在。

我也尝试在env.local 中为CESIUM_BASE_URL 设置一个变量,但它仍然不起作用。任何缺少步骤的指针或指导将不胜感激。

【问题讨论】:

    标签: typescript webpack cesium


    【解决方案1】:

    将此脚本添加到您的 index.html 之前(或仅在 cesium 之前)

        ...
        </body>
        <script>
          window.CESIUM_BASE_URL = 'https://localhost:5000/';
        <script>
        <script>
        ...
    

    资源:
    https://cesium.com/blog/2016/01/26/cesium-and-webpack/#ive-already-got-webpack-set-up-just-tell-me-how-to-use-cesium https://github.com/opensensorhub/osh-js/issues/55

    【讨论】:

      【解决方案2】:

      执行此操作的最佳方法可能是在您的 webpack.config.js 文件中添加来自 webpack 的 CopyPlugin

      在配置中:

            new DefinePlugin({
              CESIUM_BASE_URL: JSON.stringify(env.CESIUM_BASE_URL || 'http://localhost/'),
            }),
      

      【讨论】:

        【解决方案3】:
        configureWebpack: {
             plugins: [
              new CopyWebpackPlugin({
                patterns: [
                  { from: Path.resolve('./node_modules/cesium/Source/Workers'), to: 'Workers' },
                  { from: Path.resolve('./node_modules/cesium/Source/Assets'), to: 'Assets' },
                  { from: Path.resolve('./node_modules/cesium/Source/Widgets'), to: 'Widgets' },
                  { from: Path.resolve('./node_modules/cesium/Source/ThirdParty/Workers'), to: 'WoThirdParty/Workersrkers' },
                ]
              }),
              new webpack.DefinePlugin({
              CESIUM_BASE_URL: JSON.stringify('./')
              })
              ],
          },
        
        

        【讨论】:

          猜你喜欢
          • 2018-04-21
          • 2022-06-22
          • 1970-01-01
          • 2023-02-20
          • 2015-09-24
          • 1970-01-01
          • 1970-01-01
          • 2010-09-06
          • 2014-11-01
          相关资源
          最近更新 更多