MapboxMapController

MapController implementation backed by Mapbox Maps SDK: wires style sources/layers, custom GL weather layers (MapboxLayerHost), camera sync (CameraSync), and Mapbox gestures (e.g. map clicks).

Construct with the same MapView you show in your activity and an XweatherAccount for API access.

See also

for weather layers, timeline, data inspector, and legends.

Constructors

Link copied to clipboard
constructor(mapView: MapView, baseContext: Context, account: XweatherAccount, lifecycleOwner: LifecycleOwner)
constructor(mapView: MapView, account: XweatherAccount)

Types

Link copied to clipboard
object Companion

Shared constants for MapboxMapController: logging tag, camera projection modes, and GL-stencil ids.

Properties

Link copied to clipboard
val account: XweatherAccount
Link copied to clipboard
val animationOptions: AnimationOptions

Configuration options that control the behavior of timeline animations and data preloading.

Link copied to clipboard
lateinit var centerLatLng: Coordinate

Geographic center of the map in latitude/longitude degrees, kept in sync with the camera.

Link copied to clipboard

Pick/inspect weather values at a tap location; enable with addDataInspectorControl. Configure off-screen dismissal via DataInspectorControl.cancelCalloutWhenOffScreen.

Link copied to clipboard

Internal debounce job for camera move-end handling; managed by MapboxMapController.

Link copied to clipboard

Approximate download progress fraction (0f–1f) while tiles are in flight.

Link copied to clipboard

All MapsGL map layers currently registered on this controller, keyed by layer id.

Link copied to clipboard

Optional UI control for layer legends; install with add.

Link copied to clipboard
var mapboxMap: MapboxMap?

Mapbox map handle; non-null after construction. Safe to use from the main thread once the view is attached.

Link copied to clipboard

Session id assigned at construction; must match Timeline.mapSessionId for global tile bookkeeping (com.xweather.mapsgl.data.TileList) to apply to this controller.

Link copied to clipboard
val mapView: MapView
Link copied to clipboard

Observes encoded-tile metadata keys; when a layer id is emitted, that TileLayer refreshes visible tiles. Attach only if you extend encoded sources; normally the controller wires this internally.

Link copied to clipboard

Posted when the current load session completes (encoded downloads and bind pipeline idle).

Link copied to clipboard

Emits MapLoadProgress while map data loads. Use onLoadProgress.observe(this) { progress -> ... } like other LiveData on this controller. For coroutine / flow access, see onLoadProgressValue.

Link copied to clipboard

Same progress as onLoadProgress, exposed as a Signal for coroutine collectors.

Link copied to clipboard

Posted when loading begins for any tracked data source (e.g. tile wave started).

Link copied to clipboard

Fires with a source id after addSource registers it and the source is ready for layers.

Link copied to clipboard

The primary interface for communicating with the Xweather backend.

Link copied to clipboard

Self-reference to this controller instance, used to disambiguate this inside nested listener/Runnable bodies (e.g. downloadTrackingRunnable) where this would otherwise refer to the inner object rather than the MapController.

Link copied to clipboard

instance used for managing animation and time-based data.

Link copied to clipboard

When true, custom com.xweather.mapsgl.layers.spec.StencilLayerMaskSpec masks are baked once per dirty frame into an R8 viewport texture (JS tMask) instead of per-tile stencil rewrites during weather draw.

Link copied to clipboard

Library-internal: at least one visible layer is waiting on tile data.

Link copied to clipboard

Library-internal: edge detection for post-download refresh.

Link copied to clipboard

Library-internal: previous frame had pending tile downloads.

Functions

Link copied to clipboard
fun add(legendControl: LegendControl?)

Installs the provided legend control, wiring it to map events and populating initial legends.

open fun add(layerID: String, layerHost: CustomLayerHost)

Hook for map SDK–specific registration of a custom layer host after MapsGL created the layer.

Link copied to clipboard
open fun addCloseable(closeable: AutoCloseable)
fun addCloseable(key: String, closeable: AutoCloseable)
Link copied to clipboard

Activates and initializes the Data Inspector control for the map.

