1 of 44

History of Rendering Web Maps

Class 2

2 of 44

We’re going to take a journey deep into the history of map-making and how it led us all the way to the whiz-bang mappy miracles we see in modern maps today.

3 of 44

4 of 44

Ok, maybe not quite that far back...

5 of 44

Let’s start with print maps (you’ve probably made a few of these in your mapping career already).

What are the basic steps to making a map?

With static and print, there is one extent and one scale to style for (generally speaking, of course).

Add data

👇

Style data at specific scale and extent

👇

Export to PDF/image

6 of 44

This is not to say that print cartography is easy...

...but rather that it is straightforward compared to cartography for world-scale interactive maps.

7 of 44

When designing an interactive, multi-scale map, you have to design for many possible extents and scales.

The solution to this problem, employed by early webmaps and still common today, is to create a bunch of static maps at predetermined scales and extents.

8 of 44

Early web maps:

In the first iterations of this approach, every “pan” of the map was really a new, pre-created image loading on the page (static maps forever).

Tiled web maps:

Instead of a loading a static map for a limited number of extents, the tile era allowed users to set their own extent and the map client would handle loading just enough tiles to make the map look good.

9 of 44

The standardization of the tile led to a mini explosion of growth in the mapping world…

...including a product called TileMill and a company called MapBox

10 of 44

🤔 Remember the three basic steps to designing a print map:

Add data

👇

Style data at specific scale and extent

👇

Export to PDF/image

For multi-scale interactive maps, it’s the same steps, but with some twists:

Add all the data you might possibly need

👇

Style data at a specific set of scales and extents

👇

Export a billion (approx) tiny tiles

11 of 44

Mapnik is the monster that eats data and stylesheets and poops out map tiles with the exact right extents, at the exact right zoom levels, stored in the exact right structure.

Cool! 🤓

But the magic of TileMill happened beneath the surface.

TileMill is a visual interface for interacting with a much more powerful tool: Mapnik.

12 of 44

In TileMill, users defined styles with a special styling language called CartoCSS that defined how each data layer should be displayed at each zoom level.

CartoCSS is cool, but we won’t be getting into it further. Just know that it was around to help cartographers style their interactive maps.

13 of 44

14 of 44

TILEMILL RECAP:

  1. Load some data into the software.
  2. Use CartoCSS to specify how the map should look at each zoom level.
  3. Export a bajillion tiles.

15 of 44

TILEMILL RECAP, ctd...

  • Interactivity? Not really (except for some legit interesting workarounds.)
  • Map clients? A lot! Mapbox.js, Leaflet (👋), OpenLayers, and many more!
  • Storage? Kinda up to you, but lots of companies offered tile storage for 💸 (👋)

16 of 44

There’s a catch, right?

Several!

17 of 44

  1. Image quality

  • Renderer limitations
  • Storage limitations
  • The emergence of “retina” devices

18 of 44

2. Size

Storing tiles for the entire world, at 16+ zoom levels, and in multiple style flavors takes up a TON of space.

19 of 44

3. Malleability and updates

What happens when features change? You have to re-render the entire world, which could take a long time.

20 of 44

In an ideal world, you could create map tiles on the fly based on desired image quality and styling rules.

Enter the Mapbox Vector Tile Specification!

Vector tiles are similar to the map tiles we’re already familiar with:

The world, in a grid.

But they contain vector data instead of images.

21 of 44

🙋‍♀️ Why does this matter?

Why do you think? Hint: think back to the TileMill shortcomings we discussed earlier?

22 of 44

🙋‍♀️ Why does this matter?

Vector tiles separate data storage from map rendering.

Because you’re only storing data and a list of the rules for how the map should look, rendering only needs to happen at the very end of the process.

23 of 44

💽 A note about vector tile formats

Tiles that conform to the Mapbox Vector Tile Specification (the most common VT spec you’ll run into) are usually served with one of a few extensions:

  • .pbf: this is a protocol buffer, or protobuf, file. It’s a method for serializing data that is super compact and great for making vector tiles small and easy to transmit. Once the .pbf files arrive, they are decoded by the map client.
  • .mvt: this is a file extension specific to Mapbox Vector Tile Specification-compliant vector tiles. They are served as gzipped protocol buffers. This just means they’re extra small and compressed to make them small and fast.
  • .vector.pbf: this is an old extension that was replaced by .mvt.

24 of 44

Mapbox released Mapbox Studio (now called “Classic”) to focus on this separated data/style paradigm.

25 of 44

