Sorry, there currently isn’t a way to pass an argument to the callback function. Using a global variable is an okay solution. Another thing you can try is function scoping an argument like this:
function getCallbackFunction(argument) {
return function callbackFunction() {
return Cesium.Cartesian3.fromDegrees(argument.lon, argument.lat);
};
}
viewer.entities.add({
position: new Cesium.CallbackProperty(getCallbackFunction(argument), false)
});
This is a general JavaScript question, and not anything specific to Cesium, so keep that in mind when searching around for information. Hannah’s code is essentially the same as Function.bind which you might find more convenient.
What are you working on? As the editor for Cesium’s development team, I’m always looking for good applications we can highlight on our showcases page: http://cesiumjs.org/demos.html Is your project in a position to demo on our site?