@maplibre/native-ffi
    Preparing search index...

    Class MapHandle

    A map, with its style and camera.

    See mln_map in the C API reference.

    Hierarchy

    • Owner
      • MapHandle
    Index
    addCustomGeometrySource addCustomVectorSource addGeoJsonSource addImageSourceImage addStyleLayerJson addStyleSourceJson applyCameraDelta attachAndroidHardwareBufferRing attachAndroidSurface attachDmaBufRing attachDxgiSharedTextureRing attachIoSurfaceRing attachMetalBorrowedTexture attachMetalSurface attachOffscreen attachOhosSurface attachOpenGlBorrowedTexture attachOpenGlSurface attachVulkanBorrowedTexture attachVulkanSurface attachWaylandSurface attachWebGpuBorrowedTexture attachWebGpuSurface attachWin32Window beginCommandGroup cameraForGeometry cameraForLatLngBounds cameraForLatLngs cancelCameraTransitions cancelCameraTransitionsWithId dispose dumpDebugLogs endCommandGroup fitCameraToGeometry fitCameraToLatLngBounds fitCameraToLatLngs getCamera getFeatureState getGlobalState getImageSourceCoordinates getLoadedStyleJson getSnapshot getStyleImage getStyleLayer getStyleLayerJson getStyleLayerProperty getStyleLightProperty getStyleSource getStyleTransitionOptions getStyleUrl invalidateCustomGeometrySourceRegion invalidateCustomGeometrySourceTile invalidateCustomVectorSourceRegion invalidateCustomVectorSourceTile latLngBoundsForCamera listStyleLayers listStyleSources moveStyleLayer release removeFeatureState removeStyleImage removeStyleLayer removeStyleSource requestRepaint requestStillImage resize setBounds setCustomGeometrySourceTileData setCustomGeometrySourceTileError setCustomVectorSourceTileData setCustomVectorSourceTileError setDebugFlags setEventMask setFeatureState setFreeCameraOptions setGeoJsonSourceData setGeoJsonSourceSynchronousTiling setGeoJsonSourceUrl setGlobalStateProperty setImageSourceCoordinates setImageSourceImage setImageSourceUrl setProjectionMode setRenderingStatsViewEnabled setStyleImage setStyleJson setStyleLayerProperty setStyleLightJson setStyleLightProperty setStyleSourceVolatile setStyleTransitionOptions setStyleUrl setTileOptions setViewportOptions toString updateCamera
    "[asyncDispose]": () => Promise<void>

    Calls release(), for await using. Hosts without Symbol.asyncDispose, such as ArkTS, leave it undefined.

    "[dispose]": () => void

    Calls dispose(), for using. Hosts without Symbol.dispose, such as ArkTS, leave it undefined.

    id: bigint

    The native handle value, which runtime events report as their source. It stays readable after release, so events drained later still match this handle.

    ready: Promise<void>

    Settles once the map is ready, and rejects with a MaplibreError when it fails to become ready. Asynchronous calls on the map before then wait for it. A rejection that nothing awaits isn't reported as unhandled.

    • Adds a layer to the map's style.

      layerJson is a [layer](https://maplibre.org/maplibre-style-spec/layers/) object. The layer goes below the layer named beforeLayerId, or above every layer when beforeLayerId is empty.

      See mln_map_add_style_layer_json in the C API reference.

      Errors:

      • Status.notFound when the style has no layer named beforeLayerId, or no source with the ID that the layer uses.
      • Status.alreadyExists when the style already has a layer with the new layer's ID.
      • Status.invalidState while the style isn't loaded, as MapHandle.setStyleUrl() describes.

      Parameters

      • layerJson: unknown
      • OptionalbeforeLayerId: string

      Returns Promise<CommandCompletion>

    • Moves the camera relative to where it is, as a gesture does.

      delta can pan the map's content by an offset on the screen, scale the zoom, and add to the bearing and pitch. An anchor keeps one screen point in place while the scale, bearing, or pitch changes. An anchor needs one of those changes, and combines with an offset only when the delta has no animation. The function finishes when the map applies the delta, before an animation ends.

      A delta that replaces an animated one starts from where that animation left the camera, so the rest of the replaced change never happens. To reach an exact camera, use MapHandle.updateCamera().

      A delta in the end phase can carry momentum, which keeps the camera moving from the gesture's release velocities and slows it on each rendered frame. The gesture lasts until the momentum ends: the snapshot keeps gesture_in_progress set, and camera events report CameraChangeSource.momentum. With momentum, animation sets only transition_id and the end handler, which runs when the gesture ends.

      A delta in the begin phase, MapHandle.cancelCameraTransitions(), or a cancellation by that ID stops the momentum. A later command that sets a field stops only the parts of the momentum that move that field. On a tilted map, the pan moves the map's content the same distance on the screen in every direction.

      See mln_map_apply_camera_delta in the C API reference.

      Parameters

      Returns Promise<CommandCompletion>

    • Creates a session that renders the map into a ring of Android hardware buffers that the library allocates.

      Acquire each frame with RenderSessionHandle.acquireFrame(), and get its buffer with AcquiredFrameHandle.withAndroidHardwareBuffer(). RenderSessionHandle.resize() gives the ring new buffers of the new size.

      A Vulkan build renders with device, or, when device is null, with a device that the library creates. An OpenGL build uses an EGL context on the default display, and device must be null. Attach with RenderDriverKind.coreWorker.

      To show the buffers through Android's UI, such as with Bitmap.wrapHardwareBuffer, attach without GpuSyncKindFlag.syncFd in RenderSessionAttachOptions.producerSyncKinds, so that each frame finishes before you acquire it. Keep each frame acquired until the next one replaces it on screen, then release it with GpuSyncKind.cpuComplete. Give the ring 3 buffers, so the session can render while you hold two frames.

      See mln_map_attach_android_hardware_buffer_ring in the C API reference.

      Errors:

      • Status.unsupported when Android is older than 8.0, API level 26, or when the graphics context can't render into hardware buffers: the Vulkan device lacks VK_ANDROID_external_memory_android_hardware_buffer, or the EGL display lacks EGL_ANDROID_get_native_client_buffer or EGL_ANDROID_image_native_buffer.
      • Status.nativeError when the library can't create its Vulkan device or initialize the default EGL display.

      Parameters

      Returns RenderSessionHandle

    • Creates a session that presents the map to an Android window, with a graphics context that the library creates.

      A Vulkan build presents with device, or, when device is null, with a device that the library creates. An OpenGL build uses an EGL context on the default display, and device must be null. Attach with RenderDriverKind.coreWorker.

      When the platform destroys the window, such as in SurfaceHolder.Callback.surfaceDestroyed, release the target with RenderSessionHandle.releaseTarget(), or give the session a new window with RenderSessionHandle.setAndroidSurfaceTarget(), without waiting for that to complete. The session keeps its own reference to the window and stays usable for the next window. A frame to the destroyed window finishes with RenderResult.targetNotReady, or with RenderResult.rendered if the window went away while the frame was presenting.

      See mln_map_attach_android_surface in the C API reference.

      Errors:

      • Status.invalidArgument when surface has no window, such as after the platform destroyed it.
      • Status.unsupported when you created device without VulkanDeviceOptions.presentation.
      • Status.unsupported when the GPU or the Vulkan loader can't present.
      • Status.nativeError when the library can't create the graphics context or the window's surface.

      Parameters

      Returns RenderSessionHandle

    • Creates a session that renders the map into a ring of dmabufs that the library allocates.

      Acquire each frame with RenderSessionHandle.acquireFrame(), and get its buffer with AcquiredFrameHandle.withDmaBuf(). RenderSessionHandle.resize() gives the ring new buffers of the new size.

      A Vulkan build renders with device, or, when device is null, with a device that the library creates. An OpenGL build uses an EGL context of its own, and device must be null. Attach with RenderDriverKind.coreWorker.

      For a reader that waits on no sync file, such as a Wayland compositor without explicit synchronization, attach without GpuSyncKindFlag.syncFd in RenderSessionAttachOptions.producerSyncKinds, so that each frame finishes before you acquire it. Keep each frame acquired until its reader is done with the buffer. Give the ring 3 buffers, so the session can render while you hold two frames.

      See mln_map_attach_dma_buf_ring in the C API reference.

      Errors:

      • Status.unsupported when the graphics context can't render into a dmabuf of any of formats.
      • Status.nativeError when the library can't create its Vulkan device or initialize an EGL display.

      Parameters

      Returns RenderSessionHandle

    • Creates a session that renders the map into a ring of DXGI shared textures that the library allocates.

      Acquire each frame with RenderSessionHandle.acquireFrame(), and get its texture with AcquiredFrameHandle.withDxgiSharedTexture(). RenderSessionHandle.resize() gives the ring new textures of the new size.

      The session renders with the Vulkan device device, or, when device is null, with one that the library creates. The textures belong to the device's GPU, so open them on a D3D11 or D3D12 device of the same adapter. To pick the GPU, create device with VulkanDeviceOptions.deviceLuid set to your adapter's LUID. Attach with RenderDriverKind.coreWorker.

      For a reader that waits on no fence, such as Flutter's texture registrar, attach without GpuSyncKindFlag.d3d12Fence in RenderSessionAttachOptions.producerSyncKinds, so that each frame finishes before you acquire it. Release a frame with GpuSyncKind.cpuComplete only once the reader has finished with its texture.

      See mln_map_attach_dxgi_shared_texture_ring in the C API reference.

      Errors:

      • Status.unsupported in an OpenGL build, or when the GPU can't share the textures: D3D11 has no adapter with the Vulkan device's LUID or can't share textures through NT handles, or the device lacks VK_KHR_external_memory_win32 or can't import D3D11 textures.
      • Status.nativeError when the library can't create its Vulkan device or a D3D11 device on the adapter.

      Parameters

      Returns RenderSessionHandle

    • Creates a session that renders the map into a ring of IOSurfaces that the library allocates.

      Acquire each frame with RenderSessionHandle.acquireFrame(), and get its surface with AcquiredFrameHandle.withIoSurface(). RenderSessionHandle.resize() gives the ring new surfaces of the new size. Attach with RenderDriverKind.coreWorker.

      To hand frames to a reader that can't wait on an event, such as Flutter's copyPixelBuffer, attach without GpuSyncKindFlag.metalSharedEvent in RenderSessionAttachOptions.producerSyncKinds, so that each frame finishes before you acquire it. Release a frame with GpuSyncKind.cpuComplete only once the reader has finished with its surface.

      See mln_map_attach_io_surface_ring in the C API reference.

      Errors:

      • Status.unsupported when supportedRenderBackendMask() lacks RenderBackendFlag.metal.
      • Status.nativeError when context names no device and the system has no Metal device.

      Parameters

      Returns RenderSessionHandle

    • Creates a session that presents the map to an OpenHarmony window, with a graphics context that the library creates.

      A Vulkan build presents with device, or, when device is null, with a device that the library creates. An OpenGL build uses an EGL context on the default display, and device must be null. Attach with RenderDriverKind.coreWorker.

      When the platform destroys the window, such as in an XComponent's onSurfaceDestroyed callback, release the target with RenderSessionHandle.releaseTarget(), or give the session a new window with RenderSessionHandle.setOhosSurfaceTarget(), without waiting for that to complete. The session keeps its own reference to the window and stays usable for the next window. A frame to the destroyed window finishes with RenderResult.targetNotReady, or with RenderResult.rendered if the window went away while the frame was presenting.

      See mln_map_attach_ohos_surface in the C API reference.

      Errors:

      • Status.invalidArgument when no surface in this process has OhosSurfaceDescriptor.surfaceId, such as after the platform destroyed it.
      • Status.unsupported when you created device without VulkanDeviceOptions.presentation.
      • Status.unsupported when the GPU or the Vulkan loader can't present.
      • Status.nativeError when the library can't create the graphics context or the window's surface.

      Parameters

      Returns RenderSessionHandle

    • Creates a session that presents the map to a Wayland surface, with a graphics context that the library creates.

      A Vulkan build presents with device, or, when device is null, with a device that the library creates. An OpenGL build uses an EGL context on the display, and device must be null. Attach with RenderDriverKind.coreWorker.

      The session presents without waiting for the compositor, so demand at most one frame per display refresh.

      Keep the surface until a release or replacement of the target, or a detach of the session, completes. Keep the display connected until the session's detach completes. In an OpenGL build, if you also use EGL on the display, initialize it before you attach.

      See mln_map_attach_wayland_surface in the C API reference.

      Errors:

      • Status.unsupported when you created device without VulkanDeviceOptions.presentation.
      • Status.unsupported when the GPU or the Vulkan loader can't present to Wayland.
      • Status.nativeError when the library can't create the graphics context or present to the surface.

      Parameters

      Returns RenderSessionHandle

    • Creates a session that presents the map to a Win32 window, with a graphics context that the library creates.

      A Vulkan build presents with device, or, when device is null, with a device that the library creates. An OpenGL build uses a WGL context, and device must be null. Attach with RenderDriverKind.coreWorker.

      An OpenGL build sets the window's pixel format, so don't set one yourself.

      The session presents without waiting for the display, so demand at most one frame per display refresh. While the window is minimized, frame demands finish with RenderResult.targetNotReady.

      Keep the window until a release or replacement of the target, or a detach of the session, completes.

      See mln_map_attach_win32_window in the C API reference.

      Errors:

      • Status.invalidArgument when window isn't a window, or, in an OpenGL build, already has another pixel format.
      • Status.invalidState when window is minimized or has no client area.
      • Status.unsupported when you created device without VulkanDeviceOptions.presentation.
      • Status.invalidState when window was minimized before the attach ran.
      • Status.unsupported when the GPU or the Vulkan loader can't present.
      • Status.nativeError when the library can't create the graphics context or present to the window.

      Parameters

      Returns RenderSessionHandle

    • Computes a camera that fits a GeoJSON geometry in the map's view.

      geometry is a GeoJSON geometry object with at least one coordinate, not a feature. The camera keeps the map's bearing and pitch unless fitOptions sets them, and its zoom stays within the map's zoom limits.

      See mln_map_camera_for_geometry in the C API reference.

      Errors:

      • Status.invalidArgument when the padding in fitOptions leaves no room for the area.

      Parameters

      Returns Promise<CameraOptions>

    • Moves the camera to fit a GeoJSON geometry in the map's view, at once or with an animation.

      geometry is a GeoJSON geometry object with at least one coordinate, not a feature. The camera is the one that MapHandle.cameraForGeometry() computes after the commands sent before this one apply. The function finishes when the map applies the change, before an animation ends.

      See mln_map_fit_camera_to_geometry in the C API reference.

      Errors:

      • Status.invalidArgument when the padding in update leaves no room for the area. The camera doesn't move.

      Parameters

      Returns Promise<CommandCompletion>

    • Moves the camera to fit coordinates in the map's view, at once or with an animation.

      coordinates must not be empty. The camera is the one that MapHandle.cameraForLatLngs() computes after the commands sent before this one apply. The function finishes when the map applies the change, before an animation ends.

      See mln_map_fit_camera_to_lat_lngs in the C API reference.

      Errors:

      • Status.invalidArgument when the padding in update leaves no room for the area. The camera doesn't move.

      Parameters

      Returns Promise<CommandCompletion>

    • Reads the corners of an image source's image, clockwise from the top left.

      See mln_map_get_image_source_coordinates in the C API reference.

      Errors:

      • Status.notFound when the style has no source named sourceId.
      • Status.invalidArgument when the source named sourceId isn't an image source.

      Parameters

      • sourceId: string

      Returns Promise<readonly LatLng[]>

    • Reads a property of a layer in the map's style.

      The value can differ in form from the value that was set: a color set as "#ff0000" reads back as ["rgba", 255, 0, 0, 1].

      Completes with no value when the layer doesn't set the property.

      See mln_map_get_style_layer_property in the C API reference.

      Errors:

      • Status.notFound when the style has no layer named layerId.

      Parameters

      • layerId: string
      • propertyName: string

      Returns Promise<unknown>

    • Reads a property of the light of the map's style.

      The value can differ in form from the value that was set: a color set as "#ff0000" reads back as ["rgba", 255, 0, 0, 1].

      Completes with no value when the light doesn't set the property.

      See mln_map_get_style_light_property in the C API reference.

      Parameters

      • propertyName: string

      Returns Promise<unknown>

    • Reads a source of the map's style.

      A tile source with a url has an empty attribution until its TileJSON loads, which raises RuntimeEventType.mapSourceChanged.

      Completes with no value when the style has no source named sourceId.

      See mln_map_get_style_source in the C API reference.

      Parameters

      • sourceId: string

      Returns Promise<StyleSourceInfo | undefined>

    • Moves a layer of the map's style below the layer named beforeLayerId, or above every layer when beforeLayerId is empty.

      See mln_map_move_style_layer in the C API reference.

      Errors:

      • Status.notFound when the style has no layer named layerId or beforeLayerId.
      • Status.invalidState while the style isn't loaded, as MapHandle.setStyleUrl() describes.

      Parameters

      • layerId: string
      • OptionalbeforeLayerId: string

      Returns Promise<CommandCompletion>

    • Renders a still image of a static or tile map.

      The map's render session draws the image once every resource that the image needs has loaded.

      See mln_map_request_still_image in the C API reference.

      Errors:

      • Status.cancelled when the map is released before the image is done.
      • Status.nativeError when the style or a resource that the image needs fails to load.

      Returns Promise<void>

    • Sets the data of a tile in a custom geometry source.

      data is a GeoJSON feature collection, feature, or geometry. The source ignores data for a tile that it hasn't asked for, or has since cancelled.

      See mln_map_set_custom_geometry_source_tile_data in the C API reference.

      Errors:

      • Status.notFound when the style has no source named sourceId.
      • Status.invalidArgument when the source named sourceId isn't a custom geometry source.

      Parameters

      Returns Promise<CommandCompletion>

    • Replaces the data of a GeoJSON source.

      data is a GeoJSON feature collection, feature, or geometry. The library prepares it for the source with the source's options, off the threads that the caller and the runtime use, and the command completes once the source holds it. Later commands don't wait for it. While the source is still preparing earlier data, only the newest data waits to follow it.

      With synchronous tiling on, as MapHandle.setGeoJsonSourceSynchronousTiling() describes, the command prepares data before later commands run, so the data shows in the next frame.

      See mln_map_set_geo_json_source_data in the C API reference.

      Errors:

      • Status.notFound when the style has no source named sourceId.
      • Status.invalidArgument when the source named sourceId isn't a GeoJSON source, when data isn't valid GeoJSON, or when the source clusters and data isn't a feature collection of points. The source keeps its data.
      • Status.cancelled when newer data for the source replaces data while it waits, or when the source's URL, its removal, a style load, or the map's release replaces the source's data before data is ready.
      • Status.invalidState while the style isn't loaded, as MapHandle.setStyleUrl() describes.

      Parameters

      • sourceId: string
      • data: unknown

      Returns Promise<CommandCompletion>

    • Sets whether a GeoJSON source builds its tiles while the map renders.

      Building tiles while the map renders, instead of in the background, makes new data show in the next frame. The setting replaces the synchronousUpdate member of the source's JSON, which defaults to false.

      See mln_map_set_geo_json_source_synchronous_tiling in the C API reference.

      Errors:

      • Status.notFound when the style has no source named sourceId.
      • Status.invalidArgument when the source named sourceId isn't a GeoJSON source.
      • Status.invalidState while the style isn't loaded, as MapHandle.setStyleUrl() describes.

      Parameters

      • sourceId: string
      • enabled: boolean

      Returns Promise<CommandCompletion>

    • Makes a GeoJSON source load its data from url.

      See mln_map_set_geo_json_source_url in the C API reference.

      Errors:

      • Status.notFound when the style has no source named sourceId.
      • Status.invalidArgument when the source named sourceId isn't a GeoJSON source.
      • Status.invalidState while the style isn't loaded, as MapHandle.setStyleUrl() describes.

      Parameters

      • sourceId: string
      • url: string

      Returns Promise<CommandCompletion>

    • Moves the image of an image source.

      coordinates are the image's four corners, clockwise from the top left.

      See mln_map_set_image_source_coordinates in the C API reference.

      Errors:

      • Status.notFound when the style has no source named sourceId.
      • Status.invalidArgument when the source named sourceId isn't an image source.
      • Status.invalidState while the style isn't loaded, as MapHandle.setStyleUrl() describes.

      Parameters

      • sourceId: string
      • coordinates: readonly LatLng[]

      Returns Promise<CommandCompletion>

    • Makes an image source load its image from url.

      See mln_map_set_image_source_url in the C API reference.

      Errors:

      • Status.notFound when the style has no source named sourceId.
      • Status.invalidArgument when the source named sourceId isn't an image source.
      • Status.invalidState while the style isn't loaded, as MapHandle.setStyleUrl() describes.

      Parameters

      • sourceId: string
      • url: string

      Returns Promise<CommandCompletion>

    • Loads the map's style from json.

      The command completes once the style has parsed, and the map's style is then loaded, as MapHandle.setStyleUrl() describes. The style's sources, sprites, and glyphs load in the background.

      See mln_map_set_style_json in the C API reference.

      Errors:

      • Status.nativeError when json isn't a valid style. The map keeps its current style.

      Parameters

      • json: unknown

      Returns Promise<CommandCompletion>

    • Sets a property of a layer in the map's style.

      propertyName is one of the layer's layout or paint [properties](https://maplibre.org/maplibre-style-spec/layers/), or filter, minzoom, maxzoom, source, or source-layer. A null value resets any of these but source and source-layer to its default.

      See mln_map_set_style_layer_property in the C API reference.

      Errors:

      • Status.notFound when the style has no layer named layerId.
      • Status.invalidState while the style isn't loaded, as MapHandle.setStyleUrl() describes.

      Parameters

      • layerId: string
      • propertyName: string
      • value: unknown

      Returns Promise<CommandCompletion>

    • Sets whether a source is volatile.

      The map doesn't store the tiles of a volatile source in the persistent cache.

      See mln_map_set_style_source_volatile in the C API reference.

      Errors:

      • Status.notFound when the style has no source named sourceId.
      • Status.invalidState while the style isn't loaded, as MapHandle.setStyleUrl() describes.

      Parameters

      • sourceId: string
      • isVolatile: boolean

      Returns Promise<CommandCompletion>

    • Loads the map's style from url.

      The command completes once the style document has loaded and parsed. The style's sources, sprites, and glyphs then load in the background.

      The map's style is loaded from the time a style document parses until the next call to this function. While the style isn't loaded, the commands that change it complete with Status.invalidState. To change a new map's style without a style document, first load an empty style, such as {"version":8,"sources":{},"layers":[]}.

      See mln_map_set_style_url in the C API reference.

      Errors:

      • Status.nativeError when the style document fails to load or isn't a valid style.
      • Status.cancelled when the map is released, or this function or MapHandle.setStyleJson() loads another style, before the style document parses.

      Parameters

      • url: string

      Returns Promise<CommandCompletion>