The Making of a Stacked and Animated Map

Remember that time when we mapped and animated the 2018 Formula 1 racing circuits?

You know, it had that wild, neon pink, retro color scheme…

Formula 1 screenshot

I promised to “walk through how D3 and flubber were used to make all this come together”.  Well then, we’ve arrived here, and along the way we looked at how to begin making web maps in D3 followed by how to wrap your mind around web map projections.  Be sure to check out those posts, too.  The concepts build on top of each other in the hopes of making this one easier to digest.

Getting to the main point:

How do you stack and animate geographical features that are located in different places?

Map projections play an important role in this technique.  I chose to project the Formula 1 circuits using the Mercator projection because it is good at maintaining the shapes of small features, specifically when rotated to each feature’s centroid and zoomed in closely.  Mercator thus is “conformal” in projection terminology.  And since it can be a pain to remember: zooming in closely on a map means using a large, local map scale.

I’ve broken out the inner workings of the stacking and animating technique into 3 separate parts which are very much alive and kicking in the CodePen demos below.  Each Formula 1 circuit is first translated from geographic coordinates to SVG space (projected) by rotating and scaling the Mercator projection to every one of these circuit features.  This is what fundamentally makes them appear stacked because they now occupy the same area of the SVG element.  Finally, instead of showing all of them at once, we only show one circuit’s shape at a time and animate to the shape of the next circuit in the stack.

Part 1: A two-dimensional globe is drawn with an orthographic projection to show how projections can be rotated to specific locations on Earth.  In the bottom area of this demo–using the Mercator projection with a large map scale–we also rotate to each circuit’s centroid location and then add the circuit to the stack.

See the Pen Stacking & Animating Formula 1 Circuits in D3 (Part 1) by Jacob Wasilkowski (@jwasilgeo) on CodePen.

Part 2: Skip the leisurely world tour and immediately make a stack of circuits.  Again, each circuit is drawn as an SVG <path> element with the assistance of a uniquely rotated Mercator map projection.

See the Pen Stacking & Animating Formula 1 Circuits in D3 (Part 2) by Jacob Wasilkowski (@jwasilgeo) on CodePen.

Part 3: By now we know how to quickly create a stack of disparate geographic features. The focus in this final demo is on the animation that morphs between all the circuits’ shapes using the flubber JavaScript library.

See the Pen Stacking & Animating Formula 1 Circuits in D3 (Part 3) by Jacob Wasilkowski (@jwasilgeo) on CodePen.

Leave a Reply

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