Equator/Tropics as PolylineCollection... how to add to Viewer?

I’d like to create a simple representation of the Equator and the Tropics of Cancer/Capricorn on the globe and I’m running into a few problems.

First, using examples from Sandcastle, I can do this:

var equatorLine = myViewer.entities.add({

name : ‘Equator’,

polyline : {

positions : Cesium.Cartesian3.fromDegreesArray([-179, 0,

0, 0,

179, 0]),

loop: true,

width : 3,

material : Cesium.Color.GREEN

}

});

… and I get a nice green line with a little gap near -180.

BUT, if I try to pass -180, or -179.9, the line does not draw at all (and I don’t see any errors in the console).

Next, what I’d really like to do is to create three polylines, store them in a PolylineCollection, and add that entire collection, but it’s not obvious how to do that.

I guessed:

myViewer.entities.add(myPolylineCollection);

but that didn’t work.

So, how do I create lines of latitude, and how do I add them to the viewer/scene as a collection?

Thanks

Hello,

When Cesium tries to draw a polyline on the ellipsoid surface, it tries to find the shortest surface distance between those two points and will draw that line. It has trouble figuring out how to draw a line from 180 to 0 because it is exactly on the other side of the earth. For example, it’s not obvious if the best path is to go around the equator, or through the north pole.

You can fix this problem by adding more between points to your polyline:

var viewer = new Cesium.Viewer(‘cesiumContainer’);
viewer.entities.add({
name : ‘Equator’,
polyline : {
positions : Cesium.Cartesian3.fromDegreesArray([-180, 0,
-90, 0,
0, 0,
90, 0,
180, 0]),
loop: true,
width : 3,
material : Cesium.Color.GREEN
}
});

``

Best,

Hannah

Hannah,

Thanks for that! Seems to work. What about the second part of my question, i.e. once I add these to a PolylineCollection, how do I add that collection to the Viewer/Scene?

  • Dave

Hi Dave,

Do you have a reason for using a PolylineCollection instead of adding a polyline using the Entity API?

-Hannah

Well, it seemed like the right data structure to use for a collection on polyline objects! (Where WOULD one use a PolylineCollection?)

The idea was that I have multiple Polylines (e.g. Equator, Tropics of Cancer/Capricorn) that I wanted to turn on and off together.

All that said (as you’ve seen from my other post) I’ve moved on to using the Entity API, which revealed other issues.

  • Dave