• Stars
    star
    541
  • Rank 82,114 (Top 2 %)
  • Language
    HTML
  • License
    BSD 3-Clause "New...
  • Created about 5 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Storytelling with maps template

Updated to Mapbox GL JS V2.0.0

  • Set use3dTerrain: true for 3D maps

3D mountains in Colorado

Interactive Storytelling

Some stories are best told with a map. Data journalists covering changing conditions in a population's demographics, the environment, an international conflict, or telling a simple travel story frequently provide geographic context in their graphics.

This template is designed to accelerate building out a "scrollytelling" map story. The primary input is a story broken into sections (chapters), each hooked to a particular view of a map.

Optionally, you can input a custom Mapbox Style with layers styled in Studio and toggle the layer's opacity.

The output is an HTML and JavaScript file. These outputs can be hosted on any web-accessible location, with no extra code or infrastructure required. Note that embedding the output as an iFrame in another page will not work as expected. The scroll-driven interface requires the full page.

Prerequisites

This template is for data journalists and digital storytellers of any kind. No coding experience is required. If you are planning to include some custom map layers, you will need some familiarity with Mapbox Studio.

To configure and publish a story, you will need:

  • A Mapbox access token. Sign up for a free account at mapbox.com to get one.

  • A text editor. Atom, Sublime Text, and Visual Studio Code are all fine choices.

  • A place to publish your work. Any service that hosts static files that can be accessed with a browser will do.

  • A story. This is unquestionably the hardest part. The best stories for this template will have sections that benefit from a map.

  • Attention to detail. The configuration file does require specific syntax and punctuation. Braces, brackets, commas, and quotes are important. Follow the config.js.template for guidance. Some familiarity with JSON is recommended.

  • Optionally, some spatial data in your Mapbox map. The template has options to include layer names to show and hide the data as the story sections transition. You may want to highlight a neighborhood, or show satellite data from two different times.

The template does not rely on any particular CSS framework, fonts, or images. There are some basic styles in the head of the HTML file that can be changed, so feel free to adapt and add to these to match your site and story brand.

example story screen capture

Getting Started

  • Download this repository as a ZIP file using the button above, and unzip it. If you are using git, clone this repository.

In your local copy of this repository (the unzipped file you downloaded), navigate to the src/ directory.

Make a copy of config.js.template and name it config.js. Open the new config.js file in your text editor.

