Weather Data

Weather Data

The AerisWeather MapsGL SDK includes a variety of pre-configured and pre-styled weather layers for you to include in your maps, such as radar, satellite, wind speeds, and wind particles. Additionally, you have complete control over their styling and can fully customize them for your needs.

Built-in weather layers are referenced by their weather layer code. Refer to our list of supported weather layers (opens in a new tab) and their codes when using them within the MapsGL SDK.

Adding weather layers

To add a weather layer to your map, just use the addWeatherLayer(for:) method on your map controller instance:

try controller.addWeatherLayer(for: .temperatures)
Map with temperatures

It's also easy to add multiple weather layers at once:

// adding each layer code separately
try controller.addWeatherLayer(for: .dewPoint)
try controller.addWeatherLayer(for: .windParticles)
 
// or iterating an array of weather layer codes
let weatherCodes: [WeatherService.LayerCode] = [.dewPoint, .windParticles]
for code in weatherCodes {
    try controller.addWeatherLayer(for: code)
}
Map with dew point and wind particles

Using this simple method will use the default styling and configuration for each layer provided by the SDK. However, since layers are fully customizable with MapsGL, you may decide you want to change the visual appearance of one or more weather layer when adding it to your map.

Review our weather layer styling (opens in a new tab) guide for complete details regarding weather layer customizations.

Getting active weather layers

Weather layers are given a unique layer identifier internally when added to a map that takes into account any customizations that may have been provided. Therefore, you cannot use getLayer(id:) to retrieve a weather layer using its weather layer code (opens in a new tab). Instead, use the weatherLayer(for:) method to retrieve a weather layer by its weather layer code:

let temperaturesLayer = controller.weatherLayer(for: .temperatures)

If the layer already exists on the map, the above will return the existing layer instance which you can then use to get additional information about the layer itself, such as its generated unique identifier to use when adding another layer relative to its position in the layer stack:

if let temperaturesLayer = controller.weatherLayer(for: .temperatures) {
    try controller.addWeatherLayer(for: .windParticles, beforeId: temperaturesLayer.id)
}

Removing weather layers

Removing weather layers from the map is similar to adding them. To remove a weather layer from your map, just use removeWeatherLayer(for:):

try controller.removeWeatherLayer(for: .temperatures)

This will completely remove the layer from the map and dispose of all resources associated with it as needed. If you only want to hide the layer such as when toggling it on and off, use setWeatherLayerVisibility(for:visible:) instead. See the section on toggling weather layers for more details.

Similarly, you can also remove multiple weather layers easily:

// removing each layer code separately
try controller.removeWeatherLayer(for: .dewPoint)
try controller.removeWeatherLayer(for: .windParticles)
 
// or iterating an array of weather layer codes
let weatherCodes: [WeatherService.LayerCode] = [.dewPoint, .windParticles]
for code in weatherCodes {
    try controller.removeWeatherLayer(for: code)
}

Toggling weather layers

If you are only wanting to toggle weather layers on and off, as in the case of a button click, use MapController#setWeatherLayerVisibility with the visibility argument set to false instead of removeWeatherLayer once the layer has been added to the map. This will be more efficient as layer and data source resources don't get disposed of nor do they have to be recreated when setting the weather layer to visible again.

When you're ready to add the layer back to the map, call setWeatherLayerVisibility again with the visibility argument as true instead of addWeatherLayer.

For example, to toggle the visibility of the temperatures layer, you can do one of the following:

// show the layer if it is hidden
controller.setWeatherLayerVisibility(for: .temperatures, visible: true)
 
// or hide it if it is visible
controller.setWeatherLayerVisibility(for: .temperatures, visible: false)
 
// toggle the visibility of the layer based on the current state of `isVisible`
if let temperaturesLayer = controller.weatherLayer(for: .temperatures) {
    controller.setWeatherLayerVisibility(for: .temperatures, visible: !temperaturesLayer.isVisible)
}

Overriding defaults

While we have provided some default styling for built-in weather layers, you may want to fully customize them to fit the identity and style of your application or to tell a different story with the same data. Our weather layers are fully customizable simply by providing your desired configuration overrides.

You can override the default configuration for weather layers by updating the layer configuration before adding it to the map. The following example shows how to override the default configuration for a weather layer:

var tempsConfig = WeatherService.Temperatures(service: controller.service)
tempsConfig.layer.paint.sample.opacity = 0.5
try controller.addWeatherLayer(config: tempsConfig)

Alternatively, you can configure and pass the layer directly when adding it to the map:

try controller.addWeatherLayer(config: {
    var config = WeatherService.Temperatures(service: controller.service)
    config.layer.paint.sample.opacity = 0.5
    return config
}())

Note that when overriding the default configuration, you cannot add a weather layer using the addWeatherLayer(for:) method. Instead, you must use the addWeatherLayer(config:) method with your custom configuration to add the layer to the map.