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.
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.
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.
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.