maplibre_native_ffi library

Low-level Dart bindings for the MapLibre Native C API.

Dart can resume an isolate on another native thread after any await, so an isolate cannot own a caller-driven render session. Render through core-worker sessions: Metal, Vulkan, or an EGL context that the session creates for itself. That EGL context shares nothing with the host, so it renders to a surface or offers its texture as readback. On Windows, render through Vulkan.

Native code never waits on a Dart callback. Resource providers, the log callback, and cancel callbacks run on the registering isolate after native code has moved on, and an exception that one throws goes to the registering zone's error handler.

Native code in the host, such as a Flutter plugin's platform code, can supply a registration's function pointers, context, and release through the native constructors. Wake.native wakes the host's native code without a post to the isolate. QueueLock.native is the only form of a queue lock, because native code relies on the lock being held when its callback returns. The first call that carries a native registration consumes it, and a second call throws MaplibreException with Status.invalidState. Native code releases the context of a call that it accepts, and the binding calls the release for a call that native code does not accept.

A JSON value, typed Object?, is any value that jsonEncode takes, so setStyleLayerProperty('roads', 'line-color', 'red') needs no inner quotes. A JSON parameter is always a value: null is JSON null, such as the null that restores a layer property's default. In a record member, null is absent, which native code reads as empty, as for a filter, an expression input, or cluster properties, where JSON null means nothing. A value that jsonEncode rejects throws its error before the call reaches native code. Returned JSON is the value that jsonDecode reads, and absent JSON is null, as JSON null is. A value compares its JSON members by content.

On Android, call initAndroid before you create a runtime, with the calling thread's JNIEnv* and an Android Context, which package:jni and package:jni_flutter can provide.

A pending completion keeps its isolate alive, and a callback registration does not. To wait for a callback, keep the isolate alive yourself, for example with a ReceivePort that you close once the callback runs.

Classes

