Reference
Map Controller

Map Controller

A map controller acts as an adapter to a third-party mapping library and provides a consistent interface between the functionality of MapsGL and the underlying implementation of a third-party mapping library. All MapsGL-related data, such as data sources, weather layers, custom layers, and animation timeline information, is managed by the map controller.

Supported Mapping Libraries

MapsGL SDK for Apple Platforms current supports integration with the following third-party mapping libraries:

Library + VersionControllerAdapter Library
Mapbox Maps (opens in a new tab), v11.x.xMapboxMapControllerMapsGLMapbox
Mapbox Maps (opens in a new tab), v10.x.xMapbox10MapControllerMapsGLMapbox10

Read more about setting up and using a map controller with third-party mapping libraries.

Example

The following example creates a Mapbox Map instance and initializes a MapsGL MapController with the map:

import UIKit
import MapsGLMaps
@_spi(Experimental) import MapboxMaps
 
final class ViewController: UIViewController {
    private var mapView: MapView!
    private var mapController: MapController!
    private var cancellables: Set<AnyCancellable> = []
 
    override func viewDidLoad() {
        super.viewDidLoad()
 
        // Create a Mapbox map
        let cameraOptions = CameraOptions(
            center: CLLocationCoordinate2D(latitude: 39.654, longitude: -93.102),
            zoom: 5)
        let options = MapInitOptions(cameraOptions: cameraOptions)
 
        mapView = MapView(frame: view.bounds, mapInitOptions: options)
        try! mapView.mapboxMap.setProjection(.init(name: .mercator)) // Set 2D map projection
        mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        view.addSubview(mapView)
 
        // Create a MapsGL map controller
        let xweatherAccount = XweatherAccount(id: "CLIENT_ID", secret: "CLIENT_SECRET")
        mapController = MapboxMapController(map: mapView, account: xweatherAccount)
 
        // Once the map has completed initial load…
        mapController.onLoad.observe { _ in
 
            // Add weather layers...
            
        }.store(in: &cancellables)
    }
}

Refer to the MapController API reference for more information about the available properties and methods.