Skip to content

Instantly share code, notes, and snippets.

@jhurliman
Created February 8, 2016 19:25
Show Gist options
  • Save jhurliman/4c8bba81c9f16f037894 to your computer and use it in GitHub Desktop.
Save jhurliman/4c8bba81c9f16f037894 to your computer and use it in GitHub Desktop.
Cesium.js viewer for Oakland buildings
var viewer = new Cesium.Viewer('cesiumContainer', {timeline: false, animation: false});
var promise = Cesium.GeoJsonDataSource.load(
'https://s3.amazonaws.com/jhurliman/oakland-building-footprints.geojson');
promise.then(function(dataSource) {
viewer.dataSources.add(dataSource);
// Get the array of buildings
var entities = dataSource.entities.values;
var colorHash = {};
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
var type = entity.properties.bldgtype || '';
var color = colorHash[type];
if (!color) {
color = Cesium.Color.fromRandom({ alpha: 1.0 });
colorHash[type] = color;
}
entity.polygon.material = color;
entity.polygon.outline = false;
entity.polygon.extrudedHeight = getBuildingHeight(entity);
}
});
var CENTER_LAT = 37.795024;
var CENTER_LON = -122.270031;
viewer.camera.lookAt(Cesium.Cartesian3.fromDegrees(CENTER_LON, CENTER_LAT),
new Cesium.Cartesian3(0, -4000, 4000));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
function getBuildingHeight(entity) {
var MAX_AREA = 10000; //852649.227299;
var STOREY_HEIGHT = 3.5;
var stories = entity.properties.nostory || 1;
var area = entity.properties.shape_area || 0;
return stories * STOREY_HEIGHT + Math.min(1, area / MAX_AREA) * STOREY_HEIGHT;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment