1

My goal is to add CZML to my ol-cesium application.

I have created an application using the ol-cesium-v1.27 get started instructions:

                ol3d = new olcs.OLCesium({map: map}); // map is the ol.Map instance

I have added 3D terrain and a glTF model to my application as such:

                var scene = ol3d.getCesiumScene();
                scene.terrainProvider = new Cesium.CesiumTerrainProvider({
                    url: 'https://my.terrain',
                    requestWaterMask: true
                });
                var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(
                        Cesium.Cartesian3.fromDegrees(-3, 54, 0));
                var model = scene.primitives.add(Cesium.Model.fromGltf({
                    url: '/model.glb',
                    modelMatrix: modelMatrix,
                    heightReference : Cesium.HeightReference.CLAMP_TO_GROUND,
                    scene: scene
                }));

Now I would like to add a CZML solid to the globe. The Cesium example from the Sandcastle (CZML Sandcastle) looks like this:

    var czml = [{
    "id" : "document",
    "name" : "CZML Geometries: Cones and Cylinders",
    "version" : "1.0"
}, {
    "id" : "shape1",
    "name" : "Green cylinder with black outline",
    "position" : {
        "cartographicDegrees" : [-100.0, 40.0, 200000.0]
    },
    "cylinder" : {
        "length" : 400000.0,
        "topRadius" : 200000.0,
        "bottomRadius" : 200000.0,
        "material" : {
            "solidColor" : {
                "color" : {
                    "rgba" : [0, 255, 0, 128]
                }
            }
        },
        "outline" : true,
        "outlineColor" : {
            "rgba" : [0, 0, 0, 255]
        }
    }
}, {
    "id" : "shape2",
    "name" : "Red cone",
    "position" : {
        "cartographicDegrees" : [-105.0, 40.0, 200000.0]
    },
    "cylinder" : {
        "length" : 400000.0,
        "topRadius" : 0.0,
        "bottomRadius" : 200000.0,
        "material" : {
            "solidColor" : {
                "color" : {
                    "rgba" : [255, 0, 0, 255]
                }
            }
        }
    }
}];

var viewer = new Cesium.Viewer('cesiumContainer');
var dataSourcePromise = Cesium.CzmlDataSource.load(czml);
viewer.dataSources.add(dataSourcePromise);

How do I (Can I) apply that CZML example to my ol-cesium application without using the Cesium.Viewer.

Do I need to (Can I) create my application in that "Viewer" manner?

Or can I use my current method using "Scenes" to add the CZML?

1 Answer 1

1

Disclaimer, I'm a Cesium contributor, but I haven't used OL-Cesium integration myself so I'm not an expert on that.

That said, it looks to me like OL-Cesium is constructing its own Cesium.Scene directly, which could explain why you're able to call one function to get a reference to the existing scene but not to any existing Viewer. (When you construct a Cesium.Viewer, the new viewer constructs its own Scene, so there is no need to separately construct that).

Cesium has several layers of API. The scene holds a bunch of graphics primitives, and was likely the right place for OL-Cesium to connect given that OpenLayers has its own ideas about what needs to be shown on the map and where.

The Cesium.Viewer is a much higher-level object, and is the parent of the "Entity API" layer of Cesium, where Cesium itself keeps track of a current time and which objects are where on the map at what time. CZML documents are parsed into Cesium Entities and loaded into this layer, and updated by functions inside the Viewer based on the Viewer's clock. But OpenLayers probably doesn't have any integration at all here, otherwise there would be questions about which system was in charge of positioning which objects on the map. You could construct your own viewer, but it wouldn't be integrated with your OL map, it would just be a standalone instance of Cesium at that point.

It would be interesting to consider integration going the other direction: Allowing Cesium entities to drive an OL map, rather than having the map drive a Cesium.Scene. One could imagine CZML entities moving around on an OL map driven by a Cesium timeline in such a setup. But that's not what appears to be available in OL-Cesium, so I don't think what you're asking is currently available.

1
  • I was afraid of this. Thanks for your detailed explanation. I will pass this on to the ol-cesium team and see if this is in their roadmap.
    – maw269
    Commented Jun 12, 2017 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.