-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
364 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
demo-app/src/commonMain/kotlin/dev/sargunv/maplibrecompose/demoapp/docs/Interaction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
@file:Suppress("unused", "UNUSED_ANONYMOUS_PARAMETER") | ||
|
||
package dev.sargunv.maplibrecompose.demoapp.docs | ||
|
||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.unit.dp | ||
import dev.sargunv.maplibrecompose.compose.ClickResult | ||
import dev.sargunv.maplibrecompose.compose.MaplibreMap | ||
import dev.sargunv.maplibrecompose.compose.rememberCameraState | ||
import dev.sargunv.maplibrecompose.core.CameraPosition | ||
import dev.sargunv.maplibrecompose.core.GestureSettings | ||
import dev.sargunv.maplibrecompose.core.OrnamentSettings | ||
import io.github.dellisd.spatialk.geojson.Position | ||
import kotlin.time.Duration.Companion.seconds | ||
|
||
@Composable | ||
fun Interaction() { | ||
// -8<- [start:gesture-settings] | ||
MaplibreMap( | ||
gestureSettings = | ||
GestureSettings( | ||
isTiltGesturesEnabled = true, | ||
isZoomGesturesEnabled = true, // (1)! | ||
isRotateGesturesEnabled = true, | ||
isScrollGesturesEnabled = true, | ||
) | ||
) | ||
// -8<- [end:gesture-settings] | ||
|
||
// -8<- [start:ornament-settings] | ||
MaplibreMap( | ||
ornamentSettings = | ||
OrnamentSettings( | ||
padding = PaddingValues(0.dp), // (1)! | ||
isLogoEnabled = true, // (2)! | ||
logoAlignment = Alignment.BottomStart, // (3)! | ||
isAttributionEnabled = true, // (4)! | ||
attributionAlignment = Alignment.BottomEnd, | ||
isCompassEnabled = true, // (5)! | ||
compassAlignment = Alignment.TopEnd, | ||
) | ||
) | ||
// -8<- [end:ornament-settings] | ||
|
||
// -8<- [start:camera] | ||
val camera = | ||
rememberCameraState( | ||
firstPosition = | ||
CameraPosition(target = Position(latitude = 45.521, longitude = -122.675), zoom = 13.0) | ||
) | ||
MaplibreMap(cameraState = camera) | ||
// -8<- [end:camera] | ||
|
||
// -8<- [start:camera-animate] | ||
LaunchedEffect(Unit) { | ||
camera.animateTo( | ||
finalPosition = | ||
camera.position.copy(target = Position(latitude = 47.607, longitude = -122.342)), | ||
duration = 3.seconds, | ||
) | ||
} | ||
// -8<- [end:camera-animate] | ||
|
||
// -8<- [start:click-listeners] | ||
MaplibreMap( | ||
cameraState = camera, | ||
onMapClick = { pos, offset -> | ||
val features = camera.queryRenderedFeatures(offset) | ||
if (features.isNotEmpty()) { | ||
println("Clicked on ${features[0].json()}") | ||
ClickResult.Consume // (1)! | ||
} else { | ||
ClickResult.Pass | ||
} | ||
}, | ||
onMapLongClick = { pos, offset -> | ||
println("Long click at $pos") | ||
ClickResult.Pass | ||
}, | ||
) | ||
// -8<- [end:click-listeners] | ||
} |
91 changes: 91 additions & 0 deletions
91
demo-app/src/commonMain/kotlin/dev/sargunv/maplibrecompose/demoapp/docs/Layers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
@file:Suppress("unused") | ||
|
||
package dev.sargunv.maplibrecompose.demoapp.docs | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.dp | ||
import dev.sargunv.maplibrecompose.compose.ClickResult | ||
import dev.sargunv.maplibrecompose.compose.MaplibreMap | ||
import dev.sargunv.maplibrecompose.compose.layer.Anchor | ||
import dev.sargunv.maplibrecompose.compose.layer.CircleLayer | ||
import dev.sargunv.maplibrecompose.compose.layer.LineLayer | ||
import dev.sargunv.maplibrecompose.compose.source.getBaseSource | ||
import dev.sargunv.maplibrecompose.compose.source.rememberGeoJsonSource | ||
import dev.sargunv.maplibrecompose.core.expression.LineCap | ||
import dev.sargunv.maplibrecompose.core.expression.LineJoin | ||
import dev.sargunv.maplibrecompose.demoapp.generated.Res | ||
import org.jetbrains.compose.resources.ExperimentalResourceApi | ||
|
||
@Composable | ||
@OptIn(ExperimentalResourceApi::class) | ||
fun Layers() { | ||
// -8<- [start:simple] | ||
MaplibreMap(styleUrl = "https://tiles.openfreemap.org/styles/liberty") { | ||
val tiles = getBaseSource(id = "openmaptiles") | ||
CircleLayer(id = "example", source = tiles, sourceLayer = "poi") | ||
} | ||
// -8<- [end:simple] | ||
|
||
MaplibreMap { | ||
val amtrakStations = | ||
rememberGeoJsonSource( | ||
id = "amtrak-stations", | ||
dataUrl = Res.getUri("files/data/amtrak_stations.geojson"), | ||
) | ||
|
||
// -8<- [start:amtrak-1] | ||
val amtrakRoutes = | ||
rememberGeoJsonSource( | ||
id = "amtrak-routes", | ||
dataUrl = Res.getUri("files/data/amtrak_routes.geojson"), | ||
) | ||
LineLayer( | ||
id = "amtrak-routes-casing", | ||
source = amtrakRoutes, | ||
color = const(Color.White), | ||
width = const(6.dp), | ||
) | ||
LineLayer( | ||
id = "amtrak-routes", | ||
source = amtrakRoutes, | ||
color = const(Color.Blue), | ||
width = const(4.dp), | ||
) | ||
// -8<- [end:amtrak-1] | ||
|
||
// -8<- [start:amtrak-2] | ||
LineLayer( | ||
id = "amtrak-routes", | ||
source = amtrakRoutes, | ||
cap = const(LineCap.Round), | ||
join = const(LineJoin.Round), | ||
color = const(Color.Blue), | ||
width = | ||
interpolate( | ||
type = exponential(const(1.2f)), | ||
input = zoom(), | ||
5 to const(0.4.dp), | ||
6 to const(0.7.dp), | ||
7 to const(1.75.dp), | ||
20 to const(22.dp), | ||
), | ||
) | ||
// -8<- [end:amtrak-2] | ||
|
||
// -8<- [start:anchors] | ||
Anchor.Above("road_motorway") { LineLayer(id = "amtrak-routes", source = amtrakRoutes) } | ||
// -8<- [end:anchors] | ||
|
||
// -8<- [start:interaction] | ||
CircleLayer( | ||
id = "amtrak-stations", | ||
source = amtrakStations, | ||
onClick = { features -> | ||
println("Clicked on ${features[0].json()}") | ||
ClickResult.Consume | ||
}, | ||
) | ||
// -8<- [end:interaction] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Interacting with the map | ||
|
||
## Gestures | ||
|
||
The map supports pan, zoom, rotate, and tilt gestures. Each of these can be | ||
enabled or disabled individually: | ||
|
||
```kotlin | ||
-8<- "demo-app/src/commonMain/kotlin/dev/sargunv/maplibrecompose/demoapp/docs/Interaction.kt:gesture-settings" | ||
``` | ||
|
||
1. Includes pinch, double-tap, and double-tap-and-drag. | ||
|
||
## Ornaments | ||
|
||
Ornaments are UI elements that are displayed on the map, such as a compass or | ||
attribution button. They're implemented by the underlying MapLibre SDK, so may | ||
render differently on different platforms. You can control the visibility and | ||
position of these ornaments: | ||
|
||
```kotlin | ||
-8<- "demo-app/src/commonMain/kotlin/dev/sargunv/maplibrecompose/demoapp/docs/Interaction.kt:ornament-settings" | ||
``` | ||
|
||
1. Insets the ornaments; useful if you have an edge-to-edge map or some UI | ||
elements that cover part of the map. | ||
2. Displays a MapLibre logo | ||
3. Possible alignments are constrained by the underlying SDK. The four corners | ||
are supported across platforms. | ||
4. Displays attribution defined in the map style. | ||
5. Displays a compass control when the map is rotated away from north. | ||
|
||
## Camera | ||
|
||
If you want to read or mutate the camera state, use `rememberCameraState()`. You | ||
can use this to set the start position of the map: | ||
|
||
```kotlin | ||
-8<- "demo-app/src/commonMain/kotlin/dev/sargunv/maplibrecompose/demoapp/docs/Interaction.kt:camera" | ||
``` | ||
|
||
You can now use the `camera` reference to move the camera. For example, | ||
`CameraState` exposes a `suspend fun animateTo` to animate the camera to a new | ||
position: | ||
|
||
```kotlin | ||
-8<- "demo-app/src/commonMain/kotlin/dev/sargunv/maplibrecompose/demoapp/docs/Interaction.kt:camera-animate" | ||
``` | ||
|
||
## Click listeners | ||
|
||
You can listen for clicks on the map. Given a click location, you can use camera | ||
state to query which features are present at that location: | ||
|
||
```kotlin | ||
-8<- "demo-app/src/commonMain/kotlin/dev/sargunv/maplibrecompose/demoapp/docs/Interaction.kt:click-listeners" | ||
``` | ||
|
||
1. Consumes the click event, preventing it from propagating to the individual | ||
layers' click listeners. |
Oops, something went wrong.