I cannot figure how to 'drag and drop' the position of an entity loaded by czmlDataSource. This Sandcastle code seems on the cusp of success... but as you see I cannot figure how to <<addSample>> a point without a dateTime.
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
var czml = [{
"id" : "document",
"name" : "CZML Point",
"version" : "1.0"
}, {
"id" : "point 1",
"name": "point",
"position" : {
"cartographicDegrees" : [-111.0, 40.0, 0]
},
"point": {
"color": {
"rgba": [255, 255, 255, 255]
},
"outlineColor": {
"rgba": [255, 0, 0, 255]
},
"outlineWidth" : 4,
"pixelSize": 20
}
}];
var viewer = new Cesium.Viewer('cesiumContainer');
var unitDataSource = new Cesium.CzmlDataSource;
unitDataSource.load(czml);
viewer.dataSources.add(unitDataSource);
viewer.zoomTo(unitDataSource);
var entityId;
var dragging = undefined;
var editPointHandler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
editPointHandler.setInputAction(function(click) {
var pickedObject = viewer.scene.pick(click.position);
if (Cesium.defined(pickedObject) && pickedObject.id.name === 'point') {
entityId = pickedObject.id.id;
dragging = pickedObject;
viewer.scene.screenSpaceCameraController.enableRotate = false;
}
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
editPointHandler.setInputAction(function() {
if (Cesium.defined(dragging)) {
dragging = undefined;
viewer.scene.screenSpaceCameraController.enableRotate = true;
}
}, Cesium.ScreenSpaceEventType.LEFT_UP);
editPointHandler.setInputAction(function(movement) {
var editLat, editLon;
var editPosition = viewer.camera.pickEllipsoid(movement.endPosition);
if (!Cesium.defined(editPosition) || !dragging) {
return;
}
var positionCartographic = Cesium.Ellipsoid.WGS84.cartesianToCartographic(editPosition);
editLon = Cesium.Math.toDegrees(positionCartographic.longitude);
editLat = Cesium.Math.toDegrees(positionCartographic.latitude);
var entity = unitDataSource.entities.getById(entityId);
entity.position.addSample(Cesium.JulianDate.fromIso8601(entityId), Cesium.Cartesian3.fromDegrees(editLon,editLat));
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
3. Context. Why do you need to do this? We might know a better way to accomplish your goal - We want to edit the location of models interactively. The data is time-based data loaded as a czmlDataSource. The current method of typing in coordinate data is so 1980s.