Link copied to clipboard
fun <P : LayerPaint> addLayer(descriptor: LayerDescriptor<P>, beforeID: String?): TileLayer?

Adds a new layer to the map.

Link copied to clipboard
fun addLegend(forConfig: WeatherLayerConfiguration<*, *>)

Adds or refreshes the legend defined on forConfig into the current legendControl.

Link copied to clipboard

Registers a data source. When the descriptor leaves ImageSourceDescriptor.authenticator / EncodedSourceDescriptor.authenticator / VectorSourceDescriptor.authenticator / GeoJSONSourceDescriptor.authenticator unset, this controller supplies service.authenticator automatically.

Link copied to clipboard
fun addWeatherLayer(layerCode: LayerCode, id: String? = null, beforeId: String? = null, configure: (WeatherConfiguration) -> Unit? = null): TileLayer?

Adds a weather layer from a LayerCode preset (source + descriptor + paint from service).

fun addWeatherLayer(config: WeatherConfiguration, id: String? = null, beforeId: String? = null, isCompoundLayer: Boolean = false): TileLayer?

Adds a weather layer from an explicit WeatherConfiguration (use when you built the config from WeatherService factories instead of LayerCode).

Link copied to clipboard

Cancel scheduled mask-demo refresh work; call when the user picks another demo.

Link copied to clipboard

Removes the custom stencil/texture mask from layerId so weather draws unmasked. Mask vector layers (motorway, CONUS fill) stay on the map and can be re-enabled via reregisterCustomStencilMask after restoring TileLayer.stencilLayerMask.

Link copied to clipboard

Clears all pending-download bookkeeping across every EncodedTileLayer and the shared Timeline load-session state (pending tile lists, download-progress counters, and the downloading/waiting flags). Use to force-recover a controller stuck reporting outstanding downloads that will never resolve (e.g. after a watchdog timeout).

Link copied to clipboard

Activates GLES hybrid land ∩ line stencil on a weather layer (marine clip + motorways on land). Call after addWeatherLayer when the layer uses MaskLayerKind.LAND plus line-only com.xweather.mapsgl.layers.spec.StencilLayerMaskSpec refs.

Link copied to clipboard

Re-binds OSM stencil fetch, tile-cache replay, and per-layer render hooks after addWeatherLayer with a built-in MaskLayerKind. Call from app demos when switching mask types across activities (land → water).

Link copied to clipboard
fun formatDate(date: Date): String

Formats a Date as an ISO-8601-like UTC string (first 19 chars + Z) for display or logging.

Link copied to clipboard
open override fun getBearing(): Double
Link copied to clipboard
open override fun getBounds(): LatLonBounds

Visible geographic bounds derived from Mapbox unwrapped camera bounds and VisibleGeoBounds.

Link copied to clipboard
open override fun getCenter(): Coordinate
Link copied to clipboard
Link copied to clipboard

Resolves the WeatherConfiguration that would be used for addWeatherLayer with this layerCode.

Link copied to clipboard
open override fun getFov(): Double

Returns the map camera's current field-of-view in degrees.

Link copied to clipboard
fun getLayer(id: String): MapLayer<*, *>?
Link copied to clipboard
open override fun getPitch(): Double
Link copied to clipboard
open override fun getSize(): Size

Returns the map's container size.

Link copied to clipboard
Link copied to clipboard

Raw unwrapped longitudes from Mapbox — not passed through VisibleGeoBounds, which can collapse the viewport to a single -180,180 strip and hide extra world copies for encoded tile draws.

Link copied to clipboard

Returns A layer given its LayerCode.

Link copied to clipboard
open override fun getZoom(): Double
Link copied to clipboard
Link copied to clipboard

Returns whether the map currently contains a data source with the specified identifier.

Link copied to clipboard

Returns whether the map currently contains a weather layer with the specified identifier.

Link copied to clipboard
open override fun moveLayer(id: String, beforeId: String?)

Reorders a style layer in the Mapbox style stack.

Link copied to clipboard
open override fun off(name: String, callback: (Any) -> Unit)

Removes a previously registered callback for name.

Link copied to clipboard
open override fun on(name: String, callback: (Any) -> Unit)

