Effects
The logo at the top of this page is ordinary HTML text, drawn as holographic foil by
HoloEffect
from @vfx-js/effects. Move the pointer over it to tilt the foil.
map.jumpTo() cuts. map.vfxJumpTo() glitches, tiles, smears and
pixel-sorts its way to the next place, with WebGL shader transitions.
npm install maplibre-vfx-jump
This map jumps to a random place with a random transition every few seconds.
Each jump is a single map.vfxJumpTo() call.
await map.vfxJumpTo(camera, { transition });
Install the plugin next to MapLibre GL JS and VFX-JS.
npm install maplibre-vfx-jump maplibre-gl @vfx-js/core
@vfx-js/transitions is optional. It ships the ready-made presets used in the demo
above (Glitch, Tile, PixelScan, Datamosh and more).
npm install @vfx-js/transitions
VfxJumpControl is a regular MapLibre IControl. Adding it gives the map a
vfxJumpTo() method; jumpTo() itself is left untouched.
import * as maplibregl from "maplibre-gl";
import "maplibre-gl/dist/maplibre-gl.css";
import { Glitch, Tile } from "@vfx-js/transitions";
import { VfxJumpControl } from "maplibre-vfx-jump";
const map = new maplibregl.Map({
container: "map",
style: "https://tiles.openfreemap.org/styles/liberty",
center: [141.3545, 43.0621],
zoom: 11.5,
});
// Adds map.vfxJumpTo(). Without `transition`, it defaults to Crossfade.
map.addControl(new VfxJumpControl({ transition: Glitch, duration: 0.8 }));
// Jump with the default transition
await map.vfxJumpTo({ center: [139.7671, 35.6812], zoom: 13 });
// Or pick a transition and its params per call
await map.vfxJumpTo(
{ center: [2.3376, 48.8606], zoom: 13.5 },
{ transition: Tile, params: { shape: "hex", count: 14 }, duration: 1.0 },
);
Since it is an IControl, it is cleaned up by map.removeControl() and
map.remove(), and it fits framework wrappers such as react-map-gl's
useControl().
map.jumpTo() runs underneath while the destination tiles load.
The map canvas is handed to VFX-JS as it is, so nothing in the DOM is wrapped or moved, and
preserveDrawingBuffer: true is not needed.
new VfxJumpControl(options?)| Option | Default | Description |
|---|---|---|
transition | Crossfade | A VFX-JS transition class or instance. null cuts without animating. |
params | โ | Constructor params, when transition is a class. |
duration | 0.8 | Animation length in seconds. 0 cuts immediately. |
ease | "smoothstep" | "smoothstep", "linear", or a function (x) => number. A transition's own ease wins over the default. |
settleTimeout | 2000 | Longest wait, in ms, for the map's "idle" event before the animation starts. |
map.vfxJumpTo(camera, transition?, eventData?)
Takes the same camera options as jumpTo() and returns a promise that resolves when
the transition ends. The second argument overrides transition, params,
duration and ease for that call.
control.running | Whether a transition is holding or playing. |
control.cancel() | Ends the active transition and shows the live map. |
control.vfx | The underlying VFX instance while attached, otherwise null. |
"vfxjumpstart" | Fired on the map with { camera } when a transition starts. |
"vfxjumpend" | Fired on the map with { camera } when it ends: played through, interrupted by another jump, or cancelled. Every "vfxjumpstart" is followed by exactly one. |
With prefers-reduced-motion: reduce, vfxJumpTo() skips the animation
and calls jumpTo() directly.
VFX-JS is a JavaScript library by Amagi that applies WebGL effects to HTML elements: images, videos, canvases, and even plain text.
You point it at an element and it draws the shader result in its place. This page uses it three ways, and maplibre-vfx-jump is a thin layer that connects the second one to MapLibre's camera.
The logo at the top of this page is ordinary HTML text, drawn as holographic foil by
HoloEffect
from @vfx-js/effects. Move the pointer over it to tilt the foil.
@vfx-js/transitions has shader transitions that blend one frame into another.
The demo map plays them between the old and the new camera position.
The CRT glitch that flickers behind this page and across the letters "vfx" now and then
is one small custom effect. A custom VFX-JS Transition works with
vfxJumpTo() as it is.
import { VFX } from "@vfx-js/core";
import { HoloEffect } from "@vfx-js/effects";
const vfx = new VFX();
await vfx.add(document.querySelector("h1"), {
effect: new HoloEffect({ holo: [HoloEffect.looks.card, { material: "prism" }] }),
});