← 返回 Skills 市场
🔌

Mapbox iOS Patterns

作者 Mapbox · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
99
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install mapbox-ios-patterns
功能描述
Official integration patterns for Mapbox Maps SDK on iOS. Covers installation, adding markers, user location, custom data, styles, camera control, and featur...
使用说明 (SKILL.md)

Mapbox iOS Integration Patterns

Official patterns for integrating Mapbox Maps SDK v11 on iOS with Swift, SwiftUI, and UIKit.

Use this skill when:

  • Installing and configuring Mapbox Maps SDK for iOS
  • Adding markers and annotations to maps
  • Showing user location and tracking with camera
  • Adding custom data (GeoJSON) to maps
  • Working with map styles, camera, or user interaction
  • Handling feature interactions and taps

Official Resources:


Installation & Setup

Requirements

  • iOS 12+
  • Xcode 15+
  • Swift 5.9+
  • Free Mapbox account

Step 1: Configure Access Token

Add your public token to Info.plist:

\x3Ckey>MBXAccessToken\x3C/key>
\x3Cstring>pk.your_mapbox_token_here\x3C/string>

Get your token: Sign in at mapbox.com

Step 2: Add Swift Package Dependency

  1. File → Add Package Dependencies
  2. Enter URL: https://github.com/mapbox/mapbox-maps-ios.git
  3. Version: "Up to Next Major" from 11.0.0
  4. Verify four dependencies appear: MapboxCommon, MapboxCoreMaps, MapboxMaps, Turf

Alternative: CocoaPods or direct download (install guide)


Map Initialization

SwiftUI Pattern (iOS 13+)

Basic map:

import SwiftUI
import MapboxMaps

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

    var body: some View {
        Map(viewport: $viewport)
            .mapStyle(.standard)
    }
}

With ornaments:

Map(viewport: $viewport)
    .mapStyle(.standard)
    .ornamentOptions(OrnamentOptions(
        scaleBar: .init(visibility: .visible),
        compass: .init(visibility: .adaptive),
        logo: .init(position: .bottomLeading)
    ))

UIKit Pattern

import UIKit
import MapboxMaps

class MapViewController: UIViewController {
    private var mapView: MapView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let options = MapInitOptions(
            cameraOptions: CameraOptions(
                center: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194),
                zoom: 12
            )
        )

        mapView = MapView(frame: view.bounds, mapInitOptions: options)
        mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        view.addSubview(mapView)

        mapView.mapboxMap.loadStyle(.standard)
    }
}

Add Markers (Point Annotations)

Point annotations are the most common way to mark locations on the map.

SwiftUI:

Map(viewport: $viewport) {
    PointAnnotation(coordinate: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194))
        .iconImage("custom-marker")
}

UIKit:

// Create annotation manager (once, reuse for updates)
var pointAnnotationManager = mapView.annotations.makePointAnnotationManager()

// Create marker
var annotation = PointAnnotation(coordinate: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194))
annotation.image = .init(image: UIImage(named: "marker")!, name: "marker")
annotation.iconAnchor = .bottom

// Add to map
pointAnnotationManager.annotations = [annotation]

Multiple markers:

let locations = [
    CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194),
    CLLocationCoordinate2D(latitude: 37.7849, longitude: -122.4094),
    CLLocationCoordinate2D(latitude: 37.7649, longitude: -122.4294)
]

let annotations = locations.map { coordinate in
    var annotation = PointAnnotation(coordinate: coordinate)
    annotation.image = .init(image: UIImage(named: "marker")!, name: "marker")
    return annotation
}

pointAnnotationManager.annotations = annotations

Show User Location

Step 1: Add location permission to Info.plist:

\x3Ckey>NSLocationWhenInUseUsageDescription\x3C/key>
\x3Cstring>Show your location on the map\x3C/string>

Step 2: Request permissions and show location:

import CoreLocation

// Request permissions
let locationManager = CLLocationManager()
locationManager.requestWhenInUseAuthorization()

// Show user location puck
mapView.location.options.puckType = .puck2D()
mapView.location.options.puckBearingEnabled = true

Performance Best Practices

Reuse Annotation Managers

// ❌ Don't create new managers repeatedly
func updateMarkers() {
    let manager = mapView.annotations.makePointAnnotationManager()
    manager.annotations = markers
}

// ✅ Create once, reuse
let pointAnnotationManager: PointAnnotationManager

init() {
    pointAnnotationManager = mapView.annotations.makePointAnnotationManager()
}

func updateMarkers() {
    pointAnnotationManager.annotations = markers
}

Batch Annotation Updates

// ✅ Update all at once
pointAnnotationManager.annotations = newAnnotations

// ❌ Don't update one by one
for annotation in newAnnotations {
    pointAnnotationManager.annotations.append(annotation)
}

Memory Management

