MapsGL - Map Controller
A map controller acts as an adapter to a third-party mapping library and provides a consistent interface between the functionality of MapsGL and the underlying implementation of a third-party mapping library. All MapsGL-related data, such as data sources, weather layers, custom layers, and animation timeline information, is managed by the map controller.
Read more about setting up and using a map controller with third-party mapping libraries.
Example
The following example creates a Mapbox Map instance and initializes a MapsGL MapController with the map:
// Create the map instance using third-party mapping library
mapboxgl.accessToken = 'MAPBOX_TOKEN';
const map = new mapboxgl.Map({
container: document.getElementById('map'),
style: 'mapbox://styles/mapbox/light-v11',
center: [-74.5, 40],
zoom: 3
});
map.addControl(new mapboxgl.NavigationControl(), 'bottom-left');
// Create an Account instance with our AerisWeather account access keys
const account = new aerisweather.mapsgl.Account('CLIENT_ID', 'CLIENT_SECRET');
// Create a MapController instance and provide the above `map` and `account`
// instances and desired configuration options
const controller = new aerisweather.mapsgl.MapboxMapController(map, {
account: account,
animation: {
repeat: true
},
units: {
temperature: 'F' | 'C',
speed: 'mph' | 'km/h' | 'm/s' | 'kts',
pressure: 'mb' | 'inHg' | 'hPa' | 'Pa',
distance: 'mi' | 'km' | 'ft' | 'm',
height: 'ft' | 'm',
precipitation: 'in' | 'mm' | 'cm' | 'm' | 'ft',
snowfall: 'in' | 'mm' | 'cm' | 'm' | 'ft',
direction: '°',
time: 'hr' | 'min' | 'sec' | 'ms',
rate: 'in/hr' | 'mm/hr' | 'mm/sec' | 'dBZ',
concentration: 'ppm' | 'ug/m3',
ratio: '%'
}
});Configuration
The following configuration options are supported when instantiating MapController instances.
| Option | Description | Default |
|---|---|---|
account | Type: Account (required)An Account instance configured with your AerisWeather client id and secret keys for the application. | |
animation | Type: Record<string, any> (optional)An object containing configuration options for the map controller’s timeline. Review the timeline reference documentation for more information about the available options. | |
animation.pauseWhileLoading | Type: boolean (optional)Whether to pause the timeline animation while data required for animating is loading. When true, then the entire timeline will pause animation playback while any layers are loading data required for animating. | |
animation.resumeOnMoveEnd | Type: boolean (optional)Whether to resume the timeline animation after a move end event if the animation was playing before the map move started through a pan or zoom. | |
slots | Type: SlotRegistryOptions (optional)Layer ordering slot configuration. Slots are named bands stacked bottom → top (underlay, inlay, text, overlay). On Mapbox / MapLibre classic styles, underlay is pinned below the bottom-most admin boundary. On Mapbox Standard styles, underlay maps to the native middle band and other slots to top. | |
slots.slots | Type: Record<string, { beforeId?: string; mapboxSlot?: 'bottom' | 'middle' | 'top'; }> (optional)Partial overrides for built-in or custom slots, keyed by slot id. beforeId pins that slot below a host style layer (classic Mapbox / MapLibre). mapboxSlot targets a Mapbox Standard band (bottom / middle / top). | |
slots.typeMapping | Type: Record<string, string> (optional)Overrides for the default layer-type → slot mapping (for example { fill: 'inlay' }). Unmapped types fall back to inlay. | |
slots.stackRanks | Type: Record<string, number> (optional)Default within-slot stack ranks keyed by weather layer code / stack key. Higher paints above siblings. Merged over built-in defaults. | |
slots.resolveStackRank | Type: (ctx: { layerId: string; stackKey?: string; type?: string; }) => number | undefined (optional)Custom rank resolver. Return a finite number to override, or undefined to fall through to stackRanks / built-in rules. | |
units | Type: Record<string, string> (optional)An object containing configuration options for the units used for various measurements and displayed data values on the map. This also controls the units displayed in legends for any active layers in the legend control.See the list of possible unit values below. | |
Map units
The following units are supported for the map controller’s units configuration:
| Type | Unit Options | Description | Default |
|---|---|---|---|
temperature | F, C | required | F |
speed | mph, km/h, m/s, kts | required | mph |
pressure | mb, inHg, hPa, Pa | required | inHg |
distance | mi, km, ft, m | required | mi |
height | ft, m | required | ft |
precipitation | in, mm, cm, m, ft | required | in |
snowfall | in, mm, cm, m, ft | required | in |
direction | ° | required | ° |
time | hr, min, sec, ms | required | hr |
rate | in/hr, mm/hr, mm/sec, dBZ | required | in/hr |
concentration | ppm, ug/m^3 | required | ug/m^3 |
ratio | % | required | % |
Properties
The following properties are available on MapController instances and subclasses:
| Option | Description | Default |
|---|---|---|
account | Type: Account ()The Xweather account credentials used for weather service data. | |
map | Type: (varies) ()The underlying map instance whose type will vary depending on the mapping library being used. | |
container | Type: “ ()The DOM element that contains the map. | |
context | Type: Context ()The context used for managing the map’s WebGL context. | |
timeline | Type: Timeline ()The timeline used for managing animation and time series data. | |
sources | Type: Array<DataSource> ()Returns an array of active data sources that have been added to the map. | |
sourceIds | Type: Array<string> ()Returns an array of identifiers for the active data sources that have been added to the map. | |
layers | Type: Array<WebGLLayer> ()Returns an array of active layers that have been added to the map. | |
layerIds | Type: Array<string> ()Returns an array of identifiers for the active layers that have been added to the map. | |
controls | Type: { legend: LegendControl; dataInspector: DataInspectorControl; } ()Returns the set of controls that have been added to the map. | |
weatherProvider | Type: WeatherLayerProvider ()Weather service provider for managing weather layer configurations and data. Use getSupportedLayerIds and getLayerMetadata to list layers available in this SDK build. | |
weatherLayerIds | Type: Array<string> ()Returns an array of weather layer identifiers that have been added to the map. | |
isReady | Type: boolean ()Returns whether the map controller has been initialized and is ready for use. If false, then the map controller is still in the process of loading and/or initializing and you will need to add an event listener for the load event before performing actions with the map or controller. | |
libraryInfo | Type: Record<string, any> ()Returns metadata and version information about the mapping library being used. | |
Methods
The following methods are available on MapController instances.
Map State
getSize(): { width: number; height: number; }setSize(size: { width: number; height: number; })getCenter(): { lat: number; lon: number; }setCenter({ lat: number; lon: number; })getBounds(): { north: number; west: number; east: number; south: number; }getZoom(): numbersetZoom(zoom: number)getBearing(): numbergetPitch(): numbergetFov(): numbergetUnits(): MapUnitssetUnits(units: Partial<MapUnits>)setUnitsForSystem(system: 'metric' | 'imperial' | 'custom')toggleFullscreen(): voidManaging Data
hasWeatherLayer(id: string): booleangetWeatherLayer(id: string): WebGLLayer | Array<WebGLLayer> | undefinedaddWeatherLayer(id: string, overrides?: Record<string, any>, beforeId?: string): WebGLLayer | Array<WebGLLayer> | undefinedremoveWeatherLayer(id: string): voidsetWeatherLayerVisibility(id: string, visible: boolean): voidWeather Provider
Call these on controller.weatherProvider after the map has loaded. See discovering weather layers.
weatherProvider.getSupportedLayerIds(): string[]weatherProvider.getLayerMetadata(): Promise<WeatherLayerMetadata[]>addDayNightOverlay(options?: { opacity?: number }): voidremoveDayNightOverlay(): voidhasSource(id: string): booleanhasLayer(id: string): booleangetSource(id: string): DataSourcegetLayer(id: string): WebGLLayeraddSource(id: string, config: SourceSpecification | DataSource): DataSourceaddLayer(id: string, config: LayerSpecification | WebGLLayer, beforeId?: string): WebGLLayermoveLayer(id: string, beforeId?: string): WebGLLayerremoveSource(id: string): voidremoveLayer(id: string): voidsetRefreshInterval(minutes: number, advanceToNow = true): voidLayer Ordering
Built-in slots, bottom → top: underlay, inlay, text, overlay. Higher stackRank paints above siblings in the same slot. Particle layers use inlay (not a separate slot). See layer ordering for the type → slot map, built-in ranks, host-ceiling behavior, and Mapbox Standard bands.
Slot and rank methods take a MapsGL layer id, not a weather layer code. Use the instance returned by addWeatherLayer / addLayer, or getWeatherLayer / getLayer. Composite weather codes return an array of layers — iterate when moving them.
defineSlot(id: string, definition?: { beforeId?: string; mapboxSlot?: 'bottom' | 'middle' | 'top'; }): SlotDefinitionsetSlotBeforeId(slotId: string, beforeId?: string | null): voidsetSlotOrder(ids: string[]): voidlistSlots(): SlotDefinition[]getSlotHostBeforeId(slotId: string): string | undefinedgetSlot(layerId: string): string | undefinedmoveLayerToSlot(layerId: string, slotId: string): voidgetStackRank(layerId: string): number | undefinedsetStackRank(layerId: string, rank: number): voidsetCodeStackRank(code: string, rank: number): voidMapbox Standard slots
These methods exist on MapboxMapController only. They pin MapsGL ordering slots into native Mapbox Standard bands (bottom / middle / top). MapLibre, Google Maps, and Leaflet do not expose these bands — MapLibre no-ops the methods. See Mapbox Standard styles.
When a slot has no explicit mapboxSlot, the adapter defaults are underlay → middle (below labels) and every other MapsGL slot → top (above labels).
setSlotMapboxSlot(slotId: string, mapboxSlot?: 'bottom' | 'middle' | 'top' | null): voidgetSlotMapboxSlot(slotId: string): 'bottom' | 'middle' | 'top' | undefinedusesMapboxStandardSlots(): booleanlistMapboxStandardSlots(): Array<'bottom' | 'middle' | 'top'>Layers
setPaintProperty(layerId: string, property: string, value: any)setMask(layerId: string, mask?: LayerMaskConfiguration | LayerMaskSpecification | string | null): voidQuerying Features
query(coord: { lat: number; lon: number; }): Record<string, any>Other
dispose(): voidEvents
The following events are triggered by MapController instances.
loadunloadresizeclickdblclickmousedownmouseupmouseovermouseoutmousemovezoomzoom:startzoom:endmovemove:startmove:endload:startload:completesource:addlayer:addlayer:showlayer:hidelayer:load:startlayer:load:progresslayer:load:completesource:removelayer:remove