API: Methods and Events

Static methods live on the ApexMaps class itself. Everything else is called on an instance created with new ApexMaps(element, options), and most of it is only meaningful after render() resolves.

Statics

StaticDescription
ApexMaps.setLicense(key)Registers the license key shared across the whole ApexCharts family. Call once, before any map renders.
ApexMaps.registerMap(id, geometry, meta?)Registers a geometry pack, or a loader function returning one, under id. meta carries source, license, vintage, and the recommended join key.
ApexMaps.registerProjection(name, factory)Registers a d3-geo-style projection factory under name. Registering is free; drawing a map that uses a registered projection is a licensed capability. See Projections.
ApexMaps.registerPalette(name, palette)Registers a custom color ramp, { kind, stops, colorblindSafe? }, under name for scale.palette.
ApexMaps.listMaps()Every registered map id, built-in and custom.
ApexMaps.listProjections()Every registered projection name, built-in and custom.
ApexMaps.listPalettes()Every registered palette name, built-in and custom.
ApexMaps.palette(name)A palette's anchor stops and family: { kind, stops, colorblindSafe }.
ApexMaps.mapMeta(id)Provenance for a registered map: source, license, vintage, boundary policy, recommended join key.
ApexMaps.catalogue()The built-in geometry catalogue with full provenance, for a picker UI or a docs table. Excludes anything added by hand with registerMap().

Instance methods

Lifecycle and options

MethodReturnsDescription
render()Promise<this>Builds and draws the map. Call once, after construction.
updateOptions(options, flags?)Promise<this>Merges new options into the current config and redraws. flags.redrawGeometry forces reprojection; a map or projection change infers it automatically.
updateSeries(series)thisReplaces series data and tweens fills and radii instead of rebuilding the DOM.
destroy()voidTears down listeners, observers, animation frames, and DOM. The instance is not reusable afterward.

Selection

MethodReturnsDescription
setSelection(keys)thisReplaces the selection set.
toggleSelection(key)thisAdds or removes one key.
clearSelection()thisEmpties the selection.

Drilldown

MethodReturnsDescription
drillTo(key)Promise<boolean>Drills into a feature by key, exactly as a click on it would. Resolves false when the drilldown is declined: no such feature, no drilldown configured, or no child feature belongs to the parent.
drillUp(levels?)Promise<boolean>Climbs back out. Pass Infinity to return to the top level.
drillDepthnumberRead-only property: how many levels below the top are currently displayed.

Camera

Reach the camera through map.camera, available once the map has rendered.

MethodReturnsDescription
map.camera.jumpTo(target)voidApplies a camera state with no animation.
map.camera.easeTo(target)Promise<void>Animates with a fixed duration and easing. Use for short, mechanical moves.
map.camera.flyTo(target)Promise<void>Animates along a Van Wijk zoom-and-pan path. Use for narrative moves; duration derives from distance unless overridden.
map.camera.fitBounds(bounds, options?)Promise<void>Frames a world-space bounding box.
map.camera.panBy(dx, dy)voidPans by a screen-space delta.
map.camera.stop()voidStops any in-flight move where it is. Every new move calls this first, so moves retarget instead of queueing.
frameFeature(key, options?)Promise<void>Frames one feature by key, turning the globe first on a rotatable projection so a feature on the far side can be framed at all.
resetView(options?)Promise<void>Resets the camera to the initial fit, and the initial rotation on a globe.
zoomIn() / zoomOut()voidZooms one step (the interaction.zoom.step the + / - controls use), eased about the plot center.
rotateTo(angles)voidTurns a rotatable projection to an absolute [lambda, phi, gamma?], as a drag would. No-op on a projection that cannot rotate.

target accepts center, zoom, bounds, padding, maxZoom, or raw k / x / y. flyTo and easeTo also take duration and ease; flyTo additionally takes speed and curve. On the azimuthal family a center target is resolved as a rotation (quaternion slerp), not a screen-space pan, so flyTo can reach the far side of a globe. Two read-only properties report the current view: map.zoom (camera scale, 1 at the opening fit) and map.rotation ([lambda, phi, gamma], [0, 0, 0] on a projection that cannot rotate).

Export

MethodReturnsDescription
exportSVG(options?)voidDownloads the current view as a standalone .svg file.
exportPNG(options?)Promise<void>Rasterizes the current view and downloads it as a .png.
getSvgString(options?)stringReturns the exported SVG markup as a string, with no download.
dataURI(options?)Promise<{ imgURI: string }>Returns the current view as a PNG data URI, for embedding rather than downloading.

options accepts background, scale (PNG pixel-density multiplier, default 2), and filename. See Export.

Diagnostics and serialization

MethodReturnsDescription
diagnoseJoin(seriesIndex?)JoinResult | nullThe programmatic form of the console join diagnostic: matched and unmatched counts, suggestions for near-misses, and which keys map to more than one feature.
toSpec()ApexMapsOptionsSerializes the effective, resolved options tree. JSON-serializable.

Event subscription

MethodReturnsDescription
on(event, handler)thisSubscribes to one of the events below.
off(event, handler?)thisUnsubscribes one handler, or every handler for the event when handler is omitted.
emit(event, payload?)voidEmits an event manually. Mostly useful in tests.

Events

Most events carry a FeatureEventPayload: { key, name?, value, datum, properties?, seriesName?, seriesIndex, instance }. instance is the ApexMaps instance in every payload that has one.

EventPayloadFires when
rendered{ instance }The first render() finishes.
updated{ instance }updateOptions() or updateSeries() finishes applying a change.
resized{ width, height }The container resizes and the map redraws to fit.
featureClickFeatureEventPayloadA geometry feature (choropleth or the automatic basemap) is clicked or activated with Enter. Fires before a resulting drilldown.
featureHoverFeatureEventPayloadHover enters a geometry feature.
featureFocusFeatureEventPayloadKeyboard roving-tabindex focus moves to a feature.
markClickFeatureEventPayloadA point or path mark (bubble, marker, arc, or line item) is clicked.
markHoverFeatureEventPayloadHover enters a point or path mark.
clusterClickFeatureEventPayloadA marker cluster is clicked, before the camera flies to its members.
drilldown{ key, name?, from?, to?, depth, featureCount, instance }A deeper level is on screen, after it renders.
drillup{ to?, depth, instance }Climbing back out finishes.
selectionChange{ ids, source }The selection changes: a click, a box, setSelection() / clearSelection(), or a linked map broadcasting.
legendToggle{ classIndex, instance }A legend class is clicked to mute or unmute it.
zoom{ k }The camera scale changes.
rotate{ rotate: [lambda, phi, gamma] }The globe's rotation changes, during a drag or a rotation-aware camera move.
rotateEnd{ rotate: [lambda, phi, gamma] }A globe rotation gesture or move settles.
panEndundefinedA pan gesture ends.
map.on('featureClick', ({ key, value, datum }) => {
  console.log(key, value, datum)
})

map.on('drilldown', ({ key, depth, featureCount }) => {
  fetchCounties(key).then((rows) => map.updateSeries([{ ...series, data: rows }]))
})