cesium解决DeveloperError报错‘Expected longitude to be typeof number, actual type of was string‘
文章目录
- 1.出现问题
- 2.解决方法
- 2.1确定报错位置
- 2.2对症修改
Cesium实战系列文章总目录
: 传送门
1.出现问题
背景:在进行Cesium项目开发时,将Cesium.js
版本从压缩版本
转换为未压缩版本
(便于开发调试)时就会出现DeveloperError
报错Expected longitude to be typeof number, actual type of was string
即只是切换Cesium.js版本,未做其他任何更改。
2.解决方法
看报错信息可以发现是check.js
在进行类型检查时报错,即要求是数字类型,但实际是字符串。但是为什么压缩版的Cesium.js没有报错?这里猜想可能是没有进行类型检查。
2.1确定报错位置
查看报错信息可知,报错位置是在使用primitive方式加载geojson数据绘制墙体
上。
2.2对症修改
(1)报错说类型应该为number,而非string,那就将string转换为number
let positionArray = [];
// 将字符串数组polyonArray转换为数字数组positionArray
for (element of polygonArray) {positionArray.push(Number(element));
}
(2)将字符串转换为数字后,WallGeometry.js
又报错options.positions and options.maximumHeights must have the same length
即墙体的高度数组应该和底部坐标数组的长度一致。设置代码如下:
const geometry = new Cesium.WallGeometry({positions: Cesium.Cartesian3.fromDegreesArray(positionArray),// 设置高度maximumHeights: new Array(positionArray.length / 2).fill(50),minimunHeights: new Array(positionArray.length / 2).fill(0),})
(3)修改后即可正确显示。
整体函数代码:
// 使用primitive方式加载geojson
let urlPath = './data/park/parks.geojson';
// 使用jQuery异步加载json数据
$.get(urlPath, function(data) {const features = data.features;addDataToGlobe(features);
})function addDataToGlobe(features) {const instances = [];for (let i = 0; i < features.length; i++) {for (let j = 0; j < features[i].geometry.coordinates.length; j++) {// 将字符串按照","拆分为数组polygonArray = features[i].geometry.coordinates[j].toString().split(',');}let positionArray = [];// 将字符串数组转换为数字数组for (element of polygonArray) {positionArray.push(Number(element));}const geometry = new Cesium.WallGeometry({positions: Cesium.Cartesian3.fromDegreesArray(positionArray),// 设置高度maximumHeights: new Array(positionArray.length / 2).fill(50),minimunHeights: new Array(positionArray.length / 2).fill(0),})instances.push(new Cesium.GeometryInstance({geometry: geometry,attributes: {color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.GREEN),},}));}// 合并单个geometry,提高渲染效率const primitive = new Cesium.Primitive({geometryInstances: instances,// PerInstanceColorAppearance:使用每个实例自定义的颜色着色appearance: new Cesium.PerInstanceColorAppearance(),});this.viewer.scene.primitives.add(primitive);
}
修改后正确运行绘制的墙体效果:
cesium解决DeveloperError报错‘Expected longitude to be typeof number, actual type of was string‘相关推荐
- cesium解决报错“Expected listener to be typeof function, actual typeof was undefined“
文章目录 1.出现问题 2.解决方法 Cesium实战系列文章总目录: 传送门 1.出现问题 在Cesium开发过程中,添加事件监听的过程中出现报错:name: 'DeveloperError', m ...
- 报错:SON parse error: Cannot deserialize value of type `java.lang.String` from Array value (token `Jso
详细报错 JSON parse error: Cannot deserialize value of type java.lang.String from Array value (token Jso ...
- 解决Mybatis报错问题:org.apache.ibatis.binding.BindingException: Type interface com.kuang.dao.UserDao is
解决方案分为两种情况: 1.在mybatis核心配置文件中(mybatis-config.xml)配置mappers <!--每一个Mapper.xml文件都需要在mybatis核心配置文件中注 ...
- elasticsearch报错expected <block end>, but found BlockMappingStart解决方法
elasticsearch报错expected , but found BlockMappingStart解决方法 参考文章: (1)elasticsearch报错expected , but fou ...
- [已解决]Object c,报错Expected method body
Object c,报错Expected method body 原因分析:因为我将应该写在头文件Person.h的声明,写在和实现的Person.m文件中了 解决办法:将这些声明放在头文件Person ...
- cesium 开发记录报错:DeveloperError: Appearance/Geometry mismatch.
cesium 开发记录报错:DeveloperError: Appearance/Geometry mismatch. The appearance requires vertex shader at ...
- 解决yolov5 报错 ValueError: not enough values to unpack (expected 3, got 0)
解决yolov5 报错 ValueError: not enough values to unpack (expected 3, got 0) *注意报错提示 :labels, shapes, sel ...
- path manipulation怎么解决_PyCharm报错与解决方法一览
报错: IndentationError:expected an indented block 分析: 缩进错误! 解决: 你只要在出现错误的那一行,按空格或Tab(但不能混用)键缩进就行.往往有的人 ...
- clickhouse 报错 “Unmatched parentheses: (“ 或者报错 “Expected one of: CODEC, NULL, ALIAS, TTL, ClosingR
环境 启动服务 docker run -d --name some-clickhouse-server --ulimit nofile=262144:262144 yandex/clickhouse- ...
最新文章
- 如何用技术恢复模糊的图像?在线教学…
- cuda合并访问的要求_CUDA优化的冷知识 5 | 似是而非的计时方法
- 语音识别可以直接编码吗
- Java中基本数据类型和Object之间的关系
- 【Pandas】apply,applymap和map的区别
- Codeforces 1109F. Sasha and Algorithm of Silence's Sounds
- wxWidgets:wxMenuItem类用法
- IOS 开发环境,证书和授权文件等详解
- (LeetCode 83)Remove Duplicates from Sorted Lists
- golang-context
- 服务器产品的特质和优势,亿速云裸金属服务器兼具“弹性”和“裸金属”两种属性,既有虚拟机的弹性,同时又保留了裸金属的一切性能、特性和优势!...
- pythonifnotnone_python中if not x: 和 if x is not None: 和 if not x is None的使用和区别
- Hdu - 1210 - Eddy's 洗牌问题
- linux shell 脚本使用
- 数据结构笔记(二十一)--二叉树的遍历
- idea 添加格式化json插件GsonFormat 和快速解析第三方返回json数据
- 分享一个好用的Python在线编辑器
- 蓝牙sbc怎么解决_你不知道蓝牙耳机术语,看懂了才明白哪些是优质蓝牙耳机
- html自动幻灯片代码,简单常用的幻灯片播放实现代码
- 分页虚拟存储管理——页面置换算法例题