Map
API reference for the Map class in 3DMapFi.
The Map
class is the core component for rendering and interacting with maps in 3DMapFi. It provides methods for controlling the map view, managing layers and sources, handling user interaction, and integrating with other 3DMapFi features.
Initialization
Create a new map instance by specifying options such as container, style, center, zoom, and projection.
Methods
setStyle
Set the map’s style at runtime. Accepts a style URL or style object.
- Parameters:
style
(string|object) - Returns:
void
- Events: Triggers
style.load
event.
setProjection
Change the map projection.
- Parameters:
projection
(string|object) - Returns:
void
- Events: Triggers
projectionchange
event.
setAtmosphere
Configure atmospheric effects such as fog, sky color, and sunlight.
- Parameters:
options
(object) - Returns:
void
setTerrain
Enable and configure 3D terrain.
- Parameters:
options
(object) - Returns:
void
addLayer
Add a new layer to the map. Layers control how data is rendered.
- Parameters:
layer
(object),beforeId
(string, optional) - Returns:
void
removeLayer
Remove a layer by its ID.
- Parameters:
layerId
(string) - Returns:
void
addSource
Add a data source (GeoJSON, vector, raster, etc.).
- Parameters:
id
(string),source
(object) - Returns:
void
removeSource
Remove a source by its ID.
- Parameters:
id
(string) - Returns:
void
addControl
Add a control (e.g., navigation, fullscreen, custom).
- Parameters:
control
(object),position
(string, optional) - Returns:
void
on
Listen for map or layer events.
- Parameters:
event
(string),layerId
(string, optional),handler
(function) - Returns:
void
off
Remove an event listener.
- Parameters:
event
(string),handler
(function) - Returns:
void
getCenter / setCenter
Get or set the map center.
getZoom / setZoom
Get or set the zoom level.
getBearing / setBearing
Get or set the map bearing (rotation).
getPitch / setPitch
Get or set the map pitch (tilt).
resize
Resize the map when the container size changes.
flyTo
Animate the map to a new location.
fitBounds
Fit the map view to given bounds.
Properties
container
: The DOM element for rendering the map.style
: The current map style.center
: The current center coordinates.zoom
: The current zoom level.bearing
: The current rotation.pitch
: The current tilt.projection
: The current projection.loaded
: Boolean indicating if the map is fully loaded.
Events
See Event API for a full list of supported events.