Hi Dzung ( Resent with code below)
Thanks for your suggestion.
I have made some progress but not enough to be useful
I am now getting coordinates writing to the console log and using them to put into a Geojson file to create a billboard/marker.
The position of the marker is still not exactly where I click on the 3d model.
I think the exact coordinates are being given for the underlying terrain and not according to what I select my model.
I have attached the following so you can help diagnose what the problem is.
- My Script I am using in the sandcastle. (Hello world - attached below)
- My Geojson file I am loading into Cesium to produce the marker.(TestCoordinates1.geojson)
These are my issues;
- The marker is not located exactly where I click to get the coordinates. I know by looking at the story slide that the height is incorrect. Can you help with that as I don’t know how to correct the height. Once the height is corrected I will be able to assess if the long and lat are exactly correct.
You can see from my screenshot that the maker is below the surface.
// Grant CesiumJS access to your ion assets
Cesium.Ion.defaultAccessToken = ";
var viewer = new Cesium.Viewer(“cesiumContainer”);
var tileset = viewer.scene.primitives.add(
new Cesium.Cesium3DTileset({
url: Cesium.IonResource.fromAssetId(158422),
})
);
tileset.readyPromise
.then(function () {
viewer.zoomTo(tileset);
// Apply the default style if it exists
var extras = tileset.asset.extras;
if (
Cesium.defined(extras) &&
Cesium.defined(extras.ion) &&
Cesium.defined(extras.ion.defaultStyle)
) {
tileset.style = new Cesium.Cesium3DTileStyle(extras.ion.defaultStyle);
}
})
.otherwise(function (error) {
console.log(error);
});
viewer.canvas.addEventListener(‘click’, function(e){
var mousePosition = new Cesium.Cartesian2(e.clientX, e.clientY);
var ellipsoid = viewer.scene.globe.ellipsoid;
var cartesian = viewer.camera.pickEllipsoid(mousePosition, ellipsoid);
if (cartesian) {
var cartographic = ellipsoid.cartesianToCartographic(cartesian);
var longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(15);
var latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(15);
var heightString = Cesium.Math.toDegrees(cartographic.height).toFixed(15);
console.log(longitudeString + ‘, ’ + latitudeString +’,’ + heightString);
} else {
console.log(‘Globe was not picked’);
}
}, false);
//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== ‘undefined’) {
window.startupCalled = true;
startup(Cesium);
}
Geojson
{
“type”: “FeatureCollection”,
“features”: [
{
“type”: “Feature”,
“id”: “f45a1e55-441b-eeb0-686f-a285c8a7f320”,
“properties”: {
“name”: “Marker 1”,
“description”: “”,
“created”: “2020-09-29T10:53:26.789Z”,
“modified”: “2020-09-29T10:53:26.789Z”,
“tags”: ,
“color”: [
1,
0.9019607843137255,
0,
1
]
},
“geometry”: {
“type”: “Point”,
“coordinates”: [
6.680826504143448, 46.551491763372738,0.000000053360853
]
}
} ]
}
Thanks and I look forward to your reply.