AcquiredFrameHandle
Owner of one native handle.
AnchoredMomentum
How a gesture's zoom, bearing, or pitch keeps changing after release.
AndroidHardwareBufferFrame
The Android hardware buffer of an acquired frame.
AndroidHardwareBufferRingDescriptor
A ring of Android hardware buffers that the library allocates, for MapHandle.attachAndroidHardwareBufferRing().
AndroidSurfaceDescriptor
An Android window to present to, for MapHandle.attachAndroidSurface().
AndroidSurfaceReplacement
A new Android window for RenderSessionHandle.setAndroidSurfaceTarget().
AnimationOptions
How a camera change animates.
BoundOptions
Limits on the camera, for MapHandle.setBounds().
CacheDatabaseOperation
A maintenance action on a runtime's cache database.
Camera
A map's whole camera.
CameraBounds
All the limits on a map's camera.
CameraChangeMode
Whether a camera change jumps or animates.
CameraChangeSource
What moved the camera.
CameraDelta
A change to the camera from where it is now, for gestures.
CameraFitOptions
Options for finding the camera that fits an area.
CameraFitUpdate
A camera change that fits an area, for MapHandle.fitCameraToLatLngBounds() and the other fit commands.
CameraOptions
A camera, with only the members that fields selects.
CameraQueryResult
A map's camera, with the snapshot generation that it matches.
CameraTransitionEnd
The end of a camera change.
CameraTransitionHandler
A callback for the end of a camera change, for AnimationOptions.
CameraTransitionOutcome
How a camera change ended.
CameraUpdate
A camera change for MapHandle.updateCamera().
CameraUpdateMode
How a camera command moves the camera.
CameraVelocity
How fast each part of a camera change moves.
CanonicalTileId
A tile's zoom level z, column x, and row y, with row 0 at the north.
CommandCompletion
The generations that a committed command published. A command's future fails with MaplibreException instead when native reports it failed or cancelled.
ConstrainMode
How the map keeps the camera within the world or within its bounds.
CustomGeometrySourceOptions
The callbacks and options of a custom geometry source.
CustomVectorSourceOptions
The callbacks and options of a custom vector source.
DmaBufFormat
A DRM format and modifier that you can import.
DmaBufFrame
The dmabuf of an acquired frame.
DmaBufPlane
Where one plane of a dmabuf keeps its data.
DmaBufRingDescriptor
A ring of dmabufs that the library allocates, for MapHandle.attachDmaBufRing().
DxgiSharedTextureFrame
The DXGI shared texture of an acquired frame.
DxgiSharedTextureRingDescriptor
A ring of DXGI shared textures that the library allocates, for MapHandle.attachDxgiSharedTextureRing().
EdgeInsets
Distances in logical pixels from each edge of the map.
EglContextDescriptor
The EGL objects that a render session makes its OpenGL context from.
FeatureId
The ID of a feature in a source, as the source's data gives it.
FeatureIdDoubleValue
FeatureIdIntValue
FeatureIdStringValue
FeatureIdUintValue
FeatureStateSelector
The features whose state to set, read, or remove.
FrameDemand
A demand for one frame.
FrameDemandFlag
How a frame demand behaves.
FramePacerHandle
Owner of one native handle.
FramePacerOptions
Options for creating a frame pacer.
FreeCamera
A map camera's whole position and orientation in three dimensions.
FreeCameraOptions
The camera's position and orientation in three dimensions.
GeoJsonSourceOptions
Options for a GeoJSON [source](https://maplibre.org/maplibre-style-spec/sources/#geojson).
GestureMomentum
How a gesture keeps moving the camera after the user lets go.
GesturePhase
Where a camera change falls in a gesture that the user makes.
GpuSync
A point in GPU work that the other side waits for before using a texture.
GpuSyncKind
How one side waits for the other's GPU work on a shared texture.
GpuSyncKindFlag
A GPU sync kind, as a bit in a set.
HttpHeader
An HTTP header.
HttpHeaderRule
Headers to add to the HTTP requests whose URL matches a pattern.
HttpHeaderTransform
Headers to add to HTTP requests, for RuntimeHandle.setHttpHeaderTransform().
ImageContent
The area of an image, in image pixels, that text fits inside.
ImageStretch
A range of image pixels, from from to to, that stretches to fit text.
IoSurfaceFrame
The IOSurface of an acquired frame.
IoSurfaceRingDescriptor
A ring of IOSurfaces that the library allocates, for MapHandle.attachIoSurfaceRing().
LatLng
A geographic coordinate, in degrees.
LatLngBounds
A rectangle of coordinates, from its southwest to its northeast corner.
LogEvent
The part of the library that logged a message.
LogHandler
A log callback, for setLogCallback().
LogicalExtent
A size in logical pixels, and the physical pixels in each logical pixel.
LogicalSize
A size in logical pixels, which the map's scale factor turns into pixels.
LogSeverity
The severity of a log message.
LogSeverityFlag
A log severity, as a bit in a set.
MapDebugFlag
A debug overlay that the map draws.
MapHandle
Owner of one native handle.
MapLoadError
Why a map failed to load a style.
MapMode
When a map renders.
MapOptions
Options for RuntimeHandle.createMap().
MapProjectionCameraResult
A projection's camera, as MapProjectionHandle.getCamera() reports it.
MapProjectionHandle
Owner of one native handle.
MapSnapshot
A map's state, as MapHandle.getSnapshot() reads it.
MapTileOptions
How the map picks the tiles to load.
MapTileSettings
All the settings for how a map picks the tiles to load.
MapView
One view of a map: its camera, size, and projection.
MapViewport
A map's whole viewport.
MapViewportOptions
How the map orients and constrains its view.
MetalBorrowedTexture
A Metal texture of a borrowed ring.
MetalBorrowedTextureDescriptor
A ring of your Metal textures, for MapHandle.attachMetalBorrowedTexture().
MetalBorrowedTextureReplacement
New Metal textures for a borrowed ring, for RenderSessionHandle.setMetalBorrowedTextureTarget().
MetalContextDescriptor
The Metal device that a render session uses.
MetalSurfaceDescriptor
A Metal layer to render to, for MapHandle.attachMetalSurface().
MetalSurfaceReplacement
A new Metal layer for RenderSessionHandle.setMetalSurfaceTarget().
MetalTextureFrame
The Metal texture of an acquired frame.
MomentumDecay
How one part of a gesture's momentum slows from its release speed.
MomentumDecayModel
How a part of a gesture's momentum slows from its release speed.
MomentumSnap
Where a part settles after a gesture that changed it.
NativePointer
Opaque borrowed native address value used for backend interop handles.
NetworkStatus
Whether the library may use the network.
NorthOrientation
The screen direction that north points to when the bearing is 0.
OfflineGeometryRegionDefinition
An offline region that covers a GeoJSON geometry.
OfflineRegionDefinition
The area, zoom range, and style that an offline region covers.
OfflineRegionDefinitionGeometry
OfflineRegionDefinitionTilePyramid
OfflineRegionDefinitionUnknown
OfflineRegionDownloadState
Whether an offline region is downloading.
OfflineRegionInfo
An offline region in the runtime's cache file.
OfflineRegionStatus
The download progress of an offline region.
OfflineTilePyramidRegionDefinition
An offline region that covers a rectangle of the map.
OffscreenDescriptor
The image that MapHandle.attachOffscreen() renders. The session renders it at the map's scale factor.
OffscreenDeviceHandle
Owner of one native handle.
OffscreenDeviceOptions
Options for OffscreenDeviceHandle.create().
OpenGlBorrowedTexture
An OpenGL texture of a borrowed ring.
OpenGlBorrowedTextureDescriptor
A ring of your OpenGL textures, for MapHandle.attachOpenGlBorrowedTexture().
OpenGlBorrowedTextureReplacement
New OpenGL textures for a borrowed ring, for RenderSessionHandle.setOpenGlBorrowedTextureTarget().
OpenGlClientApi
The OpenGL API that a context renders with.
OpenGlContextDescriptor
How a render session gets the OpenGL context that it renders with.
OpenGlContextDescriptorData
OpenGlContextDescriptorDataEgl
OpenGlContextDescriptorDataWebGl
OpenGlContextDescriptorDataWgl
OpenGlContextOwnership
Whether a render session's OpenGL context shares objects with yours.
OpenGlContextProviderFlag
An OpenGL context platform, as a bit in a set.
OpenGlSurfaceDescriptor
An OpenGL surface to present to, for MapHandle.attachOpenGlSurface().
OpenGlSurfaceReplacement
A new OpenGL surface for RenderSessionHandle.setOpenGlSurfaceTarget().
OpenGlTextureFrame
The OpenGL texture of an acquired frame.
PanMomentum
How a gesture's pan keeps moving the map's content after release.
PremultipliedRgba8Image
An image of 8-bit RGBA pixels whose colors are multiplied by their alpha.
ProjectedMeters
A point in the Web Mercator projection, in meters.
ProjectionMode
A map's whole projection mode.
ProjectionModeOptions
Settings that skew the map or draw it without perspective.
Quaternion
A rotation, as a quaternion.
QueueLock
Your lock on a Vulkan queue that you and a render session both submit to.
RenderAbandonDisposition
What RenderSessionHandle.abandon() did with a session's graphics objects.
RenderAbandonResult
The outcome of RenderSessionHandle.abandon().
RenderBackendFlag
A render backend, as a bit in a set.
RenderDriverKind
The thread that runs a render session's graphics work.
RenderedFeature
A feature that a rendered feature query found.
RenderedFeatureQueryOptions
Options for a rendered feature query.
RenderedQueryGeometry
The screen area that a rendered feature query covers.
RenderedQueryGeometryBox
RenderedQueryGeometryLineString
RenderedQueryGeometryPoint
RenderFrameResult
How one frame demand finished.
RenderingStats
Statistics about the frames that a map renders.
RenderMode
Whether a frame drew the map complete, or lacked resources that are still loading.
RenderResult
How a frame demand finished.
RenderSessionAttachOptions
Options for attaching a render session to a map.
RenderSessionCapabilities
What an attached render session supports.
RenderSessionCapabilityFlag
Something that a render session can do.
RenderSessionHandle
Owner of one native handle.
RenderSessionSnapshot
The state of a render session at one moment.
RenderSessionState
Where a render session is in its life.
ResourceErrorReason
Why a resource request failed.
ResourceKind
The kind of a resource that the library loads.
ResourceKindFlag
A resource kind, as a bit in a set.
ResourceLoadingMethod
Where a request may load its resource from.
ResourcePriority
The priority of a resource request.
ResourceProvider
A resource provider, for RuntimeHandle.setResourceProvider().
ResourceRange
The bytes from start to end of a resource, both included.
ResourceRequestCancelHandler
A cancel callback, for ResourceRequestHandle.setCancelCallback().
ResourceRequestHandle
Owner of one native handle.
ResourceRequestInfo
A request that a resource provider serves.
ResourceResponse
The answer to a resource request.
ResourceResponseStatus
The outcome of a resource request.
ResourceRoute
The requests that a resource provider serves.
ResourceStoragePolicy
Whether the library keeps a loaded resource in its cache.
ResourceTransform
How to rewrite request URLs, for RuntimeHandle.setResourceTransform().
ResourceTransformError
Why a resource transform fails a request.
ResourceTransformRequestHandle
Owner of one native handle.
ResourceTransformRule
Query parameters to add to the URLs of requests that match a pattern.
ResourceUsage
Whether a request loads a resource for a map or an offline region.
RuntimeEvent
An event that a runtime or one of its maps raised.
RuntimeEventCameraChange
The details of RuntimeEventType.mapCameraWillChange and RuntimeEventType.mapCameraDidChange.
RuntimeEventFlag
An event type, as a bit in a set.
RuntimeEventGlyphs
The details of a glyph event.
RuntimeEventHandler
An event callback, for RuntimeHandle.setEventHandler().
RuntimeEventLoadingFailed
The details of RuntimeEventType.mapLoadingFailed.
RuntimeEventOfflineRegionResponseError
The details of RuntimeEventType.offlineRegionResponseError.
RuntimeEventOfflineRegionStatus
The details of RuntimeEventType.offlineRegionStatusChanged.
RuntimeEventOfflineRegionTileCountLimit
The details of RuntimeEventType.offlineRegionTileCountLimitExceeded.
RuntimeEventPayload
RuntimeEventPayloadCameraChange
RuntimeEventPayloadGlyphs
RuntimeEventPayloadLoadingFailed
RuntimeEventPayloadNone
RuntimeEventPayloadOfflineRegionResponseError
RuntimeEventPayloadOfflineRegionStatus
RuntimeEventPayloadOfflineRegionTileCountLimit
RuntimeEventPayloadRenderFrame
RuntimeEventPayloadSourceChanged
RuntimeEventPayloadSprite
RuntimeEventPayloadStyleImage
RuntimeEventPayloadTileAction
RuntimeEventPayloadUnknown
RuntimeEventRenderFrame
The details of RuntimeEventType.mapRenderFrameFinished.
RuntimeEventSourceChanged
The details of RuntimeEventType.mapSourceChanged.
RuntimeEventSourceType
The kind of handle that raised an event.
RuntimeEventSprite
The details of a sprite event.
RuntimeEventStyleImage
The details of RuntimeEventType.mapStyleImageMissing.
RuntimeEventTileAction
The details of RuntimeEventType.mapTileAction.
RuntimeEventType
The kind of an event.
RuntimeHandle
Owner of one native handle.
RuntimeOptions
Options for RuntimeHandle.create().
ScopedAndroidHardwareBufferFrame
A AndroidHardwareBufferFrame whose native objects are readable only while the callback of AcquiredFrameHandle.withAndroidHardwareBuffer runs. Its other members stay readable after the callback returns.
ScopedDmaBufFrame
A DmaBufFrame whose native objects are readable only while the callback of AcquiredFrameHandle.withDmaBuf runs. Its other members stay readable after the callback returns.
ScopedDxgiSharedTextureFrame
A DxgiSharedTextureFrame whose native objects are readable only while the callback of AcquiredFrameHandle.withDxgiSharedTexture runs. Its other members stay readable after the callback returns.
ScopedGpuSync
A GpuSync whose native objects are readable only while the callback of AcquiredFrameHandle.withProducerSync runs. Its other members stay readable after the callback returns.
ScopedIoSurfaceFrame
A IoSurfaceFrame whose native objects are readable only while the callback of AcquiredFrameHandle.withIoSurface runs. Its other members stay readable after the callback returns.
ScopedMetalTextureFrame
A MetalTextureFrame whose native objects are readable only while the callback of AcquiredFrameHandle.withMetalTexture runs. Its other members stay readable after the callback returns.
ScopedNativePointer
Native pointer value that is valid only while an owner-defined scope is live.
ScopedOpenGlTextureFrame
A OpenGlTextureFrame whose native objects are readable only while the callback of AcquiredFrameHandle.withOpenGlTexture runs. Its other members stay readable after the callback returns.
ScopedVulkanTextureFrame
A VulkanTextureFrame whose native objects are readable only while the callback of AcquiredFrameHandle.withVulkanTexture runs. Its other members stay readable after the callback returns.
ScreenBox
A rectangle of the screen, from its min corner to its max corner.
ScreenLineString
A line through points on the screen.
ScreenPoint
A point on the screen, in logical pixels from the map's top-left corner.
SourceFeature
A feature that a source feature query found.
SourceFeatureQueryOptions
Options for a source feature query.
Status
The result of a call or of asynchronous work.
StyleExpressionHandle
Owner of one native handle.
StyleExpressionInfo
What a style expression's result depends on.
StyleExpressionInputs
The inputs that a style expression reads while it evaluates.
StyleExpressionOptions
Options for parsing a style expression.
StyleExpressionType
The type of a style expression's result.
StyleExpressionTypeKind
The type of a style expression's result, or of the items of an array result.
StyleImageInfo
An image in the map's style.
StyleImageOptions
Options for a style image, as the [sprite](https://maplibre.org/maplibre-style-spec/sprite/) spec describes them.
StyleImageTextFit
How an image stretches to fit text along one axis.
StyleLayerInfo
A layer in the map's style.
StyleLayerVisibility
Whether a layer shows.
StyleRasterDemEncoding
How a raster DEM tile encodes elevation in its colors.
StyleSourceInfo
A source in the map's style.
StyleSourceTileInfo
The tiles of a source, as the style lists them.
StyleSourceType
The type of a style source.
StyleTileScheme
Whether a tileset counts tile rows from the north (XYZ) or the south (TMS).
StyleTransitionOptions
The default [transition](https://maplibre.org/maplibre-style-spec/transition/) for changes to a style's paint properties.
StyleVectorTileEncoding
The format of vector tiles.
TextureImageInfo
The layout of the pixels that RenderSessionHandle.readTexture() reads.
TextureReadbackResult
The pixels that RenderSessionHandle.readTexture() reads.
TileId
The ID of a tile.
TileLodMode
How the map picks the level of detail of its tiles.
TileOperation
A step in loading a tile.
UnitBezier
A timing curve from (0, 0) to (1, 1), with the control points (x1, y1) and (x2, y2).
UrlMatchFlag
How a URL pattern matches a request's URL.
UrlQueryParameter
A query parameter that a resource transform rule adds to a URL.
Vec3
A vector in three dimensions.
ViewportMode
The vertical direction of the image that the map renders.
VulkanBorrowedTexture
A Vulkan image of a borrowed ring.
VulkanBorrowedTextureDescriptor
A ring of your Vulkan images, for MapHandle.attachVulkanBorrowedTexture().
VulkanBorrowedTextureReplacement
New Vulkan images for a borrowed ring, for RenderSessionHandle.setVulkanBorrowedTextureTarget().
VulkanContextDescriptor
The Vulkan device and queue that a render session uses.
VulkanDeviceContextResult
A Vulkan device's context, as VulkanDeviceHandle.getContext() reports it.
VulkanDeviceHandle
Owner of one native handle.
VulkanDeviceOptions
Options for VulkanDeviceHandle.create().
VulkanImageOwner
The queue family that a borrowed image goes to after each frame.
VulkanSurfaceDescriptor
A Vulkan surface to present to, for MapHandle.attachVulkanSurface().
VulkanSurfaceReplacement
A new Vulkan surface for RenderSessionHandle.setVulkanSurfaceTarget().
VulkanTextureFrame
The Vulkan image of an acquired frame.
Wake
A callback that tells the caller when work is ready.
WaylandSurfaceDescriptor
A Wayland surface to present to, for MapHandle.attachWaylandSurface().
WaylandSurfaceReplacement
A new Wayland surface for RenderSessionHandle.setWaylandSurfaceTarget().
WebGlContextDescriptor
The WebGL context or canvas that a render session uses.
WebGlContextKind
How a render session gets its WebGL context.
WglContextDescriptor
The WGL objects that a render session makes its OpenGL context from.
Win32WindowDescriptor
A Win32 window to present to, for MapHandle.attachWin32Window().
Win32WindowReplacement
A new Win32 window for RenderSessionHandle.setWin32WindowTarget().

Extension Types

MapHandleDiscarding
RenderSessionHandleDiscarding
RuntimeHandleDiscarding

Constants

diagnosticMessageCapacity → const int
The size of a diagnostic message in bytes, with its terminator.
frameDemandTokenStillImage → const int
The token of the frame results that a session adds when it renders an image for MapHandle.requestStillImage(). Your own demands can't use it.
textureRingMaxDepth → const int
The most textures that a render session's texture ring can have.
vulkanNonDispatchableHandleNull → const int
The null Vulkan non-dispatchable handle.

Functions

androidFramePacerCreate({FramePacerOptions? options}) → FramePacerHandle
Creates a frame pacer that follows the display through the calling thread's AChoreographer.
appleFramePacerCreate({FramePacerOptions? options}) → FramePacerHandle
Creates a frame pacer that follows the display through a CADisplayLink.
cameraForTile(CanonicalTileId tile, LogicalSize logicalSize) → CameraOptions
Computes the camera that shows exactly one tile on a square map.
clearLogCallback() → void
Sends log messages to the platform's log again, instead of a callback.
cVersion() → int
Returns the API epoch of the library.
getNetworkStatus() → NetworkStatus
Reads whether the library may use the network.
getPluginRegisterFunctionV1() → NativePointer
Returns the function that registers a plugin's style layer types.
initAndroid(NativePointer jniEnv, NativePointer context) → void
Gives the library the Java VM and the app context that it needs on Android.
latLngForProjectedMeters(ProjectedMeters meters) → LatLng
Converts meters in the Web Mercator projection to a coordinate.
logicalExtentPhysicalSize(LogicalExtent extent) → (int, int)
Computes the size in pixels of a target with a logical size and scale factor.
openGlSupportedContextProviderMask() → OpenGlContextProviderFlag
Reports the OpenGL context platforms that this build of the library has.
projectedMetersForLatLng(LatLng coordinate) → ProjectedMeters
Converts a coordinate to meters in the Web Mercator projection.
setLogAsyncSeverityMask(LogSeverityFlag mask) → void
Selects the severities that the library logs on a background thread.
setLogCallback(LogHandler handler) → void
Sends the log messages of every runtime in the process to a callback.
setNetworkStatus(NetworkStatus status) → void
Tells the library whether it may use the network.
supportedRenderBackendMask() → RenderBackendFlag
Returns the render backends that this build of the library draws with.

Typedefs

CameraTransitionEndCallback = void Function(CameraTransitionEnd end)
Receives the end of a camera change.
CustomSourceCancelTileCallback = void Function(MapHandle map, String sourceId, CanonicalTileId tileId)
Reports that a custom source no longer needs a tile.
CustomSourceFetchTileCallback = void Function(MapHandle map, String sourceId, CanonicalTileId tileId)
Asks for the data of a tile in a custom source.
LogCallback = void Function(LogSeverity severity, LogEvent event, int code, String message)
Receives a log message.
ResourceProviderCallback = void Function(ResourceRequestInfo request, ResourceRequestHandle handle)
Serves a network request in place of the library.
ResourceRequestCancelCallback = void Function()
Reports that the library no longer needs a resource request.
ResourceTransformCallback = void Function(ResourceKind kind, String url, ResourceTransformRequestHandle request)
Rewrites the URL of a network request before the library sends it.
RuntimeEventCallback = void Function(List<RuntimeEvent> events)
Receives a batch of events.
WakeCallback = void Function()
Tells the caller that work is ready for it.

Exceptions / Errors

AbiVersionMismatchException
The native library and binding use different C ABI versions.
MaplibreException
A native status and the diagnostic that native copied for it.
NativeAdoptionFailure