Skip to content

Commit

Permalink
feat: allow bounding the zoom and pitch state (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
sargunv authored Dec 27, 2024
1 parent 709481a commit db24ad6
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
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

0 comments on commit db24ad6

Please sign in to comment.