simplemaps
Articles Home

Robinson Projection in AS3 GPL

3 Comments

One of the coolest features of our new interactive world map is that you can add location markers to the map using latitude and longitude.  And, I’m going to open source the code and show how I did this with the world so anyone can integrate it into their flash maps.

This was a difficult feature to implement because the world is a globe and when you project that globe onto two-dimensional space the latitude and longitude lines are not evenly spaced or perpendicular lines.  Solving the problem is particularly difficult for the Robinson Projection.  This is one of the most popular map projections.  It was popularized by Randy McNally in the 1960′s and is considered to be one of the most aesthetically pleasing projections of the globe.  However, unlike other projections it isn’t based on a nice formula.  Rather, it is based on an ad hoc table of input values that were chosen to look good.

To figure out how to take latitude and longitude coordinates and project them into x/y space  I had to wade through this journal article (the find articles version omits this very important table).

The process is not exactly straightforward.  You need to convert latitude and longitude into radians.  You also need to extrapolate for values that are between rows in the table.  After many frustrating hours I finally coded up some Actionscript 3 that will transform lat/lon into x/y coordinates.  These x/y coordinates are based an origin located in Africa.  So, to get them to work with Flash which has an origin in the upper left corner takes some adjustments.  Of course, you also need to scale the x/y coordinates based on the size of your map.  For the code to work, your map must be a Robinson projection and have a width that is 1.97 times the height.  I wrote some directions to walk you through the process.  As you work, use this resource for verifying output values.

————————-Download the Code————————-

1.  Robinson-Projection-Actionscript3 Code (.as)

2.  Directions on Scaling and Use (.txt)

——————————————————————

All code is licensed under the GPLv2.  This means that any derivate works that you create using the code must be released under the same license.  If you wish to use this code in a product you want to resell, you need to ask for permission by contacting me.

3 Responses to Robinson Projection in AS3 GPL

  1. Mortimer N. says:

    Thank you very much for sharing this Code.

  2. Nathan says:

    It is very kind of you to share this code, thank you.

  3. Nathan says:

    I ported this code to Javascript, it is available here: https://github.com/afar/robinson_projection

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>