// Use weak self in closures
mapView.gestures.onMapTap.observe { [weak self] context in
    self?.handleTap(context.coordinate)
}.store(in: &cancelables)

// Clean up on deinit
deinit {
    cancelables.forEach { $0.cancel() }
}

Use Standard Style

// ✅ Standard style is optimized and recommended
.mapStyle(.standard)

// Use other styles only when needed for specific use cases
.mapStyle(.standardSatellite) // Satellite imagery

Troubleshooting

Map Not Displaying

Check:

  1. MBXAccessToken in Info.plist
  2. ✅ Token is valid (test at mapbox.com)
  3. ✅ MapboxMaps framework imported
  4. ✅ MapView added to view hierarchy
  5. ✅ Correct frame/constraints set

Style Not Loading

mapView.mapboxMap.onStyleLoaded.observe { [weak self] _ in
    print("Style loaded successfully")
    // Add layers and sources here
}.store(in: &cancelables)

Performance Issues

  • Use .standard style (recommended and optimized)
  • Limit visible annotations to viewport
  • Reuse annotation managers
  • Avoid frequent style reloads
  • Batch annotation updates

Reference Files

Load these references when the task requires deeper patterns:

  • references/annotations.md — Circle, Polyline, Polygon Annotations
  • references/location-tracking.md — Camera Follow User + Get Current Location
  • references/custom-data.md — GeoJSON: Lines, Polygons, Points, Update/Remove
  • references/camera-styles.md — Camera Control + Map Styles
  • references/interactions.md — Featureset Interactions, Custom Layer Taps, Long Press, Gestures

Additional Resources

安全使用建议
This skill is a documentation/reference pack for integrating Mapbox Maps SDK on iOS and appears coherent. Before using in your app: (1) confirm you use a public Mapbox token (pk.*) as recommended — do not embed secret keys in Info.plist or source control; (2) audit any location-permission flows you implement and add clear privacy text for users; (3) follow the official Mapbox SDK repository link in the docs when adding dependencies; and (4) review and test the suggested code in your app context (especially permission handling and data sources) before shipping.
功能分析
Type: OpenClaw Skill Name: mapbox-ios-patterns Version: 1.0.0 The skill bundle provides legitimate integration patterns and documentation for the Mapbox Maps SDK v11 on iOS. All code snippets (Swift/SwiftUI) and instructions in SKILL.md, AGENTS.md, and the reference files are consistent with official Mapbox documentation, and no indicators of data exfiltration, malicious execution, or harmful prompt injection were found.
能力评估
Purpose & Capability
Name/description (Mapbox iOS patterns) match the content: Swift/SwiftUI/UIView examples, installation guidance, annotations, location, styles and interactions. There are no unrelated environment variables, binaries, or services requested.
Instruction Scope
Instructions focus on adding the Mapbox SDK and using it. They recommend placing a public MBXAccessToken in Info.plist and asking for iOS location permissions (NSLocationWhenInUseUsageDescription). Both are expected for this purpose, but note: the skill explicitly instructs requesting runtime location access (normal for map apps) and storing a public token in Info.plist — do not store secret keys or private tokens here.
Install Mechanism
No install spec or downloadable code is provided; the skill is instruction-only and references using Swift Package Manager/CocoaPods to add the official Mapbox repo. No suspicious URLs or archive installs are present (the repository URL referenced is the official GitHub).
Credentials
The skill requires no environment variables, secrets, or config paths. The only credential discussed is the Mapbox public access token (MBXAccessToken) which is appropriate and proportional for Mapbox SDK integration.
Persistence & Privilege
The skill is not always-enabled and is user-invocable with normal model invocation. It does not request elevated persistence or modify other skills/configuration.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install mapbox-ios-patterns
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /mapbox-ios-patterns 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release of official Mapbox Maps SDK integration patterns for iOS. - Covers installation, setup, map initialization (SwiftUI & UIKit), and adding markers. - Includes patterns for user location, camera control, styles, and handling feature interactions. - Offers best practices for annotation management and performance. - Troubleshooting tips and references for deeper usage patterns provided. - Links to official documentation, API reference, examples, and guides.
元数据
Slug mapbox-ios-patterns
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Mapbox iOS Patterns 是什么?

Official integration patterns for Mapbox Maps SDK on iOS. Covers installation, adding markers, user location, custom data, styles, camera control, and featur... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 99 次。

如何安装 Mapbox iOS Patterns?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install mapbox-ios-patterns」即可一键安装,无需额外配置。

Mapbox iOS Patterns 是免费的吗?

是的,Mapbox iOS Patterns 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Mapbox iOS Patterns 支持哪些平台?

Mapbox iOS Patterns 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Mapbox iOS Patterns?

由 Mapbox(@mapbox)开发并维护,当前版本 v1.0.0。

💬 留言讨论