I can measure horizontally between two points - how can I do the same vertically?

1. A concise explanation of the problem you’re experiencing.

At the moment, I can add points by double clicking on the terrain, when there are more than one point, a line is drawn between them and the (horizontal) distance is added to a label along the line.

I am trying to figure out how to do the same thing, but for vertical distances I can’t figure out how to add a point in a vertical context, an example would be to measure the height of a building and not just the width/depth.

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.

I have a Sandcastle link if that is easier:

https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/index.html#c=fVZtTxs5EP4re3xho0YOkOv1jgC6ElIuiAQKKaWQqnJ2nayL187Z3qCk4r/f+GXf8nKWot3YzzOeGT8z6wWWQRdLTRTFvB2cBl14y1JUznXGfMxbreBSYq798tV9gKOIKBVoESxFJgMqeICVIlqNuTfRFxzFZIozpj9a8Ei8EA5b7JPlVTK5jOgNvep/WfUPh7Sv+vzufdTt/9F/mT8+dK/+QgD6N758MSA6GJ3/HB712gN60H66fHq5Ht0l39K+vvnaWw27h/RmFP+8ueitBqvB+8FqRq+7V/MnMDa8+Kz6KUtieB+MPv8+/Am/i8HBoH2AztvdD0NBlu2n28do+uHHp8fz3rdXKiN91J6qLyS64/eHR5+YHv65b3OwgFRFNrQRkRJTfivFgsZEllmLJMGafBWSxR4TNjqOSRijcyVovEnm5DU30NuBsmacoQUlr+u0BzsX7jv3uoJr4BK53wx+jXkAY4IVucZLIm9p9ALs42CKmSJNt6rXXDreHueYv+XRqIhwAj44Z5D9az20b2jGxITA4c91MiJKf5yBFaW9OaBpmZEiIE0ZAeHAtCPPJU2ppguiEI7j0LlYCdY92hcjxwt9iGZkkh0HpfzuiAJtRgRNpUg/GnX247D9oX3UcJQ3ePrEujhWQqQjEXqPPAoJnRD5ShUJpxmPtJF6CKEI2Qgqe0eCK8EIYmLmVzv5LnaLgpvNYxCJ8T6wOxVWTDImIuMx5bMHwbLUZNggUH3W26XTIPSxQpnBecfWHAJHNOH6vMZp1HzdvstWYh5E6aKHrbE6JSAVMWGw7FfQDztRASSEzhJjoO4HSimnaZb+Y5creJCFtpK3htAPqaOunapguJApZoWInAKLokMzAlRNo/tMTnFEhhYdOsNNp66i44WNRsWwmE6dOksASqGn0Tlbni/vI8ywDN3uTR/Z/xuMYF7UO62YSTxPaGSFWvC8e1XuHNZBiCX7NSG2y/oWkevCJWG9rk9PT3f2oZo+zFaSKIjSHKNxsFMuugVUHOJBZc37hwAj2IKEDltUAuwOzv/awJfxKJzOGfG+DYTSFwR6GQNtbw2pGTxb9743EBQpLwrUb6xqUW1E5kHPB987dZRJ4W9rteVD2bDoUqIzyTcyVSmcNaQzVoG+NcpCcy95KrfFVXOiCGeboLQo5VQ/jEJSQlHbl2oKV9lESxxpT2r6MtitbDPWy7NuMmKCkzDfrrmBrvXLtx0t0zR8KUSZAXNUZiLvQ3cEx8tafkqyY+4Uo8kGowqsWNf9VwCZ57XAsfka9RawxbXHlKdSa+NVEZkFW3Y1n6uj4p210tmE5D6Fjd3a2tSPbTUJZbG0ly6XI/+/0lEY4TOdmDL3a8jNeMhUyCA0OGorHR4nntIJ3r2jOxJtTim390y/V3yz7t1jHkdYafh6QE5HYjZj5DzTGjK5n18SehxPoOzhCmMuC82gyHWUELjCxDUBrM+ZsaMFbr/a7NTELiu72uj6KdRzkksq16E9tb3m3onSS0bOHOVvms6F1OYyEyLU0gQ6IthQrUkGQcIhKmVoJ62cdBLTRUDj0/He2v1vvBdEDG7lsDLNGLunKzLeOztpAb5GY6Bu+ArfLIhkeGkgyeHZtZtECJ204O8mSwvBJlhWLP4H

To reproduce, double click anywhere a couple of times to add some points and for the line to be drawn between them. The distance between the points should be calculated and displayed, I’d like to calculate the vertical distance, for example, the height of a building.

I am trying to calculate the height of the click but I always seem to get ‘no cartesian’ here:

handler.setInputAction(function(click) {

var clickPosition = viewer.camera.pickEllipsoid(click.position);

var cartesian = viewer.scene.pickPosition(clickPosition);

if (cartesian) {

console.log(‘cartesian’);

var cartographic = Cesium.Cartographic.fromCartesian(cartesian);

height = cartographic.height.toFixed(2) + ’ m’;

} else {

console.log(‘no cartesian’);

}

lastPosition = clickPosition;

addPoint(lastPosition);

}, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

I would love to figure out how to measure vertical distances in addition to horizontal ones, and eventually do the same with a polygon.

4. The Cesium version you’re using, your operating system and browser.

Cesium 1.61, OS X and Chrome.

Try this:

The problem of no cartesian will be resolved

handler.setInputAction(function(click) {

var cartesian = viewer.scene.pickPosition(click.position);

console.log(cartesian);

if (Cesium.defined(cartesian)) {

console.log(‘cartesian’);

var cartographic = Cesium.Cartographic.fromCartesian(cartesian);

cartographic.height = cartographic.height.toFixed(2) + ’ m’;

} else {

console.log(‘no cartesian’);

}

Ah, thank you so much, I have no idea why using variable assigned to click.position would work though.

I’m assuming I’d need to convert the cartographic back to a cartesian in order to pass it to my addPoint method?

It basically does

addPoint(position) {

var point = {

position:position,

}

}

I’ve just realised my sandcastle link isn’t the right one, I am sure it worked earlier but I can recreate it.

If you haven’t seen it, the ion SDK (which builds some additional features onto CesiumJS) does have measurement tools for horizontal, vertical, or just perpendicular to any surface:

https://cesium.com/ion-sdk/

We’re working on making it available on the Cesium ion platform so it’s easier to make these kinds of measurements!

Hi Omar,

I actually just found that link a couple of hours ago.

Do you know if the ion SDK can be used but with non hosted ion assets?

e.g. We already have all the data we need so we don’t need any tile generation or cloud hosting offered by the ion service, but the SDK might be an option if it can be used on it’s own.

Also, here are some images to better explain, from the first picture you might expect the yellow dot to be the top of the building when it’s really a horizontal point in the distance.

Screenshot 2019-09-23 at 14.40.42.png

Screenshot 2019-09-23 at 14.41.19.png

Yes, in fact that’s currently how it’s available. It’s part of the Cesium ion on-premise tools, so you can use it locally/offline/in your own application.

You can request an evaluation here: https://cesium.com/contact/sales/

Thanks Omar,

I submitted an enquiry yesterday.

Cheers,
Martin