Convert your vector data (GeoJSON, shapefiles, etc.) into vector tiles.

Create stylesheets to determine how your map will look.

26 of 44

SOURCE

MODE

27 of 44

STYLE

MODE

28 of 44

The process for creating a map with Mapbox Studio Classic was kind of confusing.

(you don’t need to know this stuff. We’re just talking about it to illustrate why things are better today 🙂)

  • In Mapbox Studio Classic source mode, add your vector data
  • Upload to Mapbox to convert the data to vector tiles
  • Grab the ID of the newly-uploaded source and add it in Mapbox Studio Classic style mode
  • Style that source data at predetermined scales and a global extent with CartoCSS
  • Upload style to Mapbox

29 of 44

The Gist:

As opposed to a big ol bucket o tiles (TileMill), the output of Mapbox Studio Classic was:

  1. A source (vector tiles)
  2. A style (mapnik style document)

No raster tiles are created at all...

GAH

😖

30 of 44

Until you ask for them...

😨

Raster tiles are rendered on the fly, only when they’re needed. This solves the three problems we talked about earlier:

  1. Image quality. Render at whatever resolution you need.
  2. Size. Only store vector tiles and style rules.
  3. Malleability and updates. The same vector tiles can be used across an infinite number of styles!

31 of 44

Client side:

🦗

Server side:

Super dope rendering on the fly super fast and great.

32 of 44

Client side challenges:

  • Interactivity relies heavily on overlays example.

33 of 44

Client side challenges:

  • Interactivity relies heavily on overlays example.
  • Jumpiness when transitioning between zoom levels example.
  • Loading is faster than before, but could be better still!

34 of 44

💻 Moving to the client

With Vector Tiles and Mapbox Studio Classic, styles and sources were separate things that got smashed together into tiles on-demand, right? What if you could make it even more on-demand?

Mapbox GL is a way to render maps with vector tiles in the browser rather than as images on the server.

35 of 44

💻 Moving to the client

🚂 Render on the server with Mapnik. Vector tiles are combined with CartoCSS styles (both of which are stored on the server), fed to Mapnik, and raster tiles are created and served to the browser.

🚅 Vector tiles and style documents are stored on a server and both are served to the browser. As a final step, the map is rendered in the browser with the help of your device’s graphics processing unit.

36 of 44

This makes map loading super fast. It also means you can do cool stuff like:

  • Rotating
  • Tilting
  • Smooth zooming
  • Feature querying
  • More stuff we’ll talk about later!

37 of 44

So, how does this work?

💗 At the heart of the process is Vector Tiles, those little squares filled with data from earlier.

🎨 But because those tiles are just data, your browser needs guidance on what to draw and how to draw it.

Enter the Mapbox GL Style Specification!

(yes, another spec!)

The stylesheet contains all the information needed to draw your map, including:

  • References to data
  • References to Fonts
  • References to images
  • Styling rules

38 of 44

Mapbox GL Styles

Style rules are defined in the spec as layers: styled representations of data.

39 of 44

Styles are written as JSON. Each layer has a number of properties that describe where it should go, how it should look, and what data it should reference.

40 of 44

But no one wants to write a bunch of JSON by hand. 😬

This is where Mapbox Studio comes in!

Mapbox studio is a visual interface for creating GL stylesheets!

41 of 44

Hands on time!

42 of 44

  1. 👯‍♀️ Get into pairs.
    1. One person will captain ArcMap and the other will captain Mapbox Studio. (hint: one of you will need access to ArcMap)
  2. Download this GeoJSON file: http://bit.ly/sf-bounds-geojson
  3. Splitting up:
    • Open the file in ArcMap and add a basemap.
    • Open a new Style in Mapbox Studio, then, from the Layers tab, click the plus button (+) to create a new layer. In the new layer menu, click the + Upload button to add your new layer.
  4. Both of you:
    • Try moving your new layer up and down in the layer order and note the differences between the behavior you’re seeing in ArcMap vs Mapbox Studio.

43 of 44

Hands on time:

🙋‍♀️ What did you discover?

44 of 44

Map rendering recap

TileMill

  1. Render combine data and style rules to render tiles.
  2. Store the tiles somewhere.
  3. Serve the tiles to the end user.

Mapbox Studio Classic

  • Store vector tiles and styles on a server.
  • Render tiles on the fly by combining vector tiles and style rules.
  • Serve the rendered tiles to the end user.

Mapbox Studio

  • Store vector tiles and styles on a server.
  • Serve tiles and style document to end user.
  • Render the map from vector tiles and style rules.