GeoJsonDataSource.entities statement does nothing

Through my debuggin of an app, I’ve found that this line is not doing anything.

markersEntities = dataSource.entities.values;

where DataSource is the GeoJsonDataSource object. I have analyzed it further using console.log() and while console.log(dataSource) shows that it exists, if I try to console.log(DataSource.entities) nothing happens. Not undefined, not null, just nothing at all prints. My usage of it was taken right from the tutorials in the docs, and the docs do say that this object should have entities. Furthermore, when I’ve opened up the DataSource object in the console, I can see the entities and their data contained inside it.

What could be the issue with this? I should say also that no runtime errors are happening when that line gets called either.

This sounds like you’re running your code inside of a promise, which is throwing an error, but the error is not caught, so you see no error or output from your console.log statement. Although hard to say without seeing the code or a Sandcastle to reproduce.

I would make sure you have the appropriate .catch or .otherwise call on your promise to make sure these errors are caught.

Can you explain what you mean by running code inside a promise? I am basing my code off the developer tutorials, which use the viewer object. I don’t see any promise object in the docs. I’ll share my basic code below.

(function () {
"use strict";
Cesium.Ion.defaultAccessToken = 'mytokenredacted';

var viewer = new Cesium.Viewer('cesiumContainer', {
    scene3DOnly: true,
    selectionIndicator: false,
    baseLayerPicker: false,
    terrainProvider : Cesium.createWorldTerrain()

// Enable lighting based on sun/moon positions
    viewer.scene.globe.enableLighting = true;
// Create an initial camera view
var initialPosition = new Cesium.Cartesian3.fromDegrees(-104.906216393, 39.614, 2731.082799425431);
var initialOrientation = new Cesium.HeadingPitchRoll.fromDegrees(7.1077496389876024807, -31.987223091598949054, 0.025883251314954971306);
var homeCameraView = {
    destination : initialPosition,
    orientation : {
        heading : initialOrientation.heading,
        pitch : initialOrientation.pitch,
        roll : initialOrientation.roll
// Set the initial view;

// override the default home button
viewer.homeButton.viewModel.command.beforeExecute.addEventListener(function (e) {
        e.cancel = true;;

// add geojson source
var geojsonOptions = {
    clamptoground: true
var mapMarkerSamples = Cesium.GeoJsonDataSource.load('Source/SampleData/sampleGeoJSON.json', geojsonOptions);

//load 3D buildings set
// Load the NYC buildings tileset
var citySet = new Cesium.Cesium3DTileset({ url: Cesium.IonResource.fromAssetId(96188) });
//var city = viewer.scene.primitives.add(citySet);

//display options

var smileElement = document.getElementById('smile');
var buildingsElement = document.getElementById('buildings');

buildingsElement.addEventListener('change', function(e) {
    var city = viewer.scene.primitives.add(citySet); =;
    viewer.shadows =;

smileElement.addEventListener('change', function(e) {
if ( {
    mapMarkerSamples.then(function(dataSource) {
        // add new data as entities to the viewer
        console.log("hello"); = true;
        markers = viewer.dataSources.entities;
        markersEntities = dataSource.entities.values;

        for(var i = 0; i < markersEntities.length; i++) {
            var entity = markersEntities[i];
            if (Cesium.defined(entity.polygon)) {
                //styling code
                entity.polygon.material = Cesium.Color(255,215,0, 0.6); // partial transparent gold
            else if (Cesium.defined(entity.point)) {
                //styling code
                entity.point.material = Cesium.Color.BLACK;
            else if (Cesium.defined(entity.polyline)) {
                entity.polyline.material = Cesium.Color.BLACK;
else {
            mapMarkerSamples.then(function(dataSource) {
                // remove sources
       = false;

        } =;

Thanks for the help!

mapMarkerSamples is a promise. You call .then on it run code when that promise resolves. You have an uncaught error because you need to add an .otherwise call to catch the error. See example of .otherwise call here: or you can read up more generally on promises in JavaScript.

What kind of project are you working on with Cesium?