Drawing tools
As part of providing the measurement widget we've also added access to some drawing utilities for making your own tools.
Today this includes the polygon and polyline drawing tools.
It is recommended to give the user some control over the ground occlusion state while tools are active.
Within our web navigator we allow pressing "g" on the keyboard to toggle it.
Here is how Cesium code lets you toggle it:
Polyline
Here is how you can enable and manage the polyline drawing tool.
The positions it works with are Cesium.Cartesian3. Read to the end of this page to learn how to turn that into latitude and longitude information.
Polygon
Here is how you can enable and manage the polygon drawing tool.
The positions it works with are Cesium.Cartesian3. Read to the end of this page to learn how to turn that into latitude and longitude information.
2D cursor into 3D position
If you need more or would like to develop your own tools. It is recommended to use our GetAccuratePosition method instead of Cesium directly.
This is because Cesium has a number of bugs where it may pick the position through the terrain and miss the mark by over 10km.
Our method uses some techniques to make this a rare occurrence.
Here is an example on how you can place 3D points on the map.
Drawing utilities
A common need is conversion between cartesian3 and cartographic. Here is how you can do that.
Below is a cheat sheet of some utilities that Nextspace provides within its library to help interact with the Cesium viewer.
As mentioned before getting a 3d position from a 2d cursor has some bugs in Cesium.
Here is a reminder on the utility we provide to help with that.
Here is a utility for getting the height of the terrain at a specific position. This will never crash nor return a non-number.
It will include a "error" property within the data if you'd like to know when there was a problem.
If you have a polyline and need to know a position x meters along it then use this utility:
Cesium has a concept of "HeightReference" which means an altitude value can mean different things in different concepts.
This can be quite annoying to program with as an Entity might say "50 meters height" but you'll need to calculate what that means to you.
For example you might want to know the height above the ground or the height above the sea.