Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow bounding the zoom and pitch state #199

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,30 @@ internal class AndroidMap(

override var onFpsChanged: (Double) -> Unit = { _ -> }

override var minPitch
get() = map.minPitch
set(value) {
map.setMinPitchPreference(value)
}

override var maxPitch
get() = map.maxPitch
set(value) {
map.setMaxPitchPreference(value)
}

override var minZoom
get() = map.minZoomLevel
set(value) {
map.setMinZoomPreference(value)
}

override var maxZoom
get() = map.maxZoomLevel
set(value) {
map.setMaxZoomPreference(value)
}

override val visibleBoundingBox: BoundingBox
get() = map.projection.visibleRegion.latLngBounds.toBoundingBox()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import kotlin.math.roundToInt
* @param modifier The modifier to be applied to the layout.
* @param styleUri The URI of the map style specification JSON to use, see
* [MapLibre Style](https://maplibre.org/maplibre-style-spec/).
* @param zoomRange The allowable bounds for the camera zoom level.
* @param pitchRange The allowable bounds for the camera pitch.
* @param gestureSettings Defines which user map gestures are enabled.
* @param ornamentSettings Defines which additional UI elements are displayed on top of the map.
* @param cameraState The camera state specifies what position of the map is rendered, at what zoom,
Expand Down Expand Up @@ -83,6 +85,8 @@ import kotlin.math.roundToInt
public fun MaplibreMap(
modifier: Modifier = Modifier,
styleUri: String = "https://demotiles.maplibre.org/style.json",
zoomRange: ClosedRange<Float> = 0f..20f,
pitchRange: ClosedRange<Float> = 0f..60f,
gestureSettings: GestureSettings = GestureSettings.AllEnabled,
ornamentSettings: OrnamentSettings = OrnamentSettings.AllEnabled,
cameraState: CameraState = rememberCameraState(),
Expand Down Expand Up @@ -165,6 +169,10 @@ public fun MaplibreMap(
cameraState.map = map
map.onFpsChanged = onFrame
map.isDebugEnabled = isDebugEnabled
map.minZoom = zoomRange.start.toDouble()
map.maxZoom = zoomRange.endInclusive.toDouble()
map.minPitch = pitchRange.start.toDouble()
map.maxPitch = pitchRange.endInclusive.toDouble()
map.setGestureSettings(gestureSettings)
map.setOrnamentSettings(ornamentSettings)
map.setMaximumFps(maximumFps)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@ import kotlin.time.Duration

internal interface MaplibreMap {
var styleUri: String

var isDebugEnabled: Boolean

var cameraPosition: CameraPosition

var maxZoom: Double

var minZoom: Double

var maxPitch: Double

var minPitch: Double

var onFpsChanged: (Double) -> Unit

val visibleBoundingBox: BoundingBox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,30 @@ internal class IosMap(
else 0uL
}

override var minPitch
get() = mapView.minimumPitch
set(value) {
mapView.minimumPitch = value
}

override var maxPitch
get() = mapView.maximumPitch
set(value) {
mapView.maximumPitch = value
}

override var minZoom
get() = mapView.minimumZoomLevel
set(value) {
mapView.minimumZoomLevel = value
}

override var maxZoom
get() = mapView.maximumZoomLevel
set(value) {
mapView.maximumZoomLevel = value
}

override val visibleBoundingBox: BoundingBox
get() = mapView.visibleCoordinateBounds.toBoundingBox()

Expand Down
Loading