Registers callback for controller-issued events named name (see MapControllerEvents).

Link copied to clipboard
open override fun onConfigurationChanged(p0: Configuration)

ComponentCallbacks2: no-op; orientation is handled via camera callbacks.

Link copied to clipboard
open override fun onCreate(owner: LifecycleOwner)

DefaultLifecycleObserver callback: begins observing raster tile API events for owner's lifetime. Invoked automatically once registerMapLifecycleObserver has attached this controller.

Link copied to clipboard
open override fun onDestroy(owner: LifecycleOwner)

LifecycleOwner destroy hook: delegates to shutdown.

Link copied to clipboard
open override fun onLowMemory()

ComponentCallbacks2: no-op; deprecated in favor of onTrimMemory.

Link copied to clipboard
open override fun onMapClick(point: Point): Boolean

Mapbox map click: forwards to the data inspector when it is enabled.

Link copied to clipboard
open fun onPause(owner: LifecycleOwner)
Link copied to clipboard
open fun onResume(owner: LifecycleOwner)
Link copied to clipboard
open override fun onStart(owner: LifecycleOwner)

DefaultLifecycleObserver callback: resumes timeline playback, tile polling, and custom-layer updates when the host owner returns to the foreground. See resumeFromBackground.

Link copied to clipboard
open override fun onStop(owner: LifecycleOwner)

LifecycleOwner stop hook: cancels the pending move-end debounce and drops any queued GL-stencil OSM prefetch work before delegating to MapController.onStop.

Link copied to clipboard
open override fun onTileLayerEvent(layerId: String, eventType: TileLayer.TileLayerEventType, data: Any?)

TileLayer.TileLayerEventListener hook; reserved for future tile-layer events from Mapbox path.

Link copied to clipboard
open override fun onTrimMemory(level: Int)

Clears encoded tile caches outside the visible viewport when the OS reports memory pressure (ComponentCallbacks2); aggressive only for background / UI-hidden levels.

Link copied to clipboard

Triggers a manual pre-fetch of tile animation data.

Link copied to clipboard
suspend fun query(point: Point, layerList: List<String>, onTouch: Boolean = false): <Error class: unknown class><String, FeatureQueryResult>

Queries encoded tile layers and Mapbox vector layers at point for the given layer ids.

Link copied to clipboard
suspend fun queryFeatures(point: Point, vectorLayerList: List<VectorTileLayer>, onTouch: Boolean = true): <Error class: unknown class><String, FeatureQueryResult>?

Mapbox queryRenderedFeatures at a screen point for the given vector layers; fills data-inspector vector fields when onTouch matches the active inspector buffer.

Link copied to clipboard
suspend fun queryFeaturesInBox(boxTopLeft: ScreenCoordinate, boxBottomRight: ScreenCoordinate, vectorLayerList: List<VectorTileLayer>, onTouch: Boolean = true): <Error class: unknown class><String, FeatureQueryResult>?

Queries features within a rectangular area.

Link copied to clipboard
suspend fun queryFeaturesOld(point: Point, vectorLayerList: List<VectorTileLayer>, onTouch: Boolean = true): <Error class: unknown class><String, FeatureQueryResult>?

Legacy vector query implementation kept for compatibility; prefer queryFeatures.

Link copied to clipboard

Refresh the custom stencil mask for the weather layer layerId after a mask vector layer's paint has been mutated in place (e.g. new line thickness / cap / join). Updates the coordinator's per-tile listeners so subsequent mesh builds use the new paint, replays cached MVT features through the new listeners so already-loaded tiles rebuild their stencil meshes, and asks Mapbox for a repaint.

Link copied to clipboard
suspend fun refreshVisibleLayers(requestDL: Boolean = true)

Recomputes visible tiles for every visible MapsGL layer and marks custom layer hosts dirty.

Link copied to clipboard

Registers this controller with the MapView's lifecycle (Activity or fragment owner). Safe to call multiple times; typically invoked from MapboxMapController after attach.

Link copied to clipboard

Deactivates the Data Inspector control and cleans up its associated resources.

Link copied to clipboard
fun removeLayer(id: String, isCompounLayer: Boolean = false)

