map options
Add an event listener overriding the original
type of event called
event listener
Optional
options: boolean | AddEventListenerOptionsevent listener options
Add a new style layer to the map
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ... };
const map = new S2Map(options);
// Add a new style layer to the map
map.addLayer({ source: 'world', type: 'fill', color: 'red', ... });
The style layer to add
Optional
nameIndex: string | numberThe index to add the layer at
Add new marker(s) to the map
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ... };
const map = new S2Map(options);
// add a new marker
map.addMarker({ id: 22, lat: 0, lon: 0, html: '<div>hello</div>' });
A single marker or an array of markers
The name of the source to add the marker(s) to. [Default: "_markers"
]
Add a new source to the map. Sources are references to data and how to fetch it.
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ... };
const map = new S2Map(options);
// Add a new source to the map
map.addSource('TheFreakinMoon', 'http://yup-im-the-moon.com/');
Name of the source
the location of the source data
Async function to wait for the map to have all source and layer data rendered to the screen
Useful for ensuring the map is rendered before running tests, starting an animation, making changes, etc.
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ... };
const map = new S2Map(options);
// wait for the map to be full rendered before making future changes
await map.awaitFullyRendered();
// do more stuff
Delete the map instance and cleanup all it's resources
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ... }
const map = new S2Map(options)
// do something with the map
map.delete() // cleanup
Delete an existing style layer in a map given the layer's name or index
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ... };
const map = new S2Map(options);
// Delete an existing layer
map.updateLayer(12);
The index/name of the style layer to delete
Delete a source's data from the map
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ... };
const map = new S2Map(options);
// Add a new source to the map
map.addSource('TheFreakinMoon', 'http://yup-im-the-moon.com/');
// Do stuff ...
// we are done rendering the moon
map.deleteSource(['TheFreakinMoon', 'anotherSourceWeDontWantAnymore']);
A single sourceName or an array of source names
Use an easing function to travel to a specific location's longitude, latitude, and optionally zoom
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ..., view: { lon: 0, lat: 0, zoom: 0 } };
const map = new S2Map(options);
// wait for map to load, then jump to a specific location
await map.awaitFullLoaded();
map.easeTo(-120, 60, 7);
Optional
directions: AnimationDirectionsanimation guide for travel directions, speed, and easing
Use an easing function to fly to a specific location's longitude, latitude, and optionally zoom
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ..., view: { lon: 0, lat: 0, zoom: 0 } };
const map = new S2Map(options);
// wait for map to load, then jump to a specific location
await map.awaitFullLoaded();
map.flyTo(-120, 60, 7);
Optional
directions: AnimationDirectionsanimation guide for travel directions, speed, and easing
Get the dimensions of the map's container
The dimensions of the map's container
Get the current projector's view of the world
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions, View } from 's2maps-gpu';
const options: MapOptions = { ..., view: { lon: 0, lat: 0, zoom: 0 } };
const map = new S2Map(options);
// Get a filled in view object
const view: Required<View> = await map.getView();
A filled in View object
Jump to a specific location's longitude, latitude, and optionally zoom, bearing, and pitch. Takes a View object as an input.
NOTE: If either the lon
or lat
are not set, it will assume the map's current position
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ..., view: { lon: 0, lat: 0, zoom: 0 } };
const map = new S2Map(options);
// wait for map to load, then jump to a specific location
await map.awaitFullLoaded();
map.jumpTo({ lon: -120, lat: 60, zoom: 7 });
The view to jump to
Delete a marker or collection of markers from the map
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ... };
const map = new S2Map(options);
// add a new marker
map.removeMarker(22);
A single marker id or an array of marker ids to delete
The name of the source to remove the marker(s) from. [Default: "_markers"
]
Reorder layers in the map.
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ... };
const map = new S2Map(options);
// Reorder layers
map.reorderLayers({ 0: 1, 1: 0 });
The guide of how to reorder the layers
Reset a source's data already added to the map and control the method the map updates the source
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ... };
const map = new S2Map(options);
// Add a new source to the map
map.addSource('TheFreakinMoon', 'http://yup-im-the-moon.com/');
// change the location of the moon
map.resetSource(['TheFreakinMoon'], false, true);
Array of [sourceName, href]. Href is optional but if provided, the source href will be updated
Whether to keep the cache or not. don't delete any tiles, request replacements for all (for s2json since it's locally cached and fast)
Whether to await the replacement of tiles or not. to avoid flickering (i.e. adding/removing markers), we can wait for an update (from source+tile workers) on how the tile should look
Take a screenshot of the current state of the map. Returns the screenshot as an Uint8ClampedArray
.
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ... };
const map = new S2Map(options);
// wait for the map to be full rendered
await map.awaitFullyRendered();
// request the current screen
const screen = await map.screenshot();
An RGBA encoded Uint8ClampedArray
that is of size canvas.width
* canvas.height
Update the state of the map's UI mode.
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ..., darkMode: false };
const map = new S2Map(options);
// do something with the map
map.setDarkMode(true);
which UI mode to set the map to. true
for dark-mode, false
for light-mode
Update the users ability to move the map around or not.
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ..., canMove: false };
const map = new S2Map(options);
// Update the move state so the user can move around
const screen = map.setMoveState(true);
Sets the move state. If true
, the user can move the map.
Set a new style, replacing the current one if it exists
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions, StyleDefinition } from 's2maps-gpu';
const options: MapOptions = { ... };
const map = new S2Map(options);
// setup and set a new style
const style: StyleDefinition = { ... };
await map.setStyle(style);
The user defined style of how data should be rendered
if set to true, don't update the map's position to the style's view guide [Default=true
]
Update the users ability to zoom the map in and out or not.
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ..., canZoom: false };
const map = new S2Map(options);
// Update the zoom state so the user can update the zoom position
const screen = map.setZoomState(true);
Sets the zoom state. If true
, the user can zoom the map in and out.
Update the an existing style layer in a map given the layer's name or index
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ... };
const map = new S2Map(options);
// Update the style layer
map.updateLayer({ source: 'world', type: 'fill', color: 'red', ... }, 12);
The style layer to update/replace the old layer with
The index/name of the style layer to update
If true, force a full re-render of the layer. Recommended to keep true unless you know what you're doing
Update a source already added to the map and control the method the map updates the source
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions } from 's2maps-gpu';
const options: MapOptions = { ... };
const map = new S2Map(options);
// Add a new source to the map
map.addSource('TheFreakinMoon', 'http://yup-im-the-moon.com/');
// change the location of the moon
map.updateSource('TheFreakinMoon', 'http://now-im-the-moon.com/', false, true);
Name of the source
the new location of the source
Whether to keep the cache or not. don't delete any tiles, request replacements for all (for s2json since it's locally cached and fast)
Whether to await the replacement of tiles or not. to avoid flickering (i.e. adding/removing markers), we can wait for an update (from source+tile workers) on how the tile should look
Update the map's current style with new attributes, by checking for changes and updating accordingly
import { S2Map } from 's2maps-gpu'; // or you can access it via the global `window.S2Map`
import type { MapOptions, StyleDefinition } from 's2maps-gpu';
const options: MapOptions = { ..., style: { ... } };
const map = new S2Map(options);
// Update the style with new attributes
const newStyle: StyleDefinition = { ... };
map.updateStyle(newStyle);
The new style to update the old style with
The S2 Map GPU Engine 🌎 🗺️
Description
Both an S2 and WM Projection Map Engine Powered by
WebGL1
,WebGL2
, andWebGPU
.Basic JS/TS example:
Note that the most important components to build a map are the MapOptions and the StyleDefinition.
HTML Example
Events
ready
: fired when the map is ready to be interacted with / make API calls. Ships this map S2Mapmouseleave
: fired when the mouse leaves the map. Ships MouseLeaveMessagemouseenter
: fired when the mouse enters the map. Ships MouseEnterMessageclick
: fired when the user clicks on the map. Ships MouseClickMessageview
: fired when the map view changes. Ships ViewMessagescreenshot
: fired as a result of a screenshot that was requested. Ships aUint8ClampedArray
rendered
: fired when the map is fully rendered.delete
: fired to ping that the map is deleting itself.API
[width, height]
tupleUint8ClampedArray
Future API
getBounds
&setBounds
setProjection
&getProjection
getStyle
Converters
Plugins
Frameworks