Managing Data Sources

Managing Map Data Sources

A weather map can display a variety of different weather data sources at once, such as radar, satellte, earthquakes and storm cells. You can complete control over which data sources appear on your weather map and can add or remove them at any time while your application is running.

Data Types

There are three primary data types for a weather map: raster/tile, point and shape:

  • Raster/Tile: A raster image or tile layer, such as radar or temperatures.
  • Point: A series of map annotations representing point data, such as earthquakes or storm reports.
  • Shape: Vector polyline and/or polygon data, such as convective outlooks.

Refer to AWFMapLayer and the associated constants (Objective-C) or enumerated values (Swift) for the supported raster, point and shape types.

This does not include point or shape layer types as their data comes from the Xweather Weather API and does not use Maps layers.

Adding Data Sources

To add a new data source to your weather map, you need to create your source instance, which may be an instance of AWFTileSource, AWFPointSource, or AWFShapeSource depending on the type of data you want to display. You'll also need to know the layer type that corresponds to the dataset you want to add, which will either by an AWFMapLayer, AWFMapLayer or AWFMapLayer value:

let radarSource = AWFTileSource(layerType: .radar)

Alternatively, an easier method to adding data sources to your weather map is to just add them using the associated layer type and letting AWFWeatherMap setup the source objects accordingly:

weatherMap.addSource(forLayerType: .radar)

You can also add multiple data sources at once:

// add sources by instances
weatherMap.addSources([radarSource, advisoriesSource])
// add sources by layer types
weatherMap.addSources(forLayerTypes: [.radar, .advisories])

Working With Xweather Raster Maps Layers

A weather map instance will automatically handle raster Xweather Raster Maps content for basic usage, such as adding and removing layers, using the AWFMapLayer type. While this works in most use cases, you may want to use the more advanced Maps features, such as controlling opacity (opens in a new tab), adding filters (opens in a new tab) or including text labels.

To learn more about how to work with these advanced Raster Maps features, check out our Using Raster Maps Features guide.

Removing Data Sources

Removing data sources is similar to adding them by passing in the data source instance you want to remove:


Or, you can remove the data source associated with a specific layer type:

weatherMap.removeSource(forLayerType: .radar)

If the weather map does not contain the data source or a data source for the specified layer type, then this method will do nothing.

You can also remove multiple data sources at once:

// remove sources by instances
weatherMap.removeSources([radarSource, advisoriesSource])
// remove sources by layer types
weatherMap.removeSources(forLayerTypes: [.radar, .advisories])

Working With Data Sources

When working with your weather map, you may need to check if a data source is currently active. To do so, you can either use a data source instance or layer type:

// check by passing a data source instance
let isRadarActive = weatherMap.sources.contains(radarSource)
// check using a layer type
let isRadarActive = weatherMap.containsSource(forLayerType: .radar)

You can also return the data source instance associated for a particular layer type if it exists on the weather map:

let source = weatherMap.source(forLayerType: .radar)

Once a weather map has already been initialized and data sources added, you can force the map to refresh a single or all data sources. This is often useful when your application returns from the background and your weather map needs to update its content. Use the refreshAllSources method on your weather map:


You can also configure your weather map to automatically refresh its data sources at a regular interval. Just call enableAutoRefresh to start the refresh timer, typically when the view containing your weather map appears. Then make sure to call disableAutoRefresh when your weather map is no longer visible in your application:

override func viewDidAppear(_ animated: Bool) {
override func viewWillDisappear(_ animated: Bool) {

Refer to the refreshInterval documentation on AWFWeatherMapConfig for more information regarding this setting.