Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cesium - Using scaleByDistance for a billboard created through CZML

I am trying to show an icon as a billboard and scale it by distance. I can manage fine, but as soon as I load the billboard through CZML instead of directly in JS, I cannot get the billboard the resize.

In my JS file I have:

var czmlDataSource = new Cesium.CzmlDataSource();
czmlDataSource.loadUrl('airports.czml');
viewer.dataSources.add(czmlDataSource);

My CZML file shows:

[
  {
    "id":"document",
    "version":"1.0"
  },
  {
    "id":"test",
    "billboard":{
      "image":"airport.png",
      "verticalOrigin":"BOTTOM",
      "show":true
    },
    "position":{
      "cartographicDegrees":[
        0.055278, 51.505278, 0
      ]
    }
  }
]

Before I used this:

entity.billboard.scaleByDistance = new Cesium.ConstantProperty(new Cesium.NearFarScalar(1.5e3, 0.3, 3.5e5, 0.0));

Obviously this now doesn't work. But I cannot find a way how to maybe get the ID of the billboard and use the scaleByDistance.

like image 295
Stefan Den Engelsman Avatar asked Feb 13 '15 15:02

Stefan Den Engelsman


2 Answers

CZML doesn't have support for scaleByDistance embedded in it yet. But you can still do what you suggest at the bottom of your post, which is find the ID and apply the property that way.

Remember that loadUrl is async, so you can't get the ID until after it loads. The code looks like this:

var czmlDataSource = new Cesium.CzmlDataSource();
viewer.dataSources.add(czmlDataSource);
czmlDataSource.loadUrl('airports.czml').then(function() {
    var entity = czmlDataSource.entities.getById('test');
    entity.billboard.scaleByDistance = new Cesium.ConstantProperty(
            new Cesium.NearFarScalar(1.5e3, 0.3, 3.5e5, 0.0));
});
like image 148
emackey Avatar answered Oct 19 '22 04:10

emackey


The accepted solution is no longer necessary. Sometime since then, Cesium has added support for doing the following (instead of new Cesium.NearFarScalar, which obviously wouldn't work with CZML which is just JSON):

"scaleByDistance": { "nearFarScalar": [ 1.0, 2.0, 10000.0, 3.0 ] }

Tested this functionality myself and it works.

Source:

  • https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/Billboard
  • https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/NearFarScalar
like image 1
Andrew Avatar answered Oct 19 '22 02:10

Andrew