Skip to Content
APIUtilsVariable: maplibregl

Variable: maplibregl

const maplibregl: typeof maplibreGL = maplibreGL

The MapLibre GL JS build the SDK itself runs on, for the MapLibre classes the SDK does not wrap — a draggable Marker, a Popup, LngLatBounds, … — on a map the SDK created.

Use this instead of loading MapLibre separately. On the script-tag (UMD) build it is the only way to reach MapLibre at all: MapLibre v6 ships as ES modules only, so it defines no window.maplibregl, and a second copy would download about 1 MB again and could drift from the version the map runs on. Objects from it attach to MapVXMap.map, the MapLibre Map the SDK created.

Examples

Attaching a draggable marker to a map the SDK created

import { maplibregl } from "@mapvx/web-js" // Script tag: const { maplibregl } = window.MapVX const pin = new maplibregl.Marker({ draggable: true }) .setLngLat([-70.6066, -33.4177]) .setPopup(new maplibregl.Popup().setText("Drag me")) .addTo(mapVXMap.map) pin.on("dragend", () => console.log(pin.getLngLat()))

Building a standalone MapLibre map, with no SDK map on the page

import { installMapLibreWorker, maplibregl } from "@mapvx/web-js" // The SDK installs MapLibre's worker when it creates its first map. Without that call the // worker URL is unresolvable and the map renders nothing, silently: MapLibre emits no error. installMapLibreWorker() const map = new maplibregl.Map({ container: "map", style })
Last updated on