Can I change the default colors for primitives?

I’m loading a geoJson datasource, and the default color is yellow. Is it possible to change the default?

I can loop through the entities and change polygons to a different color, but changing circles doesn’t work. From a couple previous posts it sounds like updating circles after they’ve been rendered hasn’t been implemented yet; that only exists for polygons. Is that correct? I’m using Cesium 1.1.

Bart, can you elaborate on what you mean by “changing circles doesn’t work”? How are you creating the circles; through Geometry and Appearances?

This is a geoJson fragment of a point I’m loading:

    { "type": "Feature",
      "geometry": {"type": "Point", "coordinates": [69.167175292969, 34.513346401476]},
      "color": "red",
      "properties": {"id": 1081, "taskName": "B2222-140805102052"}
    },

``

I create a datasource, add it to the viewer, load the data, and change the color of each primitive to a random value (i.e., very much like the Sandcastle example:
var dataSource = new Cesium.GeoJsonDataSource();
viewer.dataSources.add(dataSource);
dataSource.load(jsonResponse.schedules[0].geoJson).then(function() {
var entities = dataSource.entities.entities;

                var colorHash = {};
                for (var i = 0; i < entities.length; i++) {
                    var entity = entities[i];
                    var name = entity.name;
                    var color = colorHash[name];
                    if (!color) {
                        color = Cesium.Color.fromRandom({
                            alpha : 0.7
                        });
                        colorHash[name] = color;
                    }
                   
                    if (entity.point) {
                        entity.point.material = Cesium.ColorMaterialProperty.fromColor(areaColor);
                    } else if (entity.polygon) {
                        entity.polygon.material = Cesium.ColorMaterialProperty.fromColor(areaColor);
                    }
                   
                }
            });

``

The problem is that the point never gets a random color. It’s always yellow. I put the conditional in there to see if the objects actually have a point or polygon property, and they do.

This is a simple example of the problem. What I’m trying to accomplish is this:

  • have the default color of all primitives be blue.
  • I have the Cesium viewer in a panel, and when a user clicks on a record in another panel, I want an area with the same ID to be selected; e.g., highlighted with a different color, change the border, etc.

This should be an easy fix. PointGraphics does not have a material property, so the below line of code

entity.point.material = Cesium.ColorMaterialProperty.fromColor(areaColor);

needs to be changed to

entity.point.color = Cesium.ConstantProperty(areaColor);

And everything should work fine. Let me know how it turns out.

There was a typo in my last message, the final line should be

entity.point.color = new Cesium.ConstantProperty(areaColor);

Now I feel dumb. That was simple and worked perfectly.

But back to the subject line of my post… is there a way to change the default colors for primitives? I

Thanks,
Bart

As of now, there is no way to set defaults pre-load for GeoJSON. We used to have the capability, but it wasn’t useful in it’s current form so it was removed pre 1.0. However, due to popular demand, we are definitely going to add this feature back soon, and it should be available in the Nov 1st release. There are some subtleties to the process that make it kind of tricky and we are still working out the details.

I wanted to add that tomorrow’s release will support the MapBox GeoJSON simplestyle specificaiton: https://github.com/mapbox/simplestyle-spec. This will be very useful for people creating their own geojson files or people who already have geojson files with styling.

I’ve also opened an issue to discuss how to implement default settings, check out this link if you want to see what we’re thinking (and provide feedback): https://github.com/AnalyticalGraphicsInc/cesium/issues/2167

Thanks

This is excellent news! It’s exactly what I’m looking for.

Thanks,
Bart

It took longer than I expected, but I just opened this pull request: https://github.com/AnalyticalGraphicsInc/cesium/pull/2256, which re-introduces the ability to set global GeoJSON defaults and also allows for basic per-instance styling. And of course for more advanced scenarios you’ll be able to fall back to manipulating entity instances directly.