Skip to content

Fly to a location based on scroll position

Replicates the MapLibre example Fly to a location based on scroll position: The Adventure of the Bruce-Partington Plans, told across London. Scroll through the story below. As each chapter reaches the middle of the screen, the map flies to that chapter’s camera.

Loading story...

fly-to-a-location-based-on-scroll-position.yaml
# yaml-language-server: $schema=https://docs.maplibre-yaml.org/schema/latest/scrollytelling.schema.json
# Gallery twin of https://maplibre.org/maplibre-gl-js/docs/examples/fly-to-a-location-based-on-scroll-position/
# A scrollytelling document: each chapter carries its camera, and scrolling
# a chapter into view flies the map there. The upstream page's chapters
# object, scroll listener and flyTo calls are the `chapters:` list; the
# runtime is the Astro <Scrollytelling> component (@maplibre-yaml/astro).
type: scrollytelling
id: fly-to-a-location-based-on-scroll-position
theme: light
config:
center: [-0.15591514, 51.51830379]
zoom: 15.5
bearing: 27
pitch: 45
mapStyle: "https://tiles.openfreemap.org/styles/bright"
interactive: false
chapters:
- id: baker
title: 221b Baker St.
description: >-
<p>November 1895. London is shrouded in fog and Sherlock Holmes and
Watson pass time restlessly awaiting a new case. "The London criminal
is certainly a dull fellow," Sherlock bemoans. "There have been numerous
petty thefts," Watson offers in response. Just then a telegram arrives
from Sherlock's brother Mycroft with a mysterious case.</p>
center: [-0.15591514, 51.51830379]
zoom: 15.5
bearing: 27
pitch: 20
alignment: right
- id: aldgate
title: Aldgate Station
description: >-
<p>Arthur Cadogan West was found dead, head crushed in on train tracks
at Aldgate Station at 6AM Tuesday morning. West worked at Woolwich
Arsenal on the Bruce-Partington submarine, a secret military project.
Plans for the submarine had been stolen and seven of the ten missing
papers were found in West's possession. Mycroft implores Sherlock to
take the case and recover the three missing papers.</p>
center: [-0.07571203, 51.51424049]
zoom: 15
bearing: 150
pitch: 0
# Upstream slows this flight with duration: 6000; chapters set speed.
speed: 0.3
alignment: right
- id: london-bridge
title: London Bridge
description: >-
<p>Holmes and Watson's investigations take them across London. Sherlock
deduces that West was murdered elsewhere, then moved to Aldgate Station
to create the illusion that he was crushed on the tracks by a train. On
their way to Woolwich Sherlock dispatches a telegram to Mycroft at
London Bridge: "Send list of all foreign spies known to be in England,
with full address."</p>
center: [-0.08533793, 51.50438536]
zoom: 13
bearing: 90
pitch: 40
speed: 0.6
alignment: right
- id: woolwich
title: Woolwich Arsenal
description: >-
<p>While investigating at Woolwich Arsenal Sherlock learns that West did
not have the three keys&mdash;door, office, and safe&mdash;necessary to
steal the papers. The train station clerk mentions seeing an agitated
West boarding the 8:15 train to London Bridge. Sherlock suspects West of
following someone who had access to the Woolwich chief's keyring with
all three keys.</p>
center: [0.05991101, 51.48752939]
zoom: 12.3
bearing: 90
alignment: right
- id: gloucester
title: Gloucester Road
description: >-
<p>Mycroft responds to Sherlock's telegram and mentions several spies.
Hugo Oberstein of 13 Caulfield Gardens catches Sherlock's eye. He heads
to the nearby Gloucester Road station to investigate and learns that the
windows of Caulfield Gardens open over rail tracks where trains stop
frequently.</p>
center: [-0.18335806, 51.49439521]
zoom: 15.3
bearing: 45
pitch: 20
speed: 0.5
alignment: right
- id: caulfield-gardens
title: 13 Caulfield Gardens
description: >-
<p>Holmes deduces that the murderer placed West atop a stopped train at
Caulfield Gardens. The train traveled to Aldgate Station before West's
body finally toppled off. Backtracking to the criminal's apartment,
Holmes finds a series of classified ads from <em>The Daily
Telegraph</em> stashed away. All are under the name Pierrot: "Monday
night after nine. Two taps. Only ourselves. Do not be so suspicious.
Payment in hard cash when goods delivered."</p>
center: [-0.19684993, 51.5033856]
zoom: 12.3
bearing: 180
alignment: right
- id: telegraph
title: The Daily Telegraph
description: >-
<p>Holmes and Watson head to The Daily Telegraph and place an ad to draw
out the criminal. It reads: "To-night. Same hour. Same place. Two taps.
Most vitally important. Your own safety at stake. Pierrot." The trap
works and Holmes catches the criminal: Colonel Valentine Walter, the
brother of Woolwich Arsenal's chief. He confesses to working for Hugo
Oberstein to obtain the submarine plans in order to pay off his
debts.</p>
center: [-0.10669358, 51.51433123]
zoom: 17.3
bearing: 90
pitch: 40
alignment: right
- id: charing-cross
title: Charing Cross Hotel
description: >-
<p>Walter writes to Oberstein and convinces him to meet in the smoking
room of the Charing Cross Hotel where he promises additional plans for
the submarine in exchange for money. The plan works and Holmes and
Watson catch both criminals.</p>
<p><small>Adapted from <a href="https://www.gutenberg.org/files/2346/2346-h/2346-h.htm">Project
Gutenberg</a>.</small></p>
center: [-0.12416858, 51.50779757]
zoom: 14.3
bearing: 90
pitch: 20
alignment: right
  • This is a type: scrollytelling document. Upstream builds a chapters object in JS, listens for scroll events and calls flyTo. Here each chapter carries its own center, zoom, bearing, pitch and speed, and the runtime does the rest.
  • The runtime is the <Scrollytelling> component from @maplibre-yaml/astro. This page passes it the same YAML file shown above, with src=.
  • Upstream slows the Aldgate flight with duration: 6000. Chapters have no duration, so that chapter uses a lower speed instead.
  • Chapters can also show and hide layers and run actions on enter and exit. See the scrollytelling schema.