V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
southcat996
V2EX  ›  JavaScript

Cesium 运动实体消失的时候报错 Uncaught TypeError: Cannot read property ‘x‘ of undefined

  •  
  •   southcat996 · 2023-06-13 16:51:12 +08:00 · 814 次点击
    这是一个创建于 521 天前的主题,其中的信息可能已经有所发展或是发生改变。
    {
        "id": "2129c05288d445708a601d5953be57ac",
        "name": "测试 001",
        "type": "004",
        "properties": {
            "status": "use"
        },
        "position": {
            "interpolationAlgorithm": "LAGRANGE",
            "interpolationDegree": 1,
            "epoch": "2022-09-10T00:00:00Z",
            "cartographicDegrees": [
                0,
                11,
                22,
                100,
                5000,
                33,
                55,
                200
            ]
        },
        "model": {
            "show": true,
            "gltf": "http://localhost:1024/earth/model/missile.glb",
            "scale": 10,
            "minimumPixelSize": 16
        },
        "label": {
            "fillColor": {
                "rgba": [
                    233,
                    150,
                    122,
                    255
                ]
            },
            "outlineWidth": 2,
            "verticalOrigin": "CENTER",
            "outlineColor": {
                "rgba": [
                    0,
                    0,
                    0,
                    255
                ]
            },
            "show": true,
            "horizontalOrigin": "LEFT",
            "scale": 0.5,
            "style": "FILL_AND_OUTLINE",
            "text": "测试",
            "pixelOffset": {
                "cartesian2": [
                    5,
                    -60
                ]
            },
            "font": "21pt Lucida Console"
        }
    }
    

    这里创建了一个运动实体测试 001

    positions: new Cesium.CallbackProperty(function() {
                              try {
                                const userEntityExists = ds.entities.getById(userEntity.id);
                                const closestSatelliteExists = closestDataSource.entities.getById(closestSatellite.id);
    
                                if (userEntityExists && userEntityExists.position && closestSatelliteExists && closestSatelliteExists.position) {
                                  return [userEntityExists.position.getValue(viewer.clock.currentTime), closestSatelliteExists.position.getValue(viewer.clock.currentTime)];
                                } else {
                                  viewer.entities.removeById(lineID);
                                  return null;
                                }
                              } catch (error) {
                                console.error(`An error occurred while creating the polyline for ${lineID}: `, error);
                                viewer.entities.removeById(lineID);
                                return null;
                              }
                            }, false),
    

    这里使用了 Cesium.CallbackProperty 来获取 postion 创建实体测试 001 和卫星的连线,现在当测试 001 消失的时候会报错 Uncaught TypeError: Cannot read property ‘x‘ of undefined 这个要怎么处理呢

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1036 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 19:48 · PVG 03:48 · LAX 11:48 · JFK 14:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.