Cartesian 3 to Cartographic coordinates

Is there a way to convert cartesian3 coordinates to cartographic?

I am trying to get the position of billboards that are placed on my map, but I want to see the position in lat/long coordinates.

Thanks for your help,
Lydia

Hi Lydia,

Check out Ellipsoid.cartesianToCartographic:
http://cesium.agi.com/Cesium/Build/Documentation/Ellipsoid.html?classFilter=Ellipsoid&show=js#cartesianToCartographic

Kevin

Thank you for your quick reply. I am now running into some problems.

I currently have the latitude, longitude, and height coordinates separated into individual variables. To combine them into one (create a Cartographic element), I am using:

var billboardPosition = Cesium.Cartographic.fromDegrees(lat, long, height);

However, now, when I try converting it back to cartesian, using Cesium.Ellipsoid.cartographicToCartesian(billboardPosition), I am getting the error: 'uncaught exception: DeveloperError: scalar is required and must be a number'. I believe this is because when the Cartographic object is created, it prints like:

({longitude: -1.6360035916051352, latitude: 0.656140155737535, height: "0"})

Why is the height surrounded by quotations? Is that why Cesium thinks it's not scalar?

Thanks, again!
Lydia

Yes, I think you’re right that the “0” is the problem. Check your “height” variable. Is it a string for some reason?

Also, fromDegrees takes longitude as the first parameter, not latitude.

Kevin

Thank you. I was able to solve the problem. :slight_smile:

I also have another (unrelated) question about setting the color for a billboard. When a user clicks on a billboard (b1), I want to change the color of it to red. However, when the user clicks on another billboard (b2) on the same map, I want b1 to change back to it's original color. This is my code so far:

oldColor = billboard.getColor();
billboard.setColor({
   red : 1.0,

Sorry! I didn't get to finish. Here's my code:

oldColor = billboard.getColor();
billboard.setColor({
   red : 1.0,
   green : 0.0,
   blue : 0.0,
   alpha: 1.0
})

and then in a later part, I have:
billboard.setColor(oldColor);

However, there is no change on my map. Do you know why this is?

Thank you!!
Lydia

getColor returns a reference to the color. Then, when you set a new color, that instance gets overwritten with the new value. In other words, oldColor changes to red when you call setColor. To fix it, make a copy.

oldColor = billboard.getColor.clone();

Oops, that should be:

oldColor = billboard.getColor().clone();

Thank you!! You've been a great help! :slight_smile:

Lydia