I've been working on a project for my company these last couple weeks trying to see if we can switch over our mapping system to Cesium. I'm only on an internship, (this is my first experience using javascript), so please forgive any gaps in knowledge.
The problem I've been stuck on the last couple days has been figuring out a way to use WebSockets to send position data/czmls to node.js server that is running Cesium. I've found a lot of tutorials and documentation on setting up a socket in java, but I'm struggling to figure out where to put the corresponding listener in the Cesium code.
I found this thread, and the example code given makes sense for handling reading-in/processing the czml file. The part I don't understand is where the call for the onMessage function would go? Would I want to add it into the "CesiumViewer.js" for example, or into the "server.js" that gets run by node.js to start the server?
Best,
Chris
var dataSource = new Cesium.GeoJsonDataSource();
viewer.dataSources.add(dataSource);
dataSource.load(jsonResponse.schedules[0].geoJson);jsonResponse.schedules[0].geoJson is a geoJson-formatted list of polygons and lines. I'm trying to implement the way you explained, but whenever I try to make a socket listen inside a javascript file that gets called by the index.html my java method errors out because it can't connect to the port. I feel like I am probably just using the wrong syntax somewhere, but I'm not sure. Also what npm package do you use for setting up your sockets?
Chris
var javaServer = require('net').createServer();
var fs = require('fs');
javaServer.on('connection', function (javaSocket) {
var clientAddress = javaSocket.address().address + ':' + javaSocket.address().port;
console.log('Java ' + clientAddress + ' connected');
javaSocket.on('data', function(data) {
fs.writeFile('test.czml', data);
});
javaSocket.on('close', function() {
console.log('Java ' + clientAddress + ' disconnected');
});
});
javaServer.listen(80);
process.on('SIGINT', function() {
server.close(function() {
process.exit(0);
});
javaServer.close();
});