Skip to content

Commit 87bf40d

Browse files
committed
Update README.md
1 parent a6129f9 commit 87bf40d

1 file changed

Lines changed: 85 additions & 54 deletions

File tree

examples/Example03Markers/README.md

Lines changed: 85 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
# Example03Markers - Marker Overlays and Click Handling
1+
# Example03Markers - Marker Overlays and Interactive Management
22

33
[Back to README](../../README.md)
44

5-
This example demonstrates the marker system in OpenMapView, including marker rendering, touch detection, and click event handling.
5+
This example demonstrates the marker system in OpenMapView, including marker rendering, touch detection, info windows, and interactive marker management.
66

77
## Features Demonstrated
88

9-
- Multiple markers at different geographic locations
10-
- Default red teardrop marker icons with color variations
9+
- Multiple markers at real Bochum landmark locations
10+
- Default teardrop marker icons with color variations
1111
- Both API styles: Kotlin direct instantiation and Google Maps builder pattern
12-
- Marker click detection and callbacks
13-
- Toast notifications on marker click
14-
- Markers with title and snippet metadata
15-
- Marker positioning with proper anchor points
16-
- Markers that stay fixed during pan and zoom
12+
- Marker click detection and selection tracking
1713
- Info windows showing marker titles and snippets
14+
- Interactive marker management (add, remove, clear)
15+
- Real-time status display (marker count, selection, camera state)
16+
- Reset functionality to restore initial state
1817

1918
## Screenshot
2019

