Map Legends

Legends can be displayed using the AWFWeatherMapLegendView class, which will handle rendering the individual legend components for the data layer types that have been added. In most cases, you will only want to add and remove legend items when data layers have been added and removed from the weather map. Therefore, you would need to implement the necessary delegate methods to be notified when data layers are added and removed:

#pragma mark - AWFWeatherMapDelegate

- (void)weatherMap:(AWFWeatherMap *)weatherMap didAddLayerType:(AWFLayerType)layerType {
	[self.legendView addLegendForLayerType:layerType];
}

- (void)weatherMap:(AWFWeatherMap *)weatherMap didRemoveLayerType:(AWFLayerType)layerType {
	[self.legendView removeLegendForLayerType:layerType];
}
extension MyWeatherMapViewController: AWFWeatherMapDelegate {
	
	public func weatherMap(_ weatherMap: AWFWeatherMap!, didAdd layerType: AWFLayerType) {
		self.legendView.addLegend(for: layerType)
	}
	
	public func weatherMap(_ weatherMap: AWFWeatherMap!, didRemove layerType: AWFLayerType) {
		self.legendView.removeLegend(for: layerType)
	}
}

After adding or removing a layer type’s legend to your legend view, you may want to call sizeToFit on the legend view to resize the view’s frame to fit the legends being displayed (specifically the height).

If you are using or subclassing AWFWeatherMapViewController then this legend view will automatically be handled for you. Legends will appear in a drop-down view from the top of your weather map for data layers that have a legend associated with it. Tapping this view or swiping down from the top of your weather map will slide down the legend view, whereas swiping up or tapping anywhere outside the legend view will slide it back up.

Last modified: November 02, 2017