TypeError: visualizers is undefined

Hello,

I’m trying to load and remove czml extruded polygons at the event of camera moveEnd (eventListener) based on the position and altitude of the camera. But Im getting this error (image attached) variably and am not sure the exact cause. By what I understand the reason could be that widget.render() function is being called in Cesium.js but since visualizers are not defined rendering stops. Even if I hard-code and comment the catch() at line 161004 of Cesium Unminified to avoid popping of error panel, the rendering still stops. Following is some of my code to give you a little insight :

viewer.camera.moveEnd.addEventListener(function() {

camera_pos = viewer.camera.positionCartographic;

if (camera_pos.height <= 5000){

if(Cesium.Rectangle.contains(someRectangle,camera_pos)){

if(camera_pos.height > 2000){

if(!dataSource1._visualizers){

create_level_1(camera_pos.height);

}

if(dataSource1._visualizers && !Cesium.Rectangle.contains(ext_1,camera_pos)){

remove_level_1();

create_level_1(camera_pos.height);

}

if(dataSource2._visualizers){

remove_level_2();

}

if(dataSource3._visualizers){

remove_level_3();

}

}

if(camera_pos.height <= 2000 && camera_pos.height > 1000){

if(!dataSource1._visualizers){

create_level_1(camera_pos.height);

}

if(!dataSource2._visualizers){

create_level_2(camera_pos.height);

}

if(dataSource1._visualizers && !Cesium.Rectangle.contains(ext_1,camera_pos)){

remove_level_1();

create_level_1(camera_pos.height);

}

if(dataSource2._visualizers && !Cesium.Rectangle.contains(ext_2,camera_pos)){

remove_level_2();

create_level_2(camera_pos.height);

}

if(dataSource3._visualizers){

remove_level_3();

}

}

if(camera_pos.height <= 1000){

if(!dataSource1._visualizers){

create_level_1(camera_pos.height);

}

else if(dataSource1._visualizers && !Cesium.Rectangle.contains(ext_1,camera_pos)){

remove_level_1();

create_level_1(camera_pos.height);

}

if(!dataSource2._visualizers){

create_level_2(camera_pos.height);

}

else if(dataSource2._visualizers && !Cesium.Rectangle.contains(ext_2,camera_pos)){

remove_level_2();

create_level_2(camera_pos.height);

}

if(!dataSource3._visualizers){

create_level_3(camera_pos.height);

}

else if(dataSource3._visualizers && !Cesium.Rectangle.contains(ext_3,camera_pos)){

remove_level_3();

create_level_3(camera_pos.height);

}

}

}

}

else if (camera_pos.height > 5000){

if(dataSource1._visualizers){

remove_level_1();

}

if(dataSource2._visualizers){

remove_level_2();

}

if(dataSource3._visualizers){

remove_level_3();

}

}

});

function create_level_1(ht){

var cam_pos = viewer.camera.positionCartographic;

var cam_lon = Cesium.Math.toDegrees(cam_pos.longitude);

var cam_lat = Cesium.Math.toDegrees(cam_pos.latitude);

ext_1 = Cesium.Rectangle.fromDegrees(cam_lon-0.008, cam_lat-0.008, cam_lon+0.008, cam_lat+0.008);

dataSource1.load(models); // ‘models’ is a string with CZML format

viewer.dataSources.add(dataSource1);

}

function create_level_2(ht){

var cam_pos = viewer.camera.positionCartographic;

var cam_lon = Cesium.Math.toDegrees(cam_pos.longitude);

var cam_lat = Cesium.Math.toDegrees(cam_pos.latitude);

ext_2 = Cesium.Rectangle.fromDegrees(cam_lon-0.002, cam_lat-0.002, cam_lon+0.002, cam_lat+0.002);

dataSource2.load(models);

viewer.dataSources.add(dataSource2);

}

function create_level_3(ht){

var cam_pos = viewer.camera.positionCartographic;

var cam_lon = Cesium.Math.toDegrees(cam_pos.longitude);

var cam_lat = Cesium.Math.toDegrees(cam_pos.latitude);

ext_3 = Cesium.Rectangle.fromDegrees(cam_lon-0.0015, cam_lat-0.0015, cam_lon+0.0015, cam_lat+0.0015);

dataSource3.load(models);

viewer.dataSources.add(dataSource3);

}

function remove_level_1(){

viewer.dataSources.remove(dataSource1);
dataSource1 = new Cesium.CzmlDataSource();

}

function remove_level_2(){

viewer.dataSources.remove(dataSource2);
dataSource2 = new Cesium.CzmlDataSource();

}

function remove_level_3(){

viewer.dataSources.remove(dataSource3);
dataSource3 = new Cesium.CzmlDataSource();

}

``

Help needed.

Thanks,

Parthesh.

Hello Parthesh,

Thank you for providing a code sample! However, I wasn’t able to get it to run in Sandcastle.

Can you please fill in the missing variables to I can run it to reproduce the problem?

Thanks,

Hannah

Hey Hannah,

Thanks for the reply.

I would like to mention that I find it difficult to recreate the error myself. But it does occur occasionally.

In my code sample the important missing variable is “models” which is nothing but a JSON parsed czml string of extruded polygons which I am dynamically fetching from some other source.

I have attached 3 example czml strings for level 1, level 2 and level 3 which Im dynamically calling as variable “models”.

The other missing variables are as follows:

someRectangle = Cesium.Rectangle.fromDegrees(72.7835,18.9051, 73.0003,19.3175);

var dataSource1 = new Cesium.CzmlDataSource(); //level1

var dataSource2 = new Cesium.CzmlDataSource(); //level2

var dataSource3 = new Cesium.CzmlDataSource(); //level3

Thanks,

Parthesh.

models_1.txt (152 KB)

models_2.txt (30.3 KB)

models_3.txt (3.06 KB)

It seems that the problem is occurring while DataSourceDisplay.prototype.update is set. Is there a way to avoid the updation of the DataSourceDisplay since I am not changing the geometry or color with time. Im just loading and removing geometries.