Examples
Controlling map layer order

Controlling map layer order

When adding raster weather layers, such as radar or satellite, to your weather map using addSourceForLayerType:, they are rendered in the order in which they are added. So the last layer to be added will appear above all other layers.

You can have more control over the order of your raster weather layers using the weather map's Xweather Raster Maps layer manager, which is an instance of AWFAmpTileSourceProvider and accessible using the amp property of your AWFWeatherMap instance. This class provides several methods for adding and removing raster Maps layers on your weather map, including addRasterLayer: and addRasterLayer:atIndex:.

However, for more order control, this class also has methods allowing you to add or move layers above or below other layers, or move them to a specific index in the collection:

- (void)addRasterLayer:(AWFRasterMapLayer *)layer aboveLayer:(AWFRasterMapLayer *)otherLayer;
- (void)addRasterLayer:(AWFRasterMapLayer *)layer belowLayer:(AWFRasterMapLayer *)otherLayer;
- (void)addRasterLayerBelowAllLayers:(AWFRasterMapLayer *)layer;
- (void)bringRasterLayerToTop:(AWFRasterMapLayer *)layer;
- (void)pushRasterLayerToBottom:(AWFRasterMapLayer *)layer;
- (void)moveRasterLayer:(AWFRasterMapLayer *)layer toIndex:(NSInteger)index;
- (void)moveRasterLayer:(AWFRasterMapLayer *)layer aboveLayer:(AWFRasterMapLayer *)otherLayer;
- (void)moveRasterLayer:(AWFRasterMapLayer *)layer belowLayer:(AWFRasterMapLayer *)otherLayer;

For example, you will usually want to display radar above satellite and advisories. But these aren't always guaranteed to be inserted in the correct order, such as when your application has a toggle menu for turning layers on and off. One solution is to move radar to the top of the stack whenever a new Maps-specific raster layer gets added using the weatherMap:didAddLayerForType: method on AWFWeatherMapDelegate:

func weatherMap(_ weatherMap: AWFWeatherMap, didAddLayerForType layerType: AWFMapLayer) {
    guard let radarLayer = weatherMap.amp.rasterLayer(forLayerType: .radar) else { return }
    if AWFWeatherLayer.isAmp(layerType) {
        weatherMap.amp.bringRasterLayer(toTop: radarLayer)
    }
}

Alternatively, add the radar layer as an instance of AWFRasterMapLayer and either insert it at a specific index in the layer collection or above or below other layers:

let radarLayer = AWFRasterMapLayer(layerType: .radar)
if let satelliteLayer = weatherMap.amp.rasterLayer(forLayerType: .satellite) {
    weatherMap.amp.addRasterLayer(radarLayer, above: satelliteLayer)
} else {
    weatherMap.amp.addRasterLayer(radarLayer)
}