Hi all,
I would like to add a ‘highlight’ feature to my project on the Battle for Normandy.
You see that upon selecting a unit, the infoBox for that unit opens and displays descriptive content for that unit. The database includes information about the unit hierarchy (the family tree, aka order of battle).
I would also like to have, upon the same click-event, all of the child units be identified by a translucent ellipse centered at the origin of each child model. The resulting effect would be to highlight the connection between an adult, its child, its grandchildren, etc.
I currently access the infoBox via AJAX. I am trying to use AJAX again to handle this highlight feature. FYI- the database recurses to create the hierarchy and then queries the hierarchy to get the cartographicDegrees for the ellipses.
I have run into two issues:
1- is there an approach to use other than AJAX to dynamically add data to a running animation?
2- lacking a compelling “YES” to the first question, what is the best way to return the CZML code from the AJAX success function so that it is immediately added to (or processed into) the existing ‘viewer’?
I’ll build upon a Sandcastle I made several weeks ago to illustrate the challenge. It isn’t exactly the same, but is similar…
var viewer = new Cesium.Viewer(‘cesiumContainer’);
var scene = viewer.scene;
//------ create CZML ------
var czml =
[{“id” : “document”,
“version” : “1.0”
},{“id” : “Boston”,
“label”:{“text”:“Boston”},
“position”:{“cartographicDegrees”:[-71.0589,42.3601,0]},
“description”:“Boston is a city…”,
},{“id” : “New York City”,
“label”:{“text”:“New York”},
“description”:“New York is a city…”,
“position”:{“cartographicDegrees”:[-74.0059,40.7127,0]},
}];
var promise = Cesium.CzmlDataSource.load(czml);
promise.then(function(dataSource) {
viewer.dataSources.add(dataSource);
//------ Get the array of entities
var entities = dataSource.entities.values;
//------ Loop entities
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
var name = entity.label;
entity.label.translucencyByDistance = new Cesium.NearFarScalar(100000,1.0,500000,0.0);
}
}).otherwise(function(error){
//------ Display error
window.alert(error);
});
//------ Use JQuery/AJAX to update to current description
var handlerA = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handlerA.setInputAction(function(click) {
var pickedObject = scene.pick(click.position);
if (Cesium.defined(pickedObject)) {
$.ajax({
async: false,
type: ‘GET’,
url: ‘addCzml2.php’,
data: (pickedObject.id.id).val(),
success: function(data) {
czmlDataSource.process(data);
}
});
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
``
PHP File <<addCzml2.php>>
<?php ?>``
Happy to try and clarify as necessary, Erik