Skip to content

Commit ff8615a

Browse files
authored
Improve example docs (#5)
1 parent e9f38a9 commit ff8615a

13 files changed

Lines changed: 466 additions & 134 deletions

File tree

examples/Example01Pan/README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Example01Pan - Basic Map Panning
22

3+
[Back to README](../../README.md)
4+
35
This example demonstrates the core functionality of OpenMapView: displaying OpenStreetMap tiles and responding to touch pan gestures.
46

57
## Features Demonstrated
@@ -64,13 +66,6 @@ fun MapViewScreen() {
6466
2. **Observe tiles loading** as you pan to new areas
6567
3. **Check smooth rendering** - map should update in real-time without lag
6668

67-
## Next Steps
68-
69-
- Try [Example02Zoom](../Example02Zoom) for zoom controls and pinch-to-zoom gestures
70-
- Try [Example03Markers](../Example03Markers) for marker overlays
71-
- Try [Example04Polylines](../Example04Polylines) for vector shapes
72-
- Try [Example05Camera](../Example05Camera) for camera animations
73-
7469
## Map Location
7570

7671
**Default Center:** Bochum, Germany (51.4661°N, 7.2491°E)

examples/Example02Zoom/README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Example02Zoom - Zoom Controls and Gestures
22

3+
[Back to README](../../README.md)
4+
35
This example demonstrates zoom functionality in OpenMapView, including both programmatic zoom controls and pinch-to-zoom gestures.
46

57
## Features Demonstrated
@@ -100,13 +102,6 @@ OpenMapView uses:
100102
- Fractional zoom (Double) for smooth transitions
101103
- Web Mercator projection for tile calculation
102104

103-
## Next Steps
104-
105-
- Try [Example01Pan](../Example01Pan) for basic panning without zoom controls
106-
- Try [Example03Markers](../Example03Markers) for marker overlays
107-
- Try [Example04Polylines](../Example04Polylines) for vector shapes
108-
- Try [Example05Camera](../Example05Camera) for camera animations
109-
110105
## Map Location
111106

112107
**Default Center:** Berlin, Germany (52.52°N, 13.405°E) at zoom 14.0

examples/Example03Markers/README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Example03Markers - Marker Overlays and Click Handling
22

3+
[Back to README](../../README.md)
4+
35
This example demonstrates the marker system in OpenMapView, including marker rendering, touch detection, and click event handling.
46

57
## Features Demonstrated
@@ -167,15 +169,6 @@ Click detection uses:
167169
- Reverse z-order checking (top markers checked first)
168170
- Configurable movement threshold (10px) to distinguish clicks from drags
169171

170-
## Next Steps
171-
172-
- Try [Example01Pan](../Example01Pan) for basic map panning
173-
- Try [Example02Zoom](../Example02Zoom) for zoom controls
174-
- Try [Example04Polylines](../Example04Polylines) for vector shapes
175-
- Try [Example05Camera](../Example05Camera) for camera animations
176-
- Modify marker positions to show your own locations
177-
- Add custom marker icons from your app resources
178-
179172
## Map Location
180173

181174
**Default Center:** Bochum, Germany (51.4661°N, 7.2491°E) at zoom 14.0

examples/Example04Polylines/README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Example04Polylines - Polylines and Polygons
22

3+
[Back to README](../../README.md)
4+
35
This example demonstrates drawing vector shapes (polylines and polygons) on OpenMapView, including styled lines, filled areas, and polygons with holes.
46

57
## Features Demonstrated
@@ -226,15 +228,6 @@ clearPolylines()
226228
clearPolygons()
227229
```
228230

229-
## Next Steps
230-
231-
- Try [Example01Pan](../Example01Pan) for basic map panning
232-
- Try [Example02Zoom](../Example02Zoom) for zoom controls
233-
- Try [Example03Markers](../Example03Markers) for marker overlays
234-
- Try [Example05Camera](../Example05Camera) for camera animations
235-
- Add your own geographic data (routes, boundaries, zones)
236-
- Experiment with different colors and transparency levels
237-
238231
## Map Location
239232

240233
**Default Center:** Bochum, Germany (51.4661°N, 7.2491°E) at zoom 14.0

examples/Example05Camera/README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Example05Camera - Camera Animations
22

3+
[Back to README](../../README.md)
4+
35
This example demonstrates smooth camera animations in OpenMapView, showing how to animate map position and zoom level changes with customizable durations and completion callbacks.
46

57
## Features Demonstrated
@@ -217,15 +219,6 @@ mapView.animateCamera(
217219
)
218220
```
219221

220-
## Next Steps
221-
222-
- Try [Example01Pan](../Example01Pan) for basic map panning
223-
- Try [Example02Zoom](../Example02Zoom) for zoom controls
224-
- Try [Example03Markers](../Example03Markers) for marker overlays
225-
- Try [Example04Polylines](../Example04Polylines) for vector shapes
226-
- Experiment with different animation durations
227-
- Add your own markers and create navigation sequences
228-
229222
## Map Location
230223

231224
Default Center: Bochum, Germany (51.4620°N, 7.2480°E) at zoom 13.0

examples/Example06Clicks/README.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Example06Clicks - Map Click Listeners
22

3+
[Back to README](../../README.md)
4+
35
This example demonstrates map click and long-click event handling in OpenMapView, showing how to detect user taps on the map and convert screen coordinates to geographic coordinates.
46

57
## Features Demonstrated
@@ -236,17 +238,6 @@ When a marker is clicked:
236238
- If marker listener returns `true`, event is consumed (map click not fired)
237239
- If marker listener returns `false`, event propagates to map click listener
238240

239-
## Next Steps
240-
241-
- Try [Example01Pan](../Example01Pan) for basic map panning
242-
- Try [Example02Zoom](../Example02Zoom) for zoom controls
243-
- Try [Example03Markers](../Example03Markers) for marker overlays
244-
- Try [Example04Polylines](../Example04Polylines) for vector shapes
245-
- Try [Example05Camera](../Example05Camera) for camera animations
246-
- Experiment with adding markers on tap
247-
- Build a distance measurement tool
248-
- Create custom context menus on long-press
249-
250241
## Map Location
251242

252243
Default Center: Bochum, Germany (51.4620°N, 7.2480°E) at zoom 13.0
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Example07DraggableMarkers - Draggable Markers with Drag Events
2+
3+
[Back to README](../../README.md)
4+
5+
This example demonstrates draggable markers in OpenMapView, showing how to enable marker dragging and handle drag event callbacks.
6+
7+
## Features Demonstrated
8+
9+
- Draggable markers with long-press activation
10+
- OnMarkerDragListener with start/drag/end callbacks
11+
- Toast notifications showing drag events
12+
- Add random markers with FAB button
13+
- Clear all markers with FAB button
14+
- Marker click listener alongside drag listener
15+
- Attribution click listener for OSM copyright
16+
17+
## Screenshot
18+
19+
![Example07DraggableMarkers Demo](screenshot.gif)
20+
21+
## Quick Start
22+
23+
### Option 1: Run in Android Studio
24+
25+
1. Open the OpenMapView project in Android Studio
26+
2. Select `examples.Example07DraggableMarkers` from the run configuration dropdown
27+
3. Click Run (green play button)
28+
4. Deploy to your device or emulator
29+
30+
### Option 2: Build and Install from Command Line
31+
32+
```bash
33+
# From project root - build, install, and launch
34+
./gradlew :examples:Example07DraggableMarkers:installDebug
35+
36+
# Launch the app
37+
adb shell am start -n de.afarber.openmapview.example07draggablemarkers/.MainActivity
38+
```
39+
40+
## Code Highlights
41+
42+
### Creating Draggable Markers
43+
44+
```kotlin
45+
val marker = Marker(
46+
position = LatLng(51.4661, 7.2491),
47+
title = "Marker 1",
48+
snippet = "Drag me!",
49+
draggable = true // Enable dragging
50+
)
51+
mapView.addMarker(marker)
52+
```
53+
54+
### Setting Up Drag Listener
55+
56+
```kotlin
57+
mapView.setOnMarkerDragListener(object : OnMarkerDragListener {
58+
override fun onMarkerDragStart(marker: Marker) {
59+
Toast.makeText(context, "Started dragging: ${marker.title}", Toast.LENGTH_SHORT).show()
60+
}
61+
62+
override fun onMarkerDrag(marker: Marker) {
63+
// Called continuously during drag - useful for real-time updates
64+
}
65+
66+
override fun onMarkerDragEnd(marker: Marker) {
67+
val coordString = "%.4f, %.4f".format(
68+
marker.position.latitude,
69+
marker.position.longitude
70+
)
71+
Toast.makeText(context, "${marker.title} at: $coordString", Toast.LENGTH_SHORT).show()
72+
}
73+
})
74+
```
75+
76+
### Key Concepts
77+
78+
- **draggable = true**: Enable dragging on individual markers
79+
- **OnMarkerDragListener**: Interface with three callbacks
80+
- **onMarkerDragStart()**: Called when long-press initiates drag
81+
- **onMarkerDrag()**: Called continuously during drag movement
82+
- **onMarkerDragEnd()**: Called when finger is lifted
83+
- **Marker position update**: Position is automatically updated during drag
84+
85+
## What to Test
86+
87+
1. **Add markers** - Click the refresh FAB to add 5 random draggable markers
88+
2. **Long-press to drag** - Press and hold a marker, then drag it
89+
3. **Observe start toast** - "Started dragging: Marker X" appears
90+
4. **Observe end toast** - New coordinates shown when released
91+
5. **Click markers** - Tap (don't hold) to see title and snippet
92+
6. **Clear all** - Click the clear FAB to remove all markers
93+
7. **Pan and zoom** - Markers remain draggable at all zoom levels
94+
8. **Attribution click** - Tap OSM attribution to open copyright page
95+
96+
## Drag Interaction Details
97+
98+
### How Dragging Works
99+
100+
1. User long-presses on a draggable marker (~500ms)
101+
2. `onMarkerDragStart()` is called
102+
3. User moves finger while holding
103+
4. `onMarkerDrag()` is called continuously
104+
5. Marker visually follows the touch point
105+
6. User lifts finger
106+
7. `onMarkerDragEnd()` is called with final position
107+
108+
### Drag vs Click vs Pan
109+
110+
- **Click**: Quick tap on marker triggers click listener
111+
- **Long-press on marker**: Initiates drag (if draggable)
112+
- **Long-press on map**: Triggers map long-click listener
113+
- **Drag on map**: Pans the map
114+
115+
## Technical Details
116+
117+
### Marker State During Drag
118+
119+
- Position is updated in real-time during drag
120+
- Marker's visual position follows the touch point
121+
- Final position is permanent after drag ends
122+
123+
### Performance
124+
125+
- Drag updates run on UI thread for responsiveness
126+
- No coordinate conversion until drag ends (efficient)
127+
- Smooth visual feedback during drag
128+
129+
## Advanced Usage
130+
131+
### Track Marker Movement
132+
133+
```kotlin
134+
var startPosition: LatLng? = null
135+
136+
mapView.setOnMarkerDragListener(object : OnMarkerDragListener {
137+
override fun onMarkerDragStart(marker: Marker) {
138+
startPosition = marker.position
139+
}
140+
141+
override fun onMarkerDrag(marker: Marker) {
142+
// Update UI with current position
143+
}
144+
145+
override fun onMarkerDragEnd(marker: Marker) {
146+
val distance = calculateDistance(startPosition!!, marker.position)
147+
Toast.makeText(context, "Moved: ${distance}m", Toast.LENGTH_SHORT).show()
148+
}
149+
})
150+
```
151+
152+
### Combine with Click Listener
153+
154+
```kotlin
155+
// Both listeners can coexist
156+
mapView.setOnMarkerClickListener { marker ->
157+
Toast.makeText(context, marker.title, Toast.LENGTH_SHORT).show()
158+
true
159+
}
160+
161+
mapView.setOnMarkerDragListener(object : OnMarkerDragListener {
162+
// ... drag callbacks
163+
})
164+
```
165+
166+
## Map Location
167+
168+
**Default Center:** Bochum, Germany (51.4661°N, 7.2491°E) at zoom 13.0
169+
170+
Random markers are generated within ~2.5km of the center.

examples/Example08Circles/README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Example08Circles - Circle Overlays with Meter-Based Radius
22

3+
[Back to README](../../README.md)
4+
35
This example demonstrates the circle system in OpenMapView, including circle rendering with meter-based radius, styling options, z-index ordering, and both API patterns.
46

57
## Features Demonstrated
@@ -190,15 +192,6 @@ The floating action button (+) adds random circles:
190192

191193
The floating action button (×) removes all circles from the map.
192194

193-
## Next Steps
194-
195-
- Try [Example03Markers](../Example03Markers) for marker overlays
196-
- Try [Example04Polylines](../Example04Polylines) for polylines and polygons
197-
- Try [Example06Clicks](../Example06Clicks) for map click listeners
198-
- Modify circle radii to experiment with different sizes
199-
- Try overlapping circles to see z-index ordering in action
200-
- Add circles at your own locations
201-
202195
## Map Location
203196

204197
**Default Center:** Bochum, Germany (51.4661°N, 7.2491°E) at zoom 12.0

examples/Example09Overlays/README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Example09Overlays - Tile Overlay Layers from Public OSM Services
22

3-
This example demonstrates the tile overlay system in OpenMapView, showing how to add multiple tile layers on top of the base map from public OpenStreetMap services.
3+
[Back to README](../../README.md)
44

5-
![Example09Overlays Demo](screenshot.gif)
5+
This example demonstrates the tile overlay system in OpenMapView, showing how to add multiple tile layers on top of the base map from public OpenStreetMap services.
66

77
## Features Demonstrated
88

@@ -15,6 +15,10 @@ This example demonstrates the tile overlay system in OpenMapView, showing how to
1515
- Real-time overlay property updates
1616
- Overlay caching and tile downloading
1717

18+
## Screenshot
19+
20+
![Example09Overlays Demo](screenshot.gif)
21+
1822
## Quick Start
1923

2024
### Option 1: Run in Android Studio
@@ -263,16 +267,6 @@ Material3 card with:
263267

264268
Floating action button (×) removes all overlays and resets transparency to 0%.
265269

266-
## Next Steps
267-
268-
- Try [Example03Markers](../Example03Markers) for marker overlays
269-
- Try [Example08Circles](../Example08Circles) for circle overlays
270-
- Try [Example04Polylines](../Example04Polylines) for polylines and polygons
271-
- Experiment with different overlay combinations
272-
- Adjust transparency to see layering effects
273-
- Test with different z-index values
274-
- Add your own custom URL tile provider
275-
276270
## Map Location
277271

278272
**Default Center:** Bochum, Germany (51.4661°N, 7.2491°E) at zoom 12.0

examples/Example10GroundOverlays/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Example10GroundOverlays - Ground Overlay Images on Map
22

3-
This example demonstrates ground overlays in OpenMapView, showing how to add images positioned on the map with support for rotation and transparency.
3+
[Back to README](../../README.md)
44

5-
![Example10GroundOverlays Demo](screenshot.gif)
5+
This example demonstrates ground overlays in OpenMapView, showing how to add images positioned on the map with support for rotation and transparency.
66

77
## Features Demonstrated
88

@@ -16,6 +16,10 @@ This example demonstrates ground overlays in OpenMapView, showing how to add ima
1616
- Dynamic overlay toggling (show/hide)
1717
- Jetpack Compose UI with Material3
1818

19+
## Screenshot
20+
21+
![Example10GroundOverlays Demo](screenshot.gif)
22+
1923
## Quick Start
2024

2125
### Run in Android Studio

0 commit comments

Comments
 (0)