Monthly Archives: December 2016

Cesium – How to show pyramid with polygon base in CZML ?



    var czml = [
      {
        "id" : "document",
        "name" : "CZML Geometries: Polygon",
        "version" : "1.0"
      }, {
        "id" : "orangePolygon",
        "name" : "Orange polygon with per-position heights and outline",
        "polygon" : {
          "positions" : {
            "cartographicDegrees" : [
              -70.0, 35.0, 100000,
              -72.0, 37.0, 0,
              -68.0, 35.0, 0
            ]
          },
          "material" : {
            "solidColor" : {
              "color" : {
                "rgba" : [255, 100, 0, 100]
              }
            }
          },
      "extrudedHeight" : 0,
      "perPositionHeight" : true,
      "outline" : true,
      "outlineColor" : {
        "rgba" : [0, 0, 0, 255]
      }
    }
  },


    {
    "id" : "orangePolygon2",
    "name" : "Orange polygon with per-position heights and outline",
    "polygon" : {
      "positions" : {
        "cartographicDegrees" : [
          -70.0, 35.0, 100000,
          -70.0, 33.0, 0,
          -68.0, 35.0, 0
        ]
      },
      "material" : {
        "solidColor" : {
          "color" : {
            "rgba" : [255, 100, 0, 100]
          }
        }
      },
      "extrudedHeight" : 0,
      "perPositionHeight" : true,
      "outline" : true,
      "outlineColor" : {
        "rgba" : [0, 0, 0, 255]
      }
    }
  },

    {
    "id" : "orangePolygon3",
    "name" : "Orange polygon with per-position heights and outline",
    "polygon" : {
      "positions" : {
        "cartographicDegrees" : [
          -70.0, 35.0, 100000,
          -70.0, 33.0, 0,
          -72.0, 37.0, 0,
        ]
      },
      "material" : {
        "solidColor" : {
          "color" : {
            "rgba" : [255, 100, 0, 100]
          }
        }
      },
      "extrudedHeight" : 0,
      "perPositionHeight" : true,
      "outline" : true,
      "outlineColor" : {
        "rgba" : [0, 0, 0, 255]
      }
    }
  }
];

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

Share

Cesium – How to show multiple polylines using czml ?

var czml = [
  {
    "id" : "document",
    "name" : "CZML Geometries: Polyline",
    "version" : "1.0"
  },
  {
    "id" : "redLine",
    "name" : "Red line on the surface",
    "polyline" : {
      "show": false,
      "positions" : {
        "cartographicDegrees" : [
          -75, 35, 0,
          -125, 35, 0
        ]
      },
      "material" : {
          "polylineOutline": {
              "color": {"rgba": [255, 0, 0, 255]},
              "outlineColor": {"rgba": [255, 255, 255, 255]},
              "outlineWidth": 2.0
          }
      },
      "width" : 5
    }
  },
  {
    "id" : "purpleLine",
    "name" : "Purple straight line at height",
    "polyline" : {
      "show": false,
      "positions" : {
        "cartographicDegrees" : [
          -125, 35, 0,
          -170, 35, 0
        ]
      },
      "material" : {
          "polylineOutline": {
              "color": {"rgba": [148, 0, 211, 255]},
              "outlineColor": {"rgba": [255, 255, 255, 255]},
              "outlineWidth": 2.0
          }
      },
      "width" : 5
    }
  }
];

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

var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(
    function () { 
        dataSource.entities.getById('purpleLine').polyline.show = true;
        dataSource.entities.getById('redLine').polyline.show = true;

    },
    Cesium.ScreenSpaceEventType.LEFT_CLICK
);

By : https://github.com/AnalyticalGraphicsInc/cesium/issues/3598

Share

Cesium – How to make an InfoBox pop up on demand ?

                              .....
                           .'       '.
                          .           .
                          :           :
                          '           '
                ,.*====.   '.       .'   .====*.,
               .-`"/c)}}},    :...:    ,{{{(c\"`-.
           _.-'-6>   {{{{{'''`     `'''}}}}}   <9-'-._
          t         |}}}}}}           {{{{{{|         y
           \__.___.'{{{{{{{           }}}}}}}'.___.__/
               `[__/}}}}}}}}         {{{{{{{{\__]`
                {{{.'     `'-._   _.-'`     '.}}}
                }}/            ```            \{{
                {{|                           |}}
                }}|                           |{{
         .------{{{\    ,               ,    /}}}------.
        //.--------'    ;               ;   '---------.\\
       ((///  _          \             /          _  \\\))
 jgs    (((--' `''-------'`'"'-----'"'`'-------''` '--)))

It’s a bit of a hack, but you can make the info popup display whatever you like by creating a fake entity and setting it as the viewer’s selected entity. For example:

var entity = new Cesium.Entity('Title to put in the infobox');
entity.description = {
    getValue : function() {
        return 'HTML to display in the infobox';
    }
};
viewer.selectedEntity = entity;
Share

Cesium – How to Improve InfoBox ?

In order to run a script in the infobox, you have to enable scrips to run in the iframe. This is disabled by default for security reasons, in case you don’t know the source of the data populating the infobox.
You can enable scrips with this code:

var iframe = document.getElementsByClassName('cesium-infoBox-iframe')[0];
iframe.setAttribute('sandbox', 'allow-same-origin allow-scripts allow-popups allow-forms'); 

Also, to get the current value of an entity property, you can use .getValue(viewer.clock.currentTime);

Share

Cesium – How to show tooltip in cesium ?


  
Share