Create a Map (Mobile)

Instantiating a map

// create a new map and add it to the view hierarchy
let map = AirMapMapView(frame: view.bounds)
map.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(map)
private AirMapMapView mapView;                  // mapbox MapView wrapper
private AirMapMapView.DynamicConfiguration configuration;

mapView = view.findViewById(R.id.map_view);
mapView.onCreate(savedInstanceState);
mapView.addOnMapDataChangedListener(this);

mapView.getMapAsync(null);
configuration = new AirMapMapView.DynamicConfiguration(null, null, true);
mapView.configure(configuration);


 // Mapbox requires lifecycle
    @Override
    public void onStart() {
        super.onStart();
        mapView.onStart();
    }

    @Override
    public void onResume() {
        super.onResume();
        mapView.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        mapView.onPause();
    }

    @Override
    public void onStop() {
        super.onStop();
        mapView.onStop();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        mapView.onDestroy();

        mapView.removeOnMapDataChangedListener(this);
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        mapView.onLowMemory();
    }

Setting the Map Theme

The AirMap map view supports 4 different themes: Standard, Dark, Light, and Satellite

map.theme = .standard
// rotate map themes
mapView.rotateMapTheme();

// set map theme
mapView.setMapTheme(AirMapMapTheme theme);

Configuring the map's behavior

The map's behavior can be configured with one of the following behaviors:

  • Automatic
  • Dynamic
  • Manual

The AirMap map view defaults to use the Automatic configuration

Automatic

The map will be configured automatically. All required rulesets will be enabled and the default pick one rulesets will be enabled. None of the optional rulesets will be enabled except for "AirMap Recommended" rulesets.

map.configuration = .automatic
AirMapMapView.Configuration configuration = new AirMapMapView.AutomaticConfiguration();
mapView.configure(configuration);

Dynamic

The map will use the provided list of preferred ruleset identifiers to enable any optional and pick one rulesets as they are encountered. If enableRecommendedRulesets is false, none of the optional "AirMap Recommended" rulesets will be enabled, unless it is the only ruleset for a jurisdiction.

// determine which rulesets are preferred
let rulesetIds = ["usa_part_107", "can_sfoc_compliant"]

// configure the map with the preferred ruleset identifiers
map.configuration = .dynamic(
    preferredRulesetIds: rulesetIds,
    enableRecommendedRulesets: true
)
AirMapMapView.Configuration configuration = new AirMapMapView.DynamicConfiguration(@Nullable Set<String> preferredRulesetIds, @Nullable Set<String> unpreferredRulesetIds, boolean enableRecommendedRulesets);
mapView.configure(configuration);

Manual

The map will be configured with only the rulesets provided. It is the caller's responsibility to query the map for jurisdictions and make a determination as to which rulesets to display. The caller should reconfigure the map accordingly as the map's jurisdictions change.

// make a determination of which rulesets the map should be configured with
let activeRulesets = [...]

// pass the rulesets to the map
map.configuration = .manual(rulesets: activeRulesets)
AirMapMapView.Configuration configuration = new AirMapMapView.ManualConfiguration(List<AirMapRuleset> selectedRulesets);
mapView.configure(configuration);

Responding to map events

As the user interacts with the map and pans from one region to another, jurisdictions will be entered and exited. Developers, specifically those that use the manual configuration method, should register to receive notification of these events, reevaluate the jurisdictions/rulesets, and reconfigure the map as necessary.

Registering as an event handler

// register as the map's delegate
map.delegate = self
public class MapFragment extends Fragment implements AirMapMapView.OnMapDataChangeListener {
}

Handling events

class MyViewController: UIViewController {

    func airMapMapViewJurisdictionsDidChange(mapView: AirMapMapView, jurisdictions: [AirMapJurisdiction]) {
        
        print("JURISDICTIONS: ", jurisdictions.map { $0.name }.joined(separator: ", ") )
    }
    
    func airMapMapViewRegionDidChange(mapView: AirMapMapView, jurisdictions: [AirMapJurisdiction], activeRulesets: [AirMapRuleset]) {
        
        // Print out all the active rulesets the map is configured with
        print("ACTIVE RULESETS: ", activeRulesets.map { $0.name }.joined(separator: ", ") )
    }
    
}
@Override
public void onRulesetsChanged(List<AirMapRuleset> availableRulesets, List<AirMapRuleset> selectedRulesets) {}

@Override 
public void onAdvisoryStatusChanged(AirMapAirspaceStatus status) {}

@Override
public void onAdvisoryStatusLoading() {}

Updated 3 years ago

Create a Map (Mobile)


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.