Thanks,
Rob
var ds = new Cesium.KmlDataSource();
ds.load('path_to_kmz');
var dsDisplay = new Cesium.DataSourceDisplay(scene);
dsDisplay.getDataSources().add(ds);
However, I am getting an error that states "Uncaught TypeError: Cannot read property 'dataSourceAdded' of undefined".
--
You received this message because you are subscribed to the Google Groups "cesium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thank you for the detailed reply!
However, can you describe how to do this without using the CesiumWidget? We are creating a canvas object and passing that to the creation of the Cesium scene. We are then creating a Cesium globe.
Is there a way to do this without the Cesium viewer or the CesiumWidget?
Thanks again
Unless I'm mistaken or things have changed... the widget has built in GUI elements (user controls, etc) that we didn't want to display. Maybe using the widget and somehow not showing these controls might be an option?
I thought that might be the case with the scene object so I am working on modifying your code to simply use the scene object we have. However, I'm still getting the error message "Uncaught TypeError: Cannot read property 'dataSourceAdded' of undefined". I'm assuming this message is coming from the DataSourceCollection?
Unless I'm mistaken or things have changed... the widget has built in GUI elements (user controls, etc) that we didn't want to display. Maybe using the widget and somehow not showing these controls might be an option?
The code to load the KMZ is at the bottom.
I'm still getting the error I described in the earlier posts.
var canvas = document.createElement('canvas');
canvas.className = "fullSize";
if (!document.getElementById("divCanvas")) {
var divCesiumContainer = document.createElement("div");
divCesiumContainer.id = "divCanvas";
document.body.appendChild(divCesiumContainer);
}
document.getElementById("divCanvas").appendChild(canvas);
scene = new Cesium.Scene({
canvas: canvas
});
scene.globe = new Cesium.Globe();
scene.globe.baseColor = Cesium.Color.BLACK;
scene.fxaa = true;
scene.skyAtmosphere = new Cesium.SkyAtmosphere();
var skyBoxBaseUrl = "resources/plugins/cesium/Cesium/Assets/Textures/SkyBox/tycho2t3_80";
scene.skyBox = new Cesium.SkyBox({
sources : {
positiveX : skyBoxBaseUrl + '_px.jpg',
negativeX : skyBoxBaseUrl + '_mx.jpg',
positiveY : skyBoxBaseUrl + '_py.jpg',
negativeY : skyBoxBaseUrl + '_my.jpg',
positiveZ : skyBoxBaseUrl + '_pz.jpg',
negativeZ : skyBoxBaseUrl + '_mz.jpg'
}
});
scene.scene3DOnly = true;
// Tile imagery
scene.imageryLayers.addImageryProvider(new Cesium.ArcGisMapServerImageryProvider({ url:'http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer' }));
// Terrain
var cesiumTerrainProviderMeshes = new Cesium.CesiumTerrainProvider({
url: 'http://cesiumjs.org/stk-terrain/tilesets/world/tiles',
credit: ''
});
scene.terrainProvider = cesiumTerrainProviderMeshes;
scene.globe.enableLighting = false;
scene.globe.showNight = false;
scene.globe.showDay = false;
scene.globe.affectedByLighting = false;
scene.debugShowFramesPerSecond = false;
if (blnShowFPS) {
var performanceContainer = document.createElement('div');
performanceContainer.className = 'cesium-performanceDisplay';
performanceContainer.style.position = 'absolute';
performanceContainer.style.bottom = '60px';
performanceContainer.style.right = '10px';
document.getElementById("divCanvas").appendChild(performanceContainer);
var performanceDisplay = new Cesium.PerformanceDisplay({container: performanceContainer});
}
var lastCamera = {position: Cesium.Cartesian3.clone(scene.camera.position),
direction: Cesium.Cartesian3.clone(scene.camera.direction),
up: Cesium.Cartesian3.clone(scene.camera.up),
right: Cesium.Cartesian3.clone(scene.camera.right),
transform: Cesium.Matrix4.clone(scene.camera.transform)
};
function animate() {
if (blnShowFPS && Cesium.defined(performanceDisplay)) performanceDisplay.update();
refreshAnimatedObjects();
if (scene.camera) {
if (!scene.camera.position.equals(lastCamera.position) ||
!scene.camera.direction.equals(lastCamera.direction) ||
!scene.camera.up.equals(lastCamera.up) ||
!scene.camera.right.equals(lastCamera.right) ||
!scene.camera.transform.equals(lastCamera.transform)) {
lastCamera = {position: Cesium.Cartesian3.clone(scene.camera.position),
direction: Cesium.Cartesian3.clone(scene.camera.direction),
up: Cesium.Cartesian3.clone(scene.camera.up),
right: Cesium.Cartesian3.clone(scene.camera.right),
transform: Cesium.Matrix4.clone(scene.camera.transform)
};
EVENT_CameraChanged.dispatch();
}
}
}
function tick() {
scene.initializeFrame();
animate();
scene.render();
Cesium.requestAnimationFrame(tick);
}
tick();
// Prevent right-click from opening a context menu.
canvas.oncontextmenu = function() {
return false;
};
// Resize handler
var onResize = function() {
var width = window.innerWidth;
var height = window.innerHeight;
if (canvas.width === width && canvas.height === height) {
return;
}
canvas.width = width;
canvas.height = height;
scene.camera.frustum.aspectRatio = width / height;
};
window.addEventListener('resize', onResize, false);
onResize();
scene.camera.setView({
position : Cesium.Cartesian3.fromDegrees(dblInitLon, dblInitLat, dblInitAlt),
heading : degreesToRadians(0.0), // east, default value is 0.0 (north)
pitch : degreesToRadians(-90), // default value (looking down)
roll : 0.0 // default value
});
// Screen handler
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(movement) {
// get an array of all primitives at the mouse position
var pickedObjects = scene.pick(movement.position);
if(Cesium.defined(pickedObjects)) {
if (typeof pickedObjects['primitive']['TrackId'] !== 'undefined' && pickedObjects['primitive']['TrackId'] !== null) {
onModelClick(null,pickedObjects['primitive']['TrackId']);
}
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
scene.screenSpaceCameraController.tiltEventTypes = [Cesium.CameraEventType.RIGHT_DRAG, Cesium.CameraEventType.PINCH];
scene.screenSpaceCameraController.zoomEventTypes = [Cesium.CameraEventType.WHEEL, Cesium.CameraEventType.PINCH];
scene.screenSpaceCameraController.enableLook = false;
// *********************************************************************
// Test loading a KMZ file
var dataSources = new Cesium.DataSourceCollection();
var dataSourceDisplay = new Cesium.DataSourceDisplay({
scene: scene,
dataSourceCollection: dataSources
});
//dataSourceDisplay.update needs to be called once a frame after all other updates have been made,
//in this case we call it in the preRender event.
scene.preRender.addEventListener(function(scene, time){
dataSourceDisplay.update(time);
});
//Now that everything is configured, we can load KML and add to list of data sources.
dataSources.add(Cesium.KmlDataSource.load('path_to_kmz'));
// *********************************************************************
I'm not receiving any errors. And I'm successfully getting past the load function.
Below is the contents of the test HTML page (I have Cesium's JS and CSS referenced properly in the page).
<div id="cesiumContainer"></div>
<script>
var widget = new Cesium.CesiumWidget('cesiumContainer');
// Test loading a KMZ file
var dataSources = new Cesium.DataSourceCollection();
var dataSourceDisplay = new Cesium.DataSourceDisplay({
scene: widget.scene,
dataSourceCollection: dataSources
});
//dataSourceDisplay.update needs to be called once a frame after all other updates have been made,
//in this case we call it in the preRender event.
widget.scene.preRender.addEventListener(function(scene, time){
dataSourceDisplay.update(time);
});
//Now that everything is configured, we can load KML and add to list of data sources.
dataSources.add(Cesium.KmlDataSource.load('path_to_KMZ'));
</script>
I can provide the test KMZ file if desired.
It appears there must be something in the KMZ/KML I'm trying to load that is not supported. However, there is no error being thrown and no messages printed to the console. How would I go about determining what items in the file I'm trying to load are not supported (other than manually removing them one by one since this is a 5MB file)?
It looks like the code is able to load KMZ/KML files. I just attempted to load a very simple KML, and it loaded successfully. Thank you for the help in getting this far!
It appears there must be something in the KMZ/KML I'm trying to load that is not supported. However, there is no error being thrown and no messages printed to the console. How would I go about determining what items in the file I'm trying to load are not supported (other than manually removing them one by one since this is a 5MB file)?
Is there a method to upload a file here?
The original version of the KMZ/KML (link below) contains a couple of screen overlays which I have removed in the version I'm testing with (as it appears they are not supported).
Here's the link to the original file...
http://metroplexenvironmental.com/docs/socal_metroplex/Google_Earth_150816/Grid Points - San Diego County.kmz
I was wondering if you've had a chance to check out the KMZ file and determine why I can't load it and why I wouldn't be getting any error or explanation messages in the console.
As I mentioned above I removed the screen overlays that are in the file because my understanding is that they are not supported. But I'm not sure why the rest of the file isn't loading.
Thanks for any help,
Rob
I/we are not creating these KMZ/KML files. I've been asked to see what it would take to read and display them in our JavaScript applications (both Cesium and Leaflet based).
I did notice that the visibility was set to 0 in these files. And as you mentioned I have found the namespace declarations to be an issue. I'm not sure what to do about the namespace issue since I'm not creating the files.
I have broken these files down into smaller pieces and with the namespace changes I have been able to load portions of the files. So we'll have to think about how to tackle this...
Thanks again for your time and help!