How to add additional "Flat" (e.g. Mercator and Winkel-Tripel) map projections?

I’d like to add additional “Flat” map projections (e.g. Mercator and Winkel-Tripel) in addition to the equirectangular (GeographicProjection) one already available.

I can do the projection math pretty easily, but it seems like Cesium might require a pretty big refactor. Am I missing something? Is there an easy way to add these?

Hello,

Cesium has support for web mercator. Here’s a code sample:

var viewer = new Cesium.Viewer('cesiumContainer', {
    sceneMode : Cesium.SceneMode.SCENE2D,
    mapProjection: new Cesium.WebMercatorProjection(Cesium.Ellipsoid.WGS84)
});

``

To add a new map projection, I think you just have to made a class that implements the MapProjection interface: http://cesiumjs.org/Cesium/Build/Documentation/MapProjection.html

So your class would need ‘project’ and ‘unproject’ functions.

Currently we default to GeographicProjection. You can see the code here: https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Core/GeographicProjection.js

And here is the code for WebMercator: https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Core/WebMercatorProjection.js

For something like Winkel-Tripel projection, you might run into some weirdness with the infinite scrolling. I would recommend starting out using the rotation map mode for 2D:

var viewer = new Cesium.Viewer(‘cesiumContainer’, {
sceneMode : Cesium.SceneMode.SCENE2D,
mapMode2D : Cesium.MapMode2D.ROTATE
});

``

If you do implement Winkel-Tripel, let us know! I think that’s something other people would be interested in, we would love the contribution back =)

Best,

Hannah

My initial tests aren’t looking great, but I’m going to keep going. (This post by Kevin Ring suggests that this kind of projection might not be possible, but I’m not exactly sure what is meant by ‘unless the projection is aligned with latitude and longitude.’ https://groups.google.com/forum/embed/?place=forum/cesium-dev&showsearch=true&showpopout=true&hideforumtitle=true&fragments=true&parenturl=http%3A%2F%2Fcesiumjs.org%2Fforum.html#!searchin/cesium-dev/mapprojection/cesium-dev/UKyD7jYTw-o/tH3PfeQ3EQAJ)

Also, it doesn’t look like the mapProjection can be changed “on-the-fly” (i.e. after the scene is already created) as it’s a read-only property and doesn’t seem to have a setter. Is that true?

Sorry, I’m not too familiar with the specifics. Maybe Kevin or someone else can give some more information.
For changing the projection on the fly- I know we used to have that available. I’m not sure why we changed it to read-only.

Sorry for not being more helpful, this is an area of the library I’m not as familiar with.

-Hannah