September 29, 2010
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.
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.
Note: Nathan has graciously ported this to JavaScript: https://github.com/afar/robinson_projection
Home | License | Privacy | Releases | Testimonials | Resources | Documentation | Order Lookup | All Maps | FAQs
Formerly FlashUSAmap.com and FlashWorldMap.com
SimpleMaps.com is a product of Pareto Software, LLC. © 2010-2024.