Globe with milkyway and halo - Swift SDK

The following example demonstrates how to create a globe map, customize the map background to achieve a Milky Way effect, and add a halo around the Earth.

This option applies only when used with the globe projection.


import SwiftUI
import CoreLocation
import MapTilerSDK

struct ContentView: View {
  init() {
    // Best practice: set the MapTiler API key on app startup instead on init
    // Replace with your MapTiler API key
    Task { await MTConfig.shared.setAPIKey("MY_API_KEY") }
  }

  @State private var mapView = MTMapView(
    options: MTMapOptions(
      center: CLLocationCoordinate2D(latitude: 20, longitude: 0),
      zoom: 1.2,
      projection: .globe,
      space: .config(MTSpace(preset: .milkywayColored)),
      halo: .enabled(true)
    )
  )

  var body: some View {
    MTMapViewContainer(map: mapView)
      .referenceStyle(.satellite)
  }
}