All skills
mapbox avatar

/mapbox-ios-patterns

@f5ae7de official
by mapboxmapbox/mapbox-agent-skills80 stars
17

Official integration patterns for Mapbox Maps SDK on iOS. Covers installation, adding markers, user location, custom data, styles, camera control, and featureset interactions. Based on official Mapbox documentation.

Use this Skill: https://skilld.dev/gh/mapbox/mapbox-agent-skills/mapbox-ios-patterns

This session only. Nothing lands on disk.

referencesinteractions.md

≈927 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Interactions: Featureset, Custom Layer Taps, Long Press, Gestures


Featureset Interactions (Recommended)

The modern Interactions API allows handling taps on map features with typed feature access. Works with Standard Style predefined featuresets like POIs, buildings, and place labels.

SwiftUI Pattern:

import SwiftUI
import MapboxMaps

struct MapView: View {
    @State private var viewport: Viewport = .camera(
        center: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194),
        zoom: 12
    )
    @State private var selectedBuildings = [StandardBuildingsFeature]()

    var body: some View {
        Map(viewport: $viewport) {
            // Tap on POI features
            TapInteraction(.standardPoi) { poi, context in
                print("Tapped POI: \(poi.name ?? "Unknown")")
                return true // Stop propagation
            }

            // Tap on buildings and collect selected buildings
            TapInteraction(.standardBuildings) { building, context in
                print("Tapped building")
                selectedBuildings.append(building)
                return true
            }

            // Apply feature state to selected buildings (highlighting)
            ForEvery(selectedBuildings, id: \.id) { building in
                FeatureState(building, .init(select: true))
            }
        }
        .mapStyle(.standard)
    }
}

UIKit Pattern:

import MapboxMaps
import Combine

class MapViewController: UIViewController {
    private var mapView: MapView!
    private var cancelables = Set<AnyCancellable>()

    override func viewDidLoad() {
        super.viewDidLoad()
        setupMap()
        setupInteractions()
    }

    func setupInteractions() {
        // Tap on POI features
        let poiToken = mapView.mapboxMap.addInteraction(
            TapInteraction(.standardPoi) { [weak self] poi, context in
                print("Tapped POI: \(poi.name ?? "Unknown")")
                return true
            }
        )

        // Tap on buildings
        let buildingToken = mapView.mapboxMap.addInteraction(
            TapInteraction(.standardBuildings) { [weak self] building, context in
                print("Tapped building")

                // Highlight the building using feature state
                self?.mapView.mapboxMap.setFeatureState(
                    building,
                    state: ["select": true]
                )
                return true
            }
        )

        // Store tokens to keep interactions active
        // Cancel tokens when done: poiToken.cancel()
    }
}

Tap on Custom Layers

let token = mapView.mapboxMap.addInteraction(
    TapInteraction(.layer("custom-layer-id")) { feature, context in
        if let properties = feature.properties {
            print("Feature properties: \(properties)")
        }
        return true
    }
)

Long Press Interactions

let token = mapView.mapboxMap.addInteraction(
    LongPressInteraction(.standardPoi) { poi, context in
        print("Long pressed POI: \(poi.name ?? "Unknown")")
        return true
    }
)

Handle Map Taps (Empty Space)

// UIKit
mapView.gestures.onMapTap.observe { [weak self] context in
    let coordinate = context.coordinate
    print("Tapped map at: \(coordinate.latitude), \(coordinate.longitude)")
}.store(in: &cancelables)

Gesture Configuration

// Disable specific gestures
mapView.gestures.options.pitchEnabled = false
mapView.gestures.options.rotateEnabled = false

// Configure zoom limits
mapView.mapboxMap.setCamera(to: CameraOptions(
    zoom: 12,
    minZoom: 10,
    maxZoom: 16
))

Source: SKILL.md on GitHub

1 warning17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    The skill provides official integration patterns for the Mapbox Maps SDK on iOS, including installation, markers, location tracking, and custom data. It follows standard iOS development practices and utilizes official Mapbox resources. No security issues or malicious behaviors were detected.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer7mo

    2/2 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at f5ae7de. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 9 hours ago.

Activeupdated 2 months ago
  • mapbox
  • ios
  • swift
  • swiftui
  • uikit
  • maps
  • annotations
  • geojson
  • location-tracking
  • camera-control

README badge

README badge for mapbox/mapbox-agent-skills/mapbox-ios-patterns

Installs and configures Mapbox Maps SDK v11 on iOS with Swift and SwiftUI, covering markers, user location, custom data layers, camera control, and feature interactions. Targets both SwiftUI and UIKit workflows and includes performance guidance for annotation management and style optimization.

Generated from the current SKILL.md.

Does this skill work with both SwiftUI and UIKit?
Yes. The skill covers both frameworks. Some APIs like `Marker` are SwiftUI-only, while `PointAnnotation` and `ViewAnnotation` work in both SwiftUI and UIKit.
What iOS version is required?
iOS 14 or later, with Xcode 15+ and Swift 5.9+. Mapbox Maps SDK v11 is the target version.
How do I handle hundreds or thousands of markers?
Use a `GeoJSONSource` with a `SymbolLayer` instead of individual annotations. The Markers and PointAnnotation APIs scale to about 100 markers; for larger datasets, load GeoJSON directly into a style layer, which scales to thousands of features and supports clustering.
Do I need a paid Mapbox account?
No. A free Mapbox account is sufficient to get an access token and use the Maps SDK.
How do I show the user's location on the map?
Add the location permission string to Info.plist, request `requestWhenInUseAuthorization()` from CLLocationManager, then enable the location puck with `mapView.location.options.puckType = .puck2D()`.

Generated from the current SKILL.md. These answers refresh after source changes.