Weather Maps

The weather map feature requires you to include the com.aerisweather.aeris.maps.AerisMapViewContainer in your layout XML where you would like the map to appear. The map includes support for AerisWeather Maps layers (radar, satellite, etc).  Point data (storm cells, storm reports) and Polygon data (convective, drought, fire). There are also features to to allow animation of these overlays and more.

Creating a Weather Map

To begin, we need to add the com.aerisweather.aeris.maps.AerisMapContainerView to your layout XML.

fragment_interactive_maps.xml


LinearLayout 
        
xmlns:android="http://schemas.android.com/apk/res/android"        
    android:layout_width="match_parent"         
    android:layout_height="match_parent"         
    android:orientation="vertical"> 

    <com.aerisweather.aeris.maps.AerisMapContainerView 
            android:id="@+id/mapView" 
            android:layout_width="match_parent"
            android:layout_height="match_parent"/> 

</LinearLayout>

The AerisWeather MapContainerView contains a reference to the AerisWeather MapView class, which is derived from GoogleMapView. This will be the main class used to access your weather map, as well as the AnimationView used to draw the images used for animating the map.

Initializing Your Map

In order to initialize the map and the various overlay controlls and settings you will need to import the AerisWeather MapView within your code. Notice too that we must implement the OnMapReadyCallback function. This is how GoogleMaps tells us that the map is ready for us to work with.

MyMapFragment.java


package com.example.fragment

public class MyMapFragment extends Fragment implements
        OnAerisMapLongClickListener, AerisCallback, ObservationsTaskCallback,
        OnAerisMarkerInfoWindowClickListener, RefreshInterface, OnMapReadyCallback

{
    private LocationHelper m_locHelper;
    private Marker m_marker;
    private TemperatureWindowAdapter m_infoAdapter;
    private static final int REQUEST_PERMISSIONS = 0;
    LayoutInflater m_inflater;
    ViewGroup m_container;
    Bundle m_savedInstanceState;
    GoogleMap m_googleMap;
    protected AerisMapView m_aerisMapView;
    private AerisMapOptions m_mapOptions = null;
    private AerisAmp m_aerisAmp;
    private boolean m_isMapReady = false;
    private boolean m_isAmpReady = false;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        m_inflater = inflater;
        m_container = container;
        m_savedInstanceState = savedInstanceState;

        View view = inflater.inflate(R.layout.fragment_interactive_maps, container, false);
        AerisMapContainerView mapContainer = (AerisMapContainerView) view.findViewById(R.id.mapView);
        m_aerisMapView = mapContainer.getAerisMapView();
        m_aerisMapView.onCreate(savedInstanceState);

        //create an instance of the AerisAMP class
        m_aerisAmp = new AerisAmp(getString(R.string.aerisapi_client_id), getString(R.string.aerisapi_client_secret));

        //start the task to get the AMP layers
        try
        {
            //get all the possible layers, then get permissions from the API and generate a list of permissible layers

            new AerisAmpGetLayersTask(new GetLayersTaskCallback(), m_aerisAmp).execute().get();
        }
        catch (Exception ex)
        {
            String s = ex.getMessage();

            //if the task fails, keep going without AMP layers
        }
        return view;
    }

 

When the map is ready, our callback is fired and we can continue with initializing the map as needed.

@Override
    public void onMapReady(GoogleMap googleMap)
    {
        m_isMapReady = true;
        m_googleMap = googleMap;
        m_aerisMapView.init(googleMap);
        if (m_isAmpReady)
        {
            initMap();
        }
    }

Using Layers

AerisWeather Android maps can be customized with many different layers, even more so with the addition of the AerisWeather Maps

 

Point and Polygon Data

To add a point or polygon layer to the map, we call the addLayer method on the AerisMapView instance, such as:


//point data - show the storm reports from the past 24 hours
m_aerisMapView.addLayer(AerisPointData.STORM_REPORTS);

//polygons 
m_aerisMapView.addLayer(AerisPolygonData.FIRE_OUTLOOK);

or retrieve the layers from the device's saved preferences:


//saved point data
m_aerisMapView.addLayer(m_mapOptions.getPointData());

//saved polygons 
m_aerisMapView.addLayer(m_mapOptions.getPolygonData();

To remove point and polygon layers from your map:


// remove point data layer
aerisMapView.removePointsLayer();
// remove point data layer
aerisMapView.removePolygonLayer(); 

 

AerisWeather Maps Layers

Displaying AerisWeather Maps weather layers on your map can be achieved in a few different ways.

Create an AerisWeather AMPLayer object for each desired AMP layer, and add them to the parent AerisWeather AMP object.


AerisAmpLayer aerisAmpLayer = new AerisAmpLayer(); //creates a radar layer by default
aerisAMP.setLayer(aerisAmpLayer);

or simply passing in the name or id of an existing AMP layer:


//add the radar layer
aerisAMP.setLayerFromName("radar");

//add the satellite layer
aerisAMP.setLayerFromId("sat");

or we can just set the default layers:


//set default layers/data
m_mapOptions.setDefaultAmpLayers();

To remove an AMP layer simply get the AerisWeather AmpLayer from the AerisAmp object's active layer list and pass that layer to the removeAmpLayer(AerisAmpLayer) method.


ArrayList layers = aerisAmp.getActiveMapLayers();
for (AerisAmpLayer layer: layers)
{
    if (layer.getLayerId() == "sat")
        aerisAmp.removeLayer(layer);
}

Last modified: July 27, 2021