Viewing a point geojson layer as markers in cesium

224 views
Skip to first unread message

Farook M

unread,
Apr 20, 2016, 1:32:14 AM4/20/16
to cesium-dev

I have a point geojson layer and i would like to add and view it using cesium. I tried with the below code

var dataSource1 = new Cesium.GeoJsonDataSource();
var roads = dataSource1.load('Apps/SampleData/layout&area.geojson');
roads.then(function(dataSource1) {
    viewer.dataSources.add(dataSource1);
    viewer.zoomTo(dataSource1);


    //Get the array of entities
    var entities1 = dataSource1.entities.values;

    var colorHash = {};
    for (var i = 0; i < entities1.length; i++) {
        //For each entity, create a random color based on the state name.
        //Some states have multiple entities, so we store the color in a
        //hash so that we use the same color for the entire state.
        var entity = entities1[i];
        var name = entity.Text;
        var color = colorHash[name];
        if (!color) {
            color = Cesium.Color.BLACK; 
            colorHash[name] = color;
        }
        //Set the polygon material to our random color.
        entity.point.material = color;
        //Remove the outlines.
        entity.point.outline = false;

    }
}).otherwise(function(error){
    //Display any errrors encountered while loading.
    window.alert(error);
});

As a result, i get all the points viewed as markers. How should i make changes to view it as a point?

Hannah Pinkos

unread,
Apr 20, 2016, 11:08:24 AM4/20/16
to cesium-dev
Hello,

The points appear as billboards by default.  You can change them to points with the following code:

 
    var entities = dataSource.entities.values;

   
for (var i = 0; i < entities.length; i++) {
       
var entity = entities[i];
        entity
.billboard = undefined;
        entity
.point = new Cesium.PointGraphics({
            color
: Cesium.Color.fromRandom(),
            pixelSize
: 10
       
});
   
}


Best,

Hannah

Farook M

unread,
Apr 21, 2016, 1:02:08 AM4/21/16
to cesium-dev
Thanks Hannah. Worked like a charm.
Reply all
Reply to author
Forward
0 new messages