无法自动确定铯基 URL(打字稿)
Unable to determine Cesium base URL automatically (Typescript)
我正在尝试为 react typescript 设置 cesium 和 resium,但卡在了最初的步骤中。我目前正在参考以下 resium website, from here I have installed the packages and attempted to setup webpack based on the following steps 中的步骤。根据我安装以下包的步骤
- npm install copy-webpack-plugin html-webpack-plugin html-webpack-include-assets-plugin
- npm 安装铯resium
还提供了以下 example,因此我尝试尽可能地模仿设置,在我的根目录中创建和调整以下文件
- webpack.config.js
- package.json(添加脚本)
完成后,我更改了 webpack.config.js
中的以下设置 CESIUM_BASE_URL: JSON.stringify("/cesium")
以指向我的 python 服务器 (https://localhost:5000
) 以获得必要的图块。
有了这个,我预计错误至少会消失,或者甚至可能会出现另一个错误,例如 "Asset XXX not found"。但是错误 DeveloperError: Unable to determine Cesium base URL automatically, try defining a global variable called CESIUM_BASE_URL
仍然存在。
我也试过在env.local
中为CESIUM_BASE_URL
设置一个变量,但还是不行。将不胜感激对任何遗漏步骤的任何指示或指导。
在其他脚本之前(或在 cesium 之前)将此脚本添加到您的 index.html
...
</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
最好的方法可能是在您的 webpack.config.js
文件中添加来自 webpack 的 CopyPlugin
。
在配置中:
new DefinePlugin({
CESIUM_BASE_URL: JSON.stringify(env.CESIUM_BASE_URL || 'http://localhost/'),
}),
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('./')
})
],
},
我正在尝试为 react typescript 设置 cesium 和 resium,但卡在了最初的步骤中。我目前正在参考以下 resium website, from here I have installed the packages and attempted to setup webpack based on the following steps 中的步骤。根据我安装以下包的步骤
- npm install copy-webpack-plugin html-webpack-plugin html-webpack-include-assets-plugin
- npm 安装铯resium
还提供了以下 example,因此我尝试尽可能地模仿设置,在我的根目录中创建和调整以下文件
- webpack.config.js
- package.json(添加脚本)
完成后,我更改了 webpack.config.js
中的以下设置 CESIUM_BASE_URL: JSON.stringify("/cesium")
以指向我的 python 服务器 (https://localhost:5000
) 以获得必要的图块。
有了这个,我预计错误至少会消失,或者甚至可能会出现另一个错误,例如 "Asset XXX not found"。但是错误 DeveloperError: Unable to determine Cesium base URL automatically, try defining a global variable called CESIUM_BASE_URL
仍然存在。
我也试过在env.local
中为CESIUM_BASE_URL
设置一个变量,但还是不行。将不胜感激对任何遗漏步骤的任何指示或指导。
在其他脚本之前(或在 cesium 之前)将此脚本添加到您的 index.html
...
</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
最好的方法可能是在您的 webpack.config.js
文件中添加来自 webpack 的 CopyPlugin
。
在配置中:
new DefinePlugin({
CESIUM_BASE_URL: JSON.stringify(env.CESIUM_BASE_URL || 'http://localhost/'),
}),
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('./')
})
],
},