Removes a layer by id, detaches consumers, and cleans encoded-grid sidecars when present.

Link copied to clipboard

Removes the currently installed legend control and clears any associated observers.

Link copied to clipboard

Unregisters a data source from this controller (does not remove layers that still reference it).

Link copied to clipboard

Removes the weather layer(s) for code from the map, sources, legends, and mask sidecars as needed.

Link copied to clipboard
fun reregisterCustomStencilMask(layerId: String, forceInvalidate: Boolean = false)

Rebinds MVT/GeoJSON stencil listeners after TileLayer.stencilLayerMask.layers changes (e.g. toggling individual mask layers in Demo 3). Paint-only updates should use refreshCustomStencilMask instead.

Link copied to clipboard
fun scheduleCustomStencilMaskDemoRefresh(layerId: String, waitForMaskMeshes: Boolean = false)

Custom StencilLayerMaskSpec / LayerMaskSpec demos need the Mapbox persistent custom layer, mask geometry, and encoded weather tiles before the first paint. Schedule after addWeatherLayer when the camera may still be moving (e.g. setCenter / setZoom).

Instanced gridded layers (wind arrows / barbs) need encoded tiles fetched after the Mapbox persistent custom layer exists. addToMap can call refreshVisibleLayers too early; schedule this from demo activities right after addWeatherLayer.

Link copied to clipboard

Land/water mask demos start paused; encoded preload must run only after the custom Mapbox layer exists and the camera has settled (fixes partial tiles on menu → demo re-entry).

open override fun schedulePrefetchGlStencilMaskTilesForWeatherRender(coords: List<TileCoord>, maskKind: MaskLayerKind, countryIso3166Alpha2: String?)

Queues GL-stencil mesh prefetch for the weather tile coords currently being rendered under maskKind (and countryIso3166Alpha2 for MaskLayerKind.COUNTRY), then kicks off runGlStencilPrefetchWorker. Tiles that already have a renderable mesh are skipped unless a transportation zoom-bin change forces a visible-tile refresh at the new stroke width.

open override fun schedulePrefetchGlStencilOsmTilesForCustomMask(coords: List<TileCoord>)

Unconditionally queues coords as GL-stencil OSM prefetch keys for a custom stencil mask (no existing-mesh check, unlike schedulePrefetchGlStencilMaskTilesForWeatherRender) and kicks off runGlStencilPrefetchWorker.

Link copied to clipboard
fun setBearing(bearing: Double)

Sets map bearing (rotation in degrees; 0 = north up).

Link copied to clipboard
open override fun setCenter(center: Coordinate)

Moves the camera center while preserving the current getZoom.

Link copied to clipboard
open override fun setLayerHostToUpdate(layerId: String)

Marks the custom MapboxLayerHost for layerId as needing its GL textures rebound.

Link copied to clipboard
open override fun setLayerVisible(id: String, visible: Boolean)

Syncs MapsGL layer visibility, custom layer host visibility, and Mapbox style visibility for id.

Link copied to clipboard
fun setPaintProperty(layerId: String, property: String, value: Any)

Sets a paint-related property on a layer (reserved for future Mapbox style parity; not fully implemented).

Link copied to clipboard
fun setPitch(pitch: Double)

Sets map pitch / tilt in degrees.

Link copied to clipboard

Shows or hides every map layer (and optional legend) belonging to code, including composite children.

Link copied to clipboard
open override fun setZoom(zoom: Double)

Animates or jumps the camera to the given Mapbox zoom.

Link copied to clipboard
open override fun shutdown()

Tears down this controller: cancels pending jobs, clears GL-stencil prefetch bookkeeping, cancels all Mapbox subscriptions (mapboxCancelables), removes the GL-stencil base OSM fetch layer, and clears MapController.layerHosts. Safe to call more than once.

Link copied to clipboard
fun trigger(type: String, data: Any? = null)

Dispatches a named event to listeners registered with on for type.

Link copied to clipboard

Ensures the invisible Mapbox fetch layer for GlStencilOsm exists and seeds a small tile neighborhood. Call after adding a stencil-only motorway mask layer and before the weather layer.