Steps

  1. Select the map style you want to use (the default is Mapbox Streets, but you can find more here https://docs.mapbox.com/api/maps/#styles, or use one of your custom Studio styles).

  2. Add a Mapbox access token. A good practice is to create a separate token per map to be able to track traffic to your different maps.

  3. Choose whether or not to display a marker at the center of each map location. If you are displaying markers, you can set the color using the markerColor property. The default color is light blue.

  4. Choose a theme for the story text. There are light and dark options.

  5. Choose where your story should be aligned over the map. Options are center, left, right, and full.

{
    style: 'mapbox://styles/mapbox/streets-v11',
    accessToken: 'YOUR_ACCESS_TOKEN',
    showMarkers: true,
    markerColor: '#3FB1CE',
    theme: 'light',
    use3dTerrain: false,
    title: 'The Title Text of this Story',
    subtitle: 'A descriptive and interesting subtitle to draw in the reader',
    byline: 'By a Digital Storyteller',
    footer: 'Source: source citations, etc.',
    chapters: [
        {
  1. Add as many chapters in your template as needed. You'll need a , between each section, but no comma at the end. Here is what a chapter looks like:
{
            id: 'slug-style-id',
            alignment: 'left',
            hidden: false,
            title: 'Display Title',
            image: './path/to/image/source.png',
            description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
            location: {
                center: [-122.418398, 37.759483],
                zoom: 8.5,
                pitch: 60,
                bearing: 0
            },
            mapAnimation: 'flyTo',
            rotateAnimation: false,
            callback: '',
            onChapterEnter: [],
            onChapterExit: []
        },
  1. Fill out your sections as needed. Give each section a unique name in the section id property. This will become the HTML div id, so avoid spaces in the name. The title, description properties are optional. The description supports HTML tags. If you have an image that goes with that section of the story, add the path to the image in the image property.

  2. For location, you can use the helper.html file to help you determine the map's position. This tool prints the location settings of the map on the screen in a format ready for copy/paste into the template. Optionally, you can change the style in this file to your custom style.

  3. Repeat until you have the location entered for each of your sections.

  4. Open index.html in a browser, and scroll. Voila!

Generate Map Position Using Helper.html

Using the helper.html file, you can search for places, zoom, pan, tilt, and rotate the map to get the desired map position (Hint: To tilt and rotate the map, right-click and drag the map).

Notice the location parameters are updated in the upper left corner with everytime you move the map. You can copy the location definition from that page into the config.js location property section.

There is also a hosted version of this file at https://demos.mapbox.com/location-helper/

location helper screen capture

Configuration File and Layer Settings

Here is a sample configuration:

var config = {
    style: 'mapbox://styles/branigan/cjz37rcb003ib1cr3s8rnkt2d',
    accessToken: 'pk.eyJ1IjoibWJ4c29sdXRpb25zIiwiYSI6ImNrMm01aG9hdTBlZGwzbXQ1ZXVrNHNmejAifQ.QHQA0N6XPWddCXtvoODHZg',
    showMarkers: false,
    theme: 'dark',
    use3dTerrain: true,
    title: 'Glaciers of Glacier National Park',
    subtitle: 'Change in coverage from 1998 to 2015',
    byline: '',
    footer: 'Source: Story text from Wikipedia, August 2019. Data from <a href="https://www.usgs.gov/centers/norock/science/retreat-glaciers-glacier-national-park">USGS</a>',
    chapters: [
        {
            id: 'glacier-np',
            alignment: 'full',
            title: 'Glacier National Park Glaciers',
            image: 'https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/2015-06-19_Glacier_National_Park_%28U.S.%29_8633.jpg/800px-2015-06-19_Glacier_National_Park_%28U.S.%29_8633.jpg',
            description: 'Glacier National Park is dominated by mountains which were carved into their present shapes by the huge glaciers of the last ice age...',
            location: {
                center: [-113.91666, 48.66451],
                zoom: 8,
                pitch: 0.00,
                bearing: 0.00
            },
            onChapterEnter: [
                {
                    layer: 'gnpglaciers-1998',
                    opacity: 0.25
                },
                {
                    layer: 'glaciernp-boundary',
                    opacity: 0.25
                }
            ],
            onChapterExit: [
                {
                    layer: 'glaciernp-boundary',
                    opacity: 0
                }
            ]
        },
        {
            id: 'harrison1998',
            alignment: 'left',
            title: 'Harrison Glacier, 1998',
            image: '',
            description: 'Harrison Glacier is located in the US state of Montana in Glacier National Park. Situated on a southeast facing ridge immediately south of Mount Jackson, Harrison Glacier is the largest glacier in Glacier National Park...',
            location: {
                center: [-113.72917, 48.58938],
                zoom: 12.92,
                pitch: 39.50,
                bearing: 36.00
            },
            onChapterEnter: [],
            onChapterExit: [
                // {
                //     layer: 'gnpglaciers-2015',
                //     opacity: 0
                // }
            ]
        }
    ]
}

Configuration Options

Note: items in bold are required.

style: This is the Mapbox style url to use for the app. It can be a standard style, or a custom style from your Mapbox account. Use a custom style if you want to include custom data or layers.

accessToken: Your Mapbox access token.

showMarkers: This controls whether markers are shown at the centerpoint of each chapter. If true, the map will display a default blue, inverted-teardrop icon.

markerColor: Accepts hexadecimal, RGB, and color names compatible with CSS standards. If showMarkers is true, this property will override the default light blue marker color.

theme: Two basic themes (light and dark) are available.

use3dTerrain: Enables 3D terrain. (Optional)

inset: Enables inset map. (Optional)

projection: Set the Map object's projection parameter to create a map with a non-Mercator projection.. (Optional)

auto: Enables automatic advancement through the chapters. (Optional)

title: The title of the overall story. (Optional)

subtitle: A subtitle for the story. (Optional)

byline: Credit the author of the story. (Optional)

footer: Citations, credits, etc. that will be displayed at the bottom of the story.

chapters: This contains all of the story content and map controls for each section of the story. Array of objects

  • id: A slug-style ID for the chapter. This is read by the JavaScript driving the app and is assigned as an HTML id for the div element containing the rest of the story. A best-practice format would be to use kebab case, like my-story-chapter-1.
  • alignment: This defines where the story text should appear over the map. Options are center, left, right, and full. When the browser window is less than 750 pixels wide, the story will be center aligned.
  • hidden: Sets the visibility of the chapter to hidden when true. The chapter will still trigger a map and layer transition.
  • title: The title of the section, displayed in an h3 element.
  • image: The path to an image to display in this section.
  • description: The main story content for the section. This should be aligned with what the reader is seeing on the map. In the vanilla version, this field will render as HTML. Images, links, and other items can be included as HTML.
  • location: Details about the map display and camera view.
    • center: Center coordinates of the map, as longitude, latitude
    • zoom: Zoom level of the map.
    • pitch: Angle of the map view. 0 is straight down, and 60 is highly tilted.
    • bearing: Degrees of rotation clockwise from North (0). Negative values represent counter-clockwise rotation.
  • mapAnimation: Defines the animation type for transitioning between locations. This property supports 'flyTo', 'easeTo', and 'jumpTo' animations. If not specified, defaults to flyTo.
    • flyTo and easeTo options (curve, maxDuration, minZoom, screenSpeed, speed) can be included in the location array, for example:
            location: {
                center: [-113.72917, 48.58938],
                zoom: 12.92,
                pitch: 39.50,
                bearing: 36.00,
                speed: 0.2,
                curve: 1
            }
  • rotateAnimation: Starts a slow rotation animation at the end of the map transition when set to true. The map will rotate 90 degrees over 24 seconds.
  • callback: Accepts the name of a JavaScript function and executes the function. Use this if you have custom code you want to run for a chapter, like turning a legend on or off, adding data from an API request, or displaying an interactive graph.
  • onChapterEnter: Layers to be displayed/hidden/muted when the section becomes active. Array of objects
    • layer: Layer name as assigned in Mapbox Studio.
    • opacity: The opacity to display the layer. 0 is fully transparent, 1 is fully opaque.
    • duration: The length of the opacity transition, numeric, in milliseconds. Default is 300. This is an optional parameter and can be omitted.
  • onChapterExit: Same as onChapterEnter except it is triggered when the section becomes inactive. Array of objects

Layer Configuration in your Mapbox Studio Style

Add and style each custom layer in your Studio style. Before the final publish, set any layers's style to be hidden with 0 opacity. Do not hide the layer. For example, if you have a circle layer, makes sure the color-opacity and/or the stroke-opacity is set to 0.

This will ensure that the map appears correctly when the story page loads. To adjust the opacity of the layers as the reader scrolls through the story, use the onChapterEnter or onChapterExit configuration options to set your desired opacity for the layer.

Organization

  • src: Code for the template
  • example: Example stories
    • glacier: Glaciers of Glacier National Park example
    • bike-philly: Philadelphia bicycle infrastructure example

Deployment

Host the index.html and config.js files in the same directory in a web-accessible location. If you don't know where to start, look into GitHub Pages or Netlify.

Built With

  • Mapbox GL JS
  • Scrollama.js

Authors

John Branigan on the Mapbox Solutions Architecture Team

License

BSD 3-Clause License

Acknowledgments

  • Lo BΓ©nichou for the idea, support, and awesome feedback throughout the design and build process
  • Paige Moody and Lem Thornton for early testing and feedback
  • Chris Toomey for ushering this work through and keeping things on track
  • Journalists with stories that help us make sense of what goes around us
  • Digital Democracy and Rudo Kemper for their fork that inspired many later features.
  • Paul Franz for developing customizations and providing feedback.

Notable Examples

mapbox.com/resources#solutions

More Repositories

1

mapbox-gl-js

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
JavaScript
10,264
star
2

pixelmatch

The smallest, simplest and fastest JavaScript pixel-level image comparison library
JavaScript
6,055
star
3

mapbox-gl-native

Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL
C++
4,297
star
4

tippecanoe

Build vector tilesets from large collections of GeoJSON features.
C++
2,423
star
5

awesome-vector-tiles

Awesome implementations of the Mapbox Vector Tile specification
2,311
star
6

delaunator

An incredibly fast JavaScript library for Delaunay triangulation of 2D points
JavaScript
2,255
star
7

earcut

The fastest and smallest JavaScript polygon triangulation library for your WebGL apps
JavaScript
2,174
star
8

supercluster

A very fast geospatial point clustering library for browsers and Node.
JavaScript
2,061
star
9

robosat

Semantic segmentation on aerial and satellite imagery. Extracts features such as: buildings, parking lots, roads, water, clouds
Python
1,997
star
10

mapbox.js

Mapbox JavaScript API, a Leaflet Plugin
HTML
1,902
star
11

geojson.io

A quick, simple tool for creating, viewing, and sharing spatial data
JavaScript
1,740
star
12

geojson-vt

Slice GeoJSON into vector tiles on the fly in the browser
JavaScript
1,731
star
13

flamebearer

Blazing fast flame graph tool for V8 and Node πŸ”₯
JavaScript
1,634
star
14

maki

A POI Icon Set
JavaScript
1,475
star
15

polylabel

A fast algorithm for finding the pole of inaccessibility of a polygon (in JavaScript and C++)
C++
1,312
star
16

togeojson

convert KML and GPX to GeoJSON, without the fuss
JavaScript
1,185
star
17

mapbox-studio-classic

JavaScript
1,136
star
18

node-pre-gyp

Node.js tool for easy binary deployment of C++ addons
JavaScript
1,071
star
19

webgl-wind

Wind power visualization with WebGL particles
JavaScript
943
star
20

geobuf

A compact binary encoding for geographic data.
JavaScript
917
star
21

mapbox-navigation-ios

Turn-by-turn navigation logic and UI in Swift on iOS
Swift
861
star
22

earcut.hpp

Fast, header-only polygon triangulation
C
850
star
23

mapbox-gl-draw

Draw tools for mapbox-gl-js
JavaScript
827
star
24

Fingertips

Touch indicators on external displays for iOS applications.
Swift
809
star
25

XcodeClangFormat

Format code in Xcode 8+ with clang-format
Objective-C++
808
star
26

vector-tile-spec

Mapbox Vector Tile specification
805
star
27

pbf

A low-level, lightweight protocol buffers implementation in JavaScript.
JavaScript
746
star
28

mapbox-android-demo

Google Play demo app for the Mapbox Maps SDK for Android
Java
704
star
29

mbutil

Importer and Exporter of MBTiles
Python
694
star
30

osm-bright

A Carto template for OpenStreetMap data
CartoCSS
690
star
31

mapbox-unity-sdk

Mapbox Unity SDK - https://www.mapbox.com/unity/
C#
677
star
32

mapboxgl-jupyter

Use Mapbox GL JS to visualize data in a Python Jupyter notebook
Python
661
star
33

carto

fast CSS-like map stylesheets
JavaScript
653
star
34

mapbox-sdk-js

A JavaScript client to Mapbox services, supporting Node, browsers, and React Native
JavaScript
652
star
35

concaveman

A very fast 2D concave hull algorithm in JavaScript
JavaScript
640
star
36

leaflet-omnivore

universal format parser for Leaflet & Mapbox.js
JavaScript
625
star
37

mapbox-react-examples

Example patterns for building React apps with Mapbox GL JS
JavaScript
615
star
38

martini

A JavaScript library for real-time RTIN terrain mesh generation
JavaScript
609
star
39

polyline

polyline encoding and decoding in javascript
JavaScript
604
star
40

mapbox-navigation-android

Mapbox Navigation SDK for Android
Kotlin
572
star
41

mbtiles-spec

specification documents for the MBTiles tileset format
569
star
42

tiny-sdf

Browser-side SDF font generator
HTML
562
star
43

mapnik-vector-tile

Mapnik implemention of Mapbox Vector Tile specification
C++
546
star
44

mapbox-gl-leaflet

binding from Mapbox GL JS to the Leaflet API
JavaScript
518
star
45

tilelive

fast interface to tiles with pluggable backends - NOT ACTIVELY MAINTAINED
JavaScript
514
star
46

cheap-ruler

Fast approximations for common geodesic measurements 🌐
JavaScript
416
star
47

mapbox-java

The Mapbox Java SDK – Java wrappers around Mapbox APIs and other location data
Java
403
star
48

jni.hpp

A modern, type-safe, header-only, C++14 wrapper for JNI
C++
388
star
49

mercantile

Spherical mercator tile and coordinate utilities
Python
381
star
50

mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
Kotlin
368
star
51

variant

C++11/C++14 Variant
C++
365
star
52

leaflet-image

leaflet maps to images
JavaScript
360
star
53

mapbox-gl-geocoder

Geocoder control for mapbox-gl-js using Mapbox Geocoding API
JavaScript
357
star
54

mbview

View mbtiles locally
EJS
353
star
55

csv2geojson

magically convert csv files to geojson files
JavaScript
353
star
56

mbxmapkit

DEPRECATED - Lightweight Mapbox integration with MapKit on iOS
Objective-C
336
star
57

DEPRECATED-mapbox-ios-sdk

REPLACED – use https://www.mapbox.com/ios-sdk instead
Objective-C
325
star
58

mapbox-sdk-py

Python SDK for Mapbox APIs **DEVELOPMENT IS TEMPORARILY PAUSED, SEE CONTRIBUTING.md**
Python
319
star
59

potpack

A tiny rectangle packing JavaScript library (for sprite layouts)
JavaScript
314
star
60

mapbox-maps-ios

Interactive, thoroughly customizable maps for iOS powered by vector tiles and Metal
Swift
313
star
61

vector-tile-js

Parses vector tiles with JavaScript
JavaScript
308
star
62

node-mbtiles

mbtiles utility, renderer, and storage backend for tilelive
JavaScript
285
star
63

mapbox-maps-flutter

Interactive, thoroughly customizable maps for Flutter powered by Mapbox Maps SDK
Swift
282
star
64

mapbox-ar-unity

DEPRECATED! A place to create/learn with Unity, ARKit/ARCore, and Mapbox!
C#
279
star
65

geo-googledocs

Tools to integrate Mapbox with Google Docs
JavaScript
276
star
66

delatin

A fast JavaScript terrain mesh generation tool based on Delaunay triangulation
JavaScript
273
star
67

hubdb

a github-powered database
JavaScript
272
star
68

flutter-mapbox-gl

Moved to https://github.com/tobrun/flutter-mapbox-gl
Java
271
star
69

mapbox-gl-styles

Prebuilt Mapbox GL styles for use in Mapbox GL JS or the Mapbox Mobile SDKs and as a starting point for custom maps built with Mapbox Studio
JavaScript
268
star
70

simplestyle-spec

A simple styling convention for GeoJSON data
266
star
71

postgis-vt-util

postgres helper functions for making vector tiles
PLpgSQL
265
star
72

gzip-hpp

Gzip header-only C++ library
C++
265
star
73

protozero

Minimalist protocol buffer decoder and encoder in C++
C++
261
star
74

sphericalmercator

Spherical Mercator math in Javascript
JavaScript
259
star
75

shp-write

create and write to shapefiles in pure javascript
JavaScript
254
star
76

geojsonhint

IMPORTANT: development of this project has been paused, see the README (Validate GeoJSON against the specification)
JavaScript
253
star
77

mason

Cross platform package manager for C/C++ apps
Python
252
star
78

wellknown

GeoJSON-emitting WKT parser for browsers and node
JavaScript
249
star
79

Hecate

Fast Geospatial Feature Storage API
Rust
247
star
80

pyskel

Skeleton of a Python package
Python
243
star
81

mapbox-plugins-android

Mapbox Android Plugins are a collection of libraries that extend our other SDKs, helping you design powerful mapping features while the plugins handle most of the heavy lifting.
Java
240
star
82

mapbox-gl-directions

Directions plugin for mapbox-gl-js using Mapbox Directions API.
JavaScript
236
star
83

tilejson-spec

JSON format for describing map tilesets.
234
star
84

mapping

OpenStreetMap contributions from the data team at Mapbox
JavaScript
233
star
85

tilebelt

simple tile utilities
JavaScript
230
star
86

geojson-merge

Merge multiple GeoJSON files into one FeatureCollection.
JavaScript
229
star
87

mapbox-arkit-ios

Utilities for combining Mapbox maps and location services with ARKit in your applications.
Swift
224
star
88

mapbox-scenekit

Swift
224
star
89

react-native-mapbox-ar

Location based augmented reality components using React Native, Viro and Mapbox
Objective-C
221
star
90

mapbox-gl-native-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL
Java
211
star
91

mapbox-gl-native-ios

Interactive, thoroughly customizable maps for iOS powered by vector tiles and OpenGL
Objective-C++
211
star
92

Simple-KML

Simple KML is a simple & lightweight parsing library for KML written in Objective-C for the iOS platform.
Objective-C
208
star
93

turf-swift

A Swift language port of Turf.js.
Swift
205
star
94

react-colorpickr

A themeable colorpicker with HSL and RGB support for React
TypeScript
205
star
95

eternal

A C++14 compile-time/constexpr map and hash map with minimal binary footprint
C++
201
star
96

node-fontnik

Fonts β‡’ protobuf-encoded SDF glyphs
JavaScript
201
star
97

ecs-watchbot

Make robots do your work for you
JavaScript
194
star
98

leaflet-pip

point in polygon intersections for leaflet
JavaScript
194
star
99

tile-cover

Generate the minimum number of tiles to cover a geojson geometry
JavaScript
183
star
100

MapboxStatic.swift

Static map snapshots with overlays in Swift or Objective-C on iOS, macOS, tvOS, and watchOS
Swift
183
star