Skip to content

Commit 98daa6c

Browse files
authored
Add geodesic, startCap/endCap, and spans support for polylines and polygons (#14)
* Add 2 markers and clean up the docs * Add toolbars, update the doc * Draw dashed polylines when highlighted * Add zoom-to-fit when navigating between overlays in Example04
1 parent 8bcee17 commit 98daa6c

File tree

28 files changed

+1596
-362
lines changed

28 files changed

+1596
-362
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Add to your `build.gradle.kts`:
1414

1515
```kotlin
1616
dependencies {
17-
implementation("de.afarber:openmapview:0.12.0")
17+
implementation("de.afarber:openmapview:0.13.0")
1818
}
1919
```
2020

docs/PERFORMANCE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ HttpClient(Android) {
269269
All requests include a user-agent header as required by OSM tile usage policy:
270270

271271
```kotlin
272-
header("User-Agent", "OpenMapView/0.12.0 (https://github.com/afarber/OpenMapView)")
272+
header("User-Agent", "OpenMapView/0.13.0 (https://github.com/afarber/OpenMapView)")
273273
```
274274

275275
### Coroutine-Based Downloads

docs/REPLACING_GOOGLE_MAPS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ dependencies {
107107
```kotlin
108108
// Add to build.gradle.kts
109109
dependencies {
110-
implementation("de.afarber:openmapview:0.12.0")
110+
implementation("de.afarber:openmapview:0.13.0")
111111
}
112112
```
113113

examples/Example01Pan/README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fun MapViewScreen() {
6464
factory = { ctx ->
6565
OpenMapView(ctx).apply {
6666
lifecycleOwner.lifecycle.addObserver(this)
67-
setCenter(LatLng(51.4661, 7.2491)) // Bochum, Germany
67+
setCenter(LatLng(51.4661, 7.2491))
6868
setZoom(14.0f)
6969
mapView = this
7070
}
@@ -81,14 +81,6 @@ fun MapViewScreen() {
8181
}
8282
```
8383

84-
### OSM-Inspired Colors (Colors.kt)
85-
86-
```kotlin
87-
val OsmParkGreen = Color(0xFFAAD3A2) // Parks and forests
88-
val OsmHighwayPink = Color(0xFFE892A2) // Highways and roads
89-
val OsmWaterBlue = Color(0xFFAAD3DF) // Water areas
90-
```
91-
9284
### Key Concepts
9385

9486
- **LatLng**: Represents geographic coordinates (latitude, longitude)
@@ -117,3 +109,4 @@ val OsmWaterBlue = Color(0xFFAAD3DF) // Water areas
117109
- Location 2 (Green marker): East of center
118110
- Location 3 (Magenta marker): South-West of center
119111
- Initial (Cyan marker): Center position
112+

examples/Example02Zoom/README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fun MapViewScreen() {
6262
factory = { ctx ->
6363
OpenMapView(ctx).apply {
6464
lifecycleOwner.lifecycle.addObserver(this)
65-
setCenter(LatLng(51.4661, 7.2491)) // Bochum, Germany
65+
setCenter(LatLng(51.4661, 7.2491))
6666
setZoom(14.0f)
6767
mapView = this
6868
}
@@ -76,14 +76,6 @@ fun MapViewScreen() {
7676
}
7777
```
7878

79-
### OSM-Inspired Colors (Colors.kt)
80-
81-
```kotlin
82-
val OsmParkGreen = Color(0xFFAAD3A2) // Parks and forests
83-
val OsmHighwayPink = Color(0xFFE892A2) // Highways and roads
84-
val OsmWaterBlue = Color(0xFFAAD3DF) // Water areas
85-
```
86-
8779
### Key Concepts
8880

8981
- **setZoom()**: Sets zoom level (2.0 = world view, 19.0 = street level)
@@ -122,3 +114,4 @@ OpenMapView uses:
122114
## Map Location
123115

124116
**Default Center:** Bochum, Germany (51.4661N, 7.2491E) at zoom 14.0
117+

examples/Example03Markers/README.md

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ example03markers/
4646
├── MarkerToolbar.kt # Horizontal toolbar with prev/next navigation buttons
4747
├── StatusToolbar.kt # Status overlay showing selection index and camera state
4848
├── MarkerData.kt # Marker data class and Bochum POI locations
49-
└── Constants.kt # Colors, dimensions, and durations
49+
└── Colors.kt # OSM-inspired colors and shared dimensions
5050
```
5151

5252
## Code Highlights
@@ -68,8 +68,8 @@ fun MapViewScreen() {
6868
OpenMapView(ctx).apply {
6969
lifecycleOwner.lifecycle.addObserver(this)
7070
setCenter(initialLocation)
71-
setZoom(13.0f)
72-
getUiSettings().infoWindowAutoDismiss = 10.seconds
71+
setZoom(15.0f)
72+
getUiSettings().infoWindowAutoDismiss = 5.seconds
7373

7474
setOnMarkerClickListener { marker ->
7575
selectedMarker = marker
@@ -98,7 +98,7 @@ addMarker(
9898
Marker(
9999
position = LatLng(51.4783, 7.2231),
100100
title = "Bochum Hauptbahnhof",
101-
snippet = "Main railway station",
101+
snippet = "Main Railway Station",
102102
icon = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED),
103103
)
104104
)
@@ -116,14 +116,6 @@ addMarker(
116116
)
117117
```
118118

119-
### OSM-Inspired Colors (Constants.kt)
120-
121-
```kotlin
122-
val OsmParkGreen = Color(0xFFAAD3A2) // Navigation buttons (prev/next)
123-
val OsmHighwayPink = Color(0xFFE892A2) // Info window toggle FAB
124-
val OsmWaterBlue = Color(0xFFAAD3DF) // Reserved for future use
125-
```
126-
127119
### Key Concepts
128120

129121
- **Marker**: Data class with position, title, snippet, icon, anchor, and tag
@@ -132,7 +124,6 @@ val OsmWaterBlue = Color(0xFFAAD3DF) // Reserved for future use
132124
- **setOnMarkerClickListener()**: Handle marker click events
133125
- **setOnInfoWindowClickListener()**: Handle info window click events
134126
- **setOnInfoWindowCloseListener()**: Handle info window close events (manual or auto-dismiss)
135-
- **infoWindowAutoDismiss**: Auto-dismiss info windows after a duration
136127

137128
## What to Test
138129

@@ -145,19 +136,6 @@ val OsmWaterBlue = Color(0xFFAAD3DF) // Reserved for future use
145136
7. **Wait 10 seconds** - info window auto-dismisses, status text turns black
146137
8. **Pan/zoom the map** - markers stay at correct geographic positions
147138

148-
## Marker Locations
149-
150-
This example displays 6 markers at notable Bochum landmarks:
151-
152-
| Location | Coordinates | Description |
153-
| ----------------- | ------------------- | -------------------- |
154-
| Hauptbahnhof | 51.4783°N, 7.2231°E | Main railway station |
155-
| Ruhr University | 51.4452°N, 7.2622°E | Ruhr-Universitat |
156-
| Rathaus | 51.4816°N, 7.2166°E | City Hall |
157-
| Bermuda3eck | 51.4807°N, 7.2222°E | Entertainment dist. |
158-
| Bergbau-Museum | 51.4892°N, 7.2174°E | Mining Museum |
159-
| Starlight Express | 51.4649°N, 7.2043°E | Musical theater |
160-
161139
## Custom Marker Icons
162140

163141
To use custom marker icons instead of the default teardrop:
@@ -211,4 +189,5 @@ Click detection uses:
211189

212190
**Default Center:** Calculated from marker positions (~51.47°N, 7.22°E) at zoom 13.0
213191

214-
All 6 markers are positioned around Bochum at real landmark locations.
192+
All 8 markers are positioned around Bochum at real landmark locations.
193+
10.4 MB
Loading

examples/Example03Markers/src/main/kotlin/de/afarber/openmapview/example03markers/Constants.kt renamed to examples/Example03Markers/src/main/kotlin/de/afarber/openmapview/example03markers/Colors.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ package de.afarber.openmapview.example03markers
99

1010
import androidx.compose.ui.graphics.Color
1111
import androidx.compose.ui.unit.dp
12-
import kotlin.time.Duration
13-
import kotlin.time.Duration.Companion.seconds
1412

1513
/**
1614
* Constants for the Example03Markers app: colors, dimensions, and durations.
@@ -27,6 +25,3 @@ val OsmWaterBlue = Color(0xFFAAD3DF)
2725

2826
/** Shared corner radius for all toolbar components (matches Material3 FAB). */
2927
val ToolbarCornerRadius = 16.dp
30-
31-
/** Duration after which info windows are automatically dismissed. */
32-
val InfoWindowAutoDismissDuration: Duration = 5.seconds

examples/Example03Markers/src/main/kotlin/de/afarber/openmapview/example03markers/MainActivity.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import androidx.compose.foundation.layout.Box
1515
import androidx.compose.foundation.layout.fillMaxSize
1616
import androidx.compose.foundation.layout.padding
1717
import androidx.compose.material.icons.Icons
18-
import androidx.compose.material.icons.filled.LocationOn
18+
import androidx.compose.material.icons.filled.LocationSearching
1919
import androidx.compose.material3.FloatingActionButton
2020
import androidx.compose.material3.Icon
2121
import androidx.compose.material3.MaterialTheme
@@ -39,6 +39,7 @@ import de.afarber.openmapview.LatLng
3939
import de.afarber.openmapview.Marker
4040
import de.afarber.openmapview.OnCameraMoveStartedListener
4141
import de.afarber.openmapview.OpenMapView
42+
import kotlin.time.Duration.Companion.seconds
4243

4344
/**
4445
* Main activity demonstrating OpenMapView marker navigation.
@@ -83,7 +84,7 @@ fun MapViewScreen() {
8384
poiMarkers.map { it.position.latitude }.average(),
8485
poiMarkers.map { it.position.longitude }.average(),
8586
)
86-
val initialZoom = 14.0f
87+
val initialZoom = 15.0f
8788

8889
// State variables - mapView is nullable because AndroidView.factory runs after first composition
8990
var mapView: OpenMapView? by remember { mutableStateOf(null) }
@@ -119,7 +120,7 @@ fun MapViewScreen() {
119120

120121
setCenter(initialLocation)
121122
setZoom(initialZoom)
122-
getUiSettings().infoWindowAutoDismiss = InfoWindowAutoDismissDuration
123+
getUiSettings().infoWindowAutoDismiss = 5.seconds
123124

124125
createMarkers(this)
125126

@@ -159,6 +160,7 @@ fun MapViewScreen() {
159160

160161
// Status overlay at top
161162
StatusToolbar(
163+
totalCount = poiMarkers.size,
162164
selectedIndex = selectedIndex,
163165
selectedMarkerTitle = selectedMarker?.title,
164166
cameraState = cameraState,
@@ -212,7 +214,7 @@ fun MapViewScreen() {
212214
.padding(16.dp),
213215
) {
214216
Icon(
215-
imageVector = Icons.Default.LocationOn,
217+
imageVector = Icons.Default.LocationSearching,
216218
contentDescription = "Toggle Info Window",
217219
)
218220
}

examples/Example03Markers/src/main/kotlin/de/afarber/openmapview/example03markers/MarkerData.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ val poiMarkers = listOf(
3030
MarkerData(
3131
position = LatLng(51.4783, 7.2231),
3232
title = "Bochum Hauptbahnhof",
33-
snippet = "Main railway station",
33+
snippet = "Main Railway Station",
3434
hue = BitmapDescriptorFactory.HUE_RED,
3535
),
3636
MarkerData(
3737
position = LatLng(51.4452, 7.2622),
3838
title = "Ruhr University",
39-
snippet = "Ruhr-Universität Bochum",
39+
snippet = "Ruhr-University Bochum",
4040
hue = BitmapDescriptorFactory.HUE_BLUE,
4141
),
4242
MarkerData(
@@ -46,9 +46,9 @@ val poiMarkers = listOf(
4646
hue = BitmapDescriptorFactory.HUE_GREEN,
4747
),
4848
MarkerData(
49-
position = LatLng(51.4807, 7.2222),
49+
position = LatLng(51.4761, 7.2161),
5050
title = "Bermuda3eck",
51-
snippet = "Entertainment district",
51+
snippet = "Entertainment District",
5252
hue = BitmapDescriptorFactory.HUE_ORANGE,
5353
),
5454
MarkerData(
@@ -58,9 +58,21 @@ val poiMarkers = listOf(
5858
hue = BitmapDescriptorFactory.HUE_MAGENTA,
5959
),
6060
MarkerData(
61-
position = LatLng(51.4649, 7.2043),
61+
position = LatLng(51.4927, 7.2342),
6262
title = "Starlight Express",
63-
snippet = "Musical theater",
63+
snippet = "Musical Theater",
6464
hue = BitmapDescriptorFactory.HUE_CYAN,
6565
),
66+
MarkerData(
67+
position = LatLng(51.4722, 7.2177),
68+
title = "Schauspielhaus Bochum",
69+
snippet = "Drama Theater",
70+
hue = BitmapDescriptorFactory.HUE_YELLOW,
71+
),
72+
MarkerData(
73+
position = LatLng(51.4854, 7.2278),
74+
title = "Zeiss Planetarium",
75+
snippet = "Domed Astronomy Center",
76+
hue = BitmapDescriptorFactory.HUE_VIOLET,
77+
),
6678
)

0 commit comments

Comments
 (0)