@@ -39,30 +38,68 @@ This example demonstrates the marker system in OpenMapView, including marker ren
3938
adb shell am start -n de.afarber.openmapview.example03markers/.MainActivity
4039
```
4140

41+
## Project Structure
42+
43+
```
44+
example03markers/
45+
├── MainActivity.kt # Main activity and MapViewScreen composable
46+
├── MarkerToolbar.kt # Horizontal toolbar with add/remove/clear buttons
47+
├── StatusToolbar.kt # Status overlay showing marker count and selection
48+
└── Colors.kt # OSM-inspired colors and shared dimensions
49+
```
50+
4251
## Code Highlights
4352

44-
### Adding Markers - Kotlin Style
53+
### MainActivity.kt
4554

4655
```kotlin
47-
OpenMapView(context).apply {
48-
setCenter(LatLng(51.4661, 7.2491)) // Bochum, Germany
49-
setZoom(14.0)
50-
51-
// Kotlin-style direct instantiation
52-
addMarker(
53-
Marker(
54-
position = LatLng(51.4661, 7.2491),
55-
title = "Bochum City Center",
56-
snippet = "Welcome to Bochum!",
56+
@Composable
57+
fun MapViewScreen() {
58+
val lifecycleOwner = LocalLifecycleOwner.current
59+
var mapView: OpenMapView? by remember { mutableStateOf(null) }
60+
var markerCount by remember { mutableIntStateOf(6) }
61+
var selectedMarker: Marker? by remember { mutableStateOf(null) }
62+
63+
Box(modifier = Modifier.fillMaxSize()) {
64+
AndroidView(
65+
factory = { ctx ->
66+
OpenMapView(ctx).apply {
67+
lifecycleOwner.lifecycle.addObserver(this)
68+
setCenter(initialLocation)
69+
setZoom(13.0f)
70+
71+
setOnMarkerClickListener { marker ->
72+
selectedMarker = marker
73+
true
74+
}
75+
mapView = this
76+
}
77+
},
78+
modifier = Modifier.fillMaxSize(),
5779
)
58-
)
80+
81+
StatusToolbar(markerCount = markerCount, selectedMarkerTitle = selectedMarker?.title, ...)
82+
MarkerToolbar(onAddClick = { ... }, onRemoveClick = { ... }, onClearClick = { ... })
83+
}
5984
}
6085
```
6186

87+
### Adding Markers - Kotlin Style
88+
89+
```kotlin
90+
addMarker(
91+
Marker(
92+
position = LatLng(51.4783, 7.2231),
93+
title = "Bochum Hauptbahnhof",
94+
snippet = "Main railway station",
95+
icon = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED),
96+
)
97+
)
98+
```
99+
62100
### Adding Markers - Google Maps Style
63101

64102
```kotlin
65-
// Google Maps API builder pattern
66103
addMarker(
67104
MarkerOptions()
68105
.position(LatLng(51.4650, 7.2500))
@@ -72,20 +109,12 @@ addMarker(
72109
)
73110
```
74111

75-
### Click Listener
112+
### OSM-Inspired Colors (Colors.kt)
76113

77114
```kotlin
78-
setOnMarkerClickListener { marker ->
79-
val message = buildString {
80-
append(marker.title ?: "Marker")
81-
if (marker.snippet != null) {
82-
append("\n")
83-
append(marker.snippet)
84-
}
85-
}
86-
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
87-
true // Consume the click event
88-
}
115+
val OsmParkGreen = Color(0xFFAAD3A2) // Add button
116+
val OsmHighwayPink = Color(0xFFE892A2) // Remove button, Reset FAB
117+
val OsmWaterBlue = Color(0xFFAAD3DF) // Clear button
89118
```
90119

91120
### Key Concepts
@@ -94,35 +123,37 @@ setOnMarkerClickListener { marker ->
94123
- **addMarker()**: Add a marker to the map
95124
- **removeMarker()**: Remove a specific marker
96125
- **clearMarkers()**: Remove all markers
126+
- **getMarkers()**: Get list of all markers
97127
- **setOnMarkerClickListener()**: Handle marker click events
98-
- **Default icon**: Red teardrop shape generated via MarkerIconFactory
99-
- **Custom icons**: Provide your own Bitmap via the `icon` parameter
128+
- **setOnInfoWindowClickListener()**: Handle info window click events
100129

101130
## What to Test
102131

103-
1. **Launch the app** - you should see 5 red markers around Bochum
104-
2. **Click a marker** - Toast message shows title and snippet
105-
3. **Pan the map** - markers stay at correct geographic positions
106-
4. **Zoom in/out** - markers remain properly positioned
107-
5. **Click different markers** - each shows its own title/snippet
132+
1. **Launch the app** - you should see 6 colored markers at Bochum landmarks
133+
2. **Tap a marker** - info window shows title and snippet, status shows selection
134+
3. **Tap info window** - toast message confirms the click
135+
4. **Tap + button** - adds new marker at map center
136+
5. **Tap - button** - removes currently selected marker
137+
6. **Tap trash button** - clears all markers
138+
7. **Tap reset FAB** - restores initial markers and camera position
139+
8. **Pan/zoom the map** - markers stay at correct geographic positions
108140

109141
## Marker Locations
110142

111-
This example displays 5 markers:
112-
113-
| Location | Coordinates | Description |
114-
| -------- | ------------------- | ------------------ |
115-
| Center | 51.4661°N, 7.2491°E | Bochum City Center |
116-
| North | 51.4700°N, 7.2550°E | North Location |
117-
| South | 51.4620°N, 7.2430°E | South Location |
118-
| West | 51.4680°N, 7.2380°E | West Location |
119-
| East | 51.4640°N, 7.2600°E | East Location |
143+
This example displays 6 markers at notable Bochum landmarks:
120144

121-
**Note on marker positioning:** While the 4 outer markers are placed on N, S, W, E sides of the central marker (by adjusting latitude/longitude), they do not appear strictly above, below, left, right on the screen. This is due to the Web Mercator projection used by OpenStreetMap, which distorts distances and angles, especially at higher latitudes. The further from the equator, the more pronounced this distortion becomes.
145+
| Location | Coordinates | Description |
146+
| ----------------- | ------------------- | -------------------- |
147+
| Hauptbahnhof | 51.4783°N, 7.2231°E | Main railway station |
148+
| Ruhr University | 51.4452°N, 7.2622°E | Ruhr-Universitat |
149+
| Rathaus | 51.4816°N, 7.2166°E | City Hall |
150+
| Bermuda3eck | 51.4807°N, 7.2222°E | Entertainment dist. |
151+
| Bergbau-Museum | 51.4892°N, 7.2174°E | Mining Museum |
152+
| Starlight Express | 51.4649°N, 7.2043°E | Musical theater |
122153

123154
## Custom Marker Icons
124155

125-
To use custom marker icons instead of the default red teardrop:
156+
To use custom marker icons instead of the default teardrop:
126157

127158
```kotlin
128159
// Create custom bitmap (e.g., from resources)
@@ -171,6 +202,6 @@ Click detection uses:
171202

172203
## Map Location
173204

174-
**Default Center:** Bochum, Germany (51.4661°N, 7.2491°E) at zoom 14.0
205+
**Default Center:** Calculated from marker positions (~51.47°N, 7.22°E) at zoom 13.0
175206

176-
All 5 markers are positioned around Bochum within ~1km radius.
207+
All 6 markers are positioned around Bochum at real landmark locations.

0 commit comments

Comments
 (0)