Remove Labels with checkbox

Hi!
I am using checkboxes to show and then remove geojson files. I now want to implement labels. But I cant seem to be able to remove the labels.

My code:

var synp = new Cesium.GeoJsonDataSource();
function synpR() {
if (synpbox.checked == true) {
viewer.dataSources.add(synp);
synp.load(‘./Data/lager/synpunkterZ.geojson’,)
var promise = Cesium.GeoJsonDataSource.load(‘./Data/lager/labels_synp.geojson’);
promise.then(function (dataSource) {
viewer.dataSources.add(dataSource);
var entities = dataSource.entities.values;
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
var position = entity.position;
entity.position = position;
entity.billboard.show = false;
entity.label = {
text: entity.properties[“DESO”],
font: ‘16px Barlow’,
fillColor: Cesium.Color.BLACK,
outline: Cesium.Color.WHITE,
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
eyeOffset: Cesium.Cartesian3(0.0, 30.0, 1000)
,
}
} } ) }
else {
viewer.dataSources.remove(synp),
viewer.dataSources.remove(promise),
viewer.entities.remove(promise)
}
};

The geometry in synp removes as it should but “promise” lables remains…

Hiya,

I’d suggest you help us by cleaning and showing your code, or even better, create a working Sandcastle example and share that here. But from a glance, you’ve got references within scopes that aren’t available in others (for example ‘promise’ is not available in your else / remove clause), and you don’t specify how and when the synP() function is called, and in what context.

Cheers,

Alex