Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions skills/mapbox-android-patterns/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ dependencies {

### Access Token

The string resource is the recommended approach — the SDK reads it automatically.

```xml
<!-- app/res/values/mapbox_access_token.xml -->
<?xml version="1.0" encoding="utf-8"?>
Expand All @@ -36,6 +38,18 @@ dependencies {
</resources>
```

To set it programmatically instead, import from `com.mapbox.common` — **not**
`com.mapbox.maps` — and assign before any map component is created:

```kotlin
import com.mapbox.common.MapboxOptions

MapboxOptions.accessToken = "pk.your_token"
```

Do NOT use manifest `<meta-data>` placeholders: the SDK does not read tokens from
`${MAPBOX_ACCESS_TOKEN}` in AndroidManifest.xml.

## Jetpack Compose

### Basic Map
Expand Down Expand Up @@ -79,19 +93,34 @@ MapboxMap(modifier = Modifier.fillMaxSize()) {

### Compose Annotations Pattern

Declarative annotation components are supported — prefer them over `MapEffect` with
an annotation manager when you are already in Compose.

```kotlin
// ❌ Declarative annotation components are not supported
// Use MapEffect with annotation managers instead (see above)
MapboxMap(modifier = Modifier.fillMaxSize()) {
// This doesn't work:
PointAnnotation(
point = Point.fromLngLat(-122.4194, 37.7749)
) {
iconImage = "custom-marker"
import com.mapbox.maps.extension.compose.annotation.generated.PointAnnotation
import com.mapbox.maps.extension.compose.annotation.rememberIconImage

@Composable
fun MapWithMarkers() {
val markerIcon = rememberIconImage(R.drawable.ic_marker)

MapboxMap(modifier = Modifier.fillMaxSize()) {
PointAnnotation(point = Point.fromLngLat(-122.4194, 37.7749)) {
iconImage = markerIcon
// Tap handling goes here. The `onClick` parameter is deprecated.
interactionsState.onClicked { /* handle tap */ true }
}
}
}
```

- `PointAnnotation` renders nothing without `iconImage` — always set it.
- Use `rememberIconImage(R.drawable.ic_marker)` for drawable resources, not
`BitmapFactory`.
- Use `interactionsState.onClicked { ... }` inside the init lambda for taps; the
`onClick` parameter is deprecated.
- Annotation IDs are `Long`, not `String`.

## View System

### Basic Map
Expand Down
Loading