Skip to content

Commit ccb9fdc

Browse files
RD-1373: Add Max and Min Zoom and Pitch Getters
Co-authored-by: klokantechsysadmin <[email protected]>
1 parent 170e262 commit ccb9fdc

File tree

10 files changed

+184
-0
lines changed

10 files changed

+184
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2025, MapTiler
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD 3-Clause
5+
*/
6+
7+
package com.maptiler.maptilersdk.commands.navigation
8+
9+
import com.maptiler.maptilersdk.bridge.MTBridge
10+
import com.maptiler.maptilersdk.bridge.MTCommand
11+
12+
internal class GetMaxPitch : MTCommand {
13+
override val isPrimitiveReturnType: Boolean = true
14+
15+
override fun toJS(): String = "${MTBridge.MAP_OBJECT}.getMaxPitch();"
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2025, MapTiler
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD 3-Clause
5+
*/
6+
7+
package com.maptiler.maptilersdk.commands.navigation
8+
9+
import com.maptiler.maptilersdk.bridge.MTBridge
10+
import com.maptiler.maptilersdk.bridge.MTCommand
11+
12+
internal class GetMaxZoom : MTCommand {
13+
override val isPrimitiveReturnType: Boolean = true
14+
15+
override fun toJS(): String = "${MTBridge.MAP_OBJECT}.getMaxZoom();"
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2025, MapTiler
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD 3-Clause
5+
*/
6+
7+
package com.maptiler.maptilersdk.commands.navigation
8+
9+
import com.maptiler.maptilersdk.bridge.MTBridge
10+
import com.maptiler.maptilersdk.bridge.MTCommand
11+
12+
internal class GetMinPitch : MTCommand {
13+
override val isPrimitiveReturnType: Boolean = true
14+
15+
override fun toJS(): String = "${MTBridge.MAP_OBJECT}.getMinPitch();"
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2025, MapTiler
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD 3-Clause
5+
*/
6+
7+
package com.maptiler.maptilersdk.commands.navigation
8+
9+
import com.maptiler.maptilersdk.bridge.MTBridge
10+
import com.maptiler.maptilersdk.bridge.MTCommand
11+
12+
internal class GetMinZoom : MTCommand {
13+
override val isPrimitiveReturnType: Boolean = true
14+
15+
override fun toJS(): String = "${MTBridge.MAP_OBJECT}.getMinZoom();"
16+
}

MapTilerSDK/src/main/java/com/maptiler/maptilersdk/map/MTMapViewController.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,16 @@ class MTMapViewController(
255255
*/
256256
override suspend fun getZoom(): Double = zoomableWorker.getZoom()
257257

258+
/**
259+
* Returns the map's maximum zoom level.
260+
*/
261+
override suspend fun getMaxZoom(): Double = zoomableWorker.getMaxZoom()
262+
263+
/**
264+
* Returns the map's minimum zoom level.
265+
*/
266+
override suspend fun getMinZoom(): Double = zoomableWorker.getMinZoom()
267+
258268
/**
259269
* Sets the map's zoom level.
260270
*
@@ -344,6 +354,16 @@ class MTMapViewController(
344354
*/
345355
override suspend fun getPitch(): Double = navigableWorker.getPitch()
346356

357+
/**
358+
* Returns the map's maximum pitch.
359+
*/
360+
override suspend fun getMaxPitch(): Double = navigableWorker.getMaxPitch()
361+
362+
/**
363+
* Returns the map's minimum pitch.
364+
*/
365+
override suspend fun getMinPitch(): Double = navigableWorker.getMinPitch()
366+
347367
/**
348368
* Sets the map's pitch in degrees (0-85).
349369
*/

MapTilerSDK/src/main/java/com/maptiler/maptilersdk/map/workers/navigable/MTNavigable.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ interface MTNavigable {
8484
*/
8585
suspend fun getPitch(): Double
8686

87+
/**
88+
* Returns the map's maximum pitch.
89+
*/
90+
suspend fun getMaxPitch(): Double
91+
92+
/**
93+
* Returns the map's minimum pitch.
94+
*/
95+
suspend fun getMinPitch(): Double
96+
8797
/**
8898
* Sets the map's pitch.
8999
*

MapTilerSDK/src/main/java/com/maptiler/maptilersdk/map/workers/navigable/NavigableWorker.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import com.maptiler.maptilersdk.commands.navigation.GetBearing
1616
import com.maptiler.maptilersdk.commands.navigation.GetCenter
1717
import com.maptiler.maptilersdk.commands.navigation.GetCenterClampedToGround
1818
import com.maptiler.maptilersdk.commands.navigation.GetCenterElevation
19+
import com.maptiler.maptilersdk.commands.navigation.GetMaxPitch
20+
import com.maptiler.maptilersdk.commands.navigation.GetMinPitch
1921
import com.maptiler.maptilersdk.commands.navigation.GetPitch
2022
import com.maptiler.maptilersdk.commands.navigation.GetRoll
2123
import com.maptiler.maptilersdk.commands.navigation.JumpTo
@@ -141,6 +143,32 @@ internal class NavigableWorker(
141143
}
142144
}
143145

146+
override suspend fun getMaxPitch(): Double {
147+
val returnTypeValue =
148+
bridge.execute(
149+
GetMaxPitch(),
150+
)
151+
152+
return when (returnTypeValue) {
153+
is StringValue -> returnTypeValue.value.toDouble()
154+
is DoubleValue -> returnTypeValue.value
155+
else -> 0.0
156+
}
157+
}
158+
159+
override suspend fun getMinPitch(): Double {
160+
val returnTypeValue =
161+
bridge.execute(
162+
GetMinPitch(),
163+
)
164+
165+
return when (returnTypeValue) {
166+
is StringValue -> returnTypeValue.value.toDouble()
167+
is DoubleValue -> returnTypeValue.value
168+
else -> 0.0
169+
}
170+
}
171+
144172
override fun setPitch(pitch: Double) {
145173
val clamped = pitch.coerceIn(0.0, 85.0)
146174
scope.launch {

MapTilerSDK/src/main/java/com/maptiler/maptilersdk/map/workers/zoomable/MTZoomable.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ interface MTZoomable {
2525
*/
2626
suspend fun getZoom(): Double
2727

28+
/**
29+
* Returns the map's maximum zoom level.
30+
*/
31+
suspend fun getMaxZoom(): Double
32+
33+
/**
34+
* Returns the map's minimum zoom level.
35+
*/
36+
suspend fun getMinZoom(): Double
37+
2838
/**
2939
* Sets the map's zoom level.
3040
*

MapTilerSDK/src/main/java/com/maptiler/maptilersdk/map/workers/zoomable/ZoomableWorker.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ package com.maptiler.maptilersdk.map.workers.zoomable
99
import com.maptiler.maptilersdk.bridge.MTBridge
1010
import com.maptiler.maptilersdk.bridge.MTBridgeReturnType.DoubleValue
1111
import com.maptiler.maptilersdk.bridge.MTBridgeReturnType.StringValue
12+
import com.maptiler.maptilersdk.commands.navigation.GetMaxZoom
13+
import com.maptiler.maptilersdk.commands.navigation.GetMinZoom
1214
import com.maptiler.maptilersdk.commands.navigation.GetZoom
1315
import com.maptiler.maptilersdk.commands.navigation.SetMaxZoom
1416
import com.maptiler.maptilersdk.commands.navigation.SetMinZoom
@@ -51,6 +53,32 @@ internal class ZoomableWorker(
5153
}
5254
}
5355

56+
override suspend fun getMaxZoom(): Double {
57+
val returnTypeValue =
58+
bridge.execute(
59+
GetMaxZoom(),
60+
)
61+
62+
return when (returnTypeValue) {
63+
is StringValue -> returnTypeValue.value.toDouble()
64+
is DoubleValue -> returnTypeValue.value
65+
else -> 0.0
66+
}
67+
}
68+
69+
override suspend fun getMinZoom(): Double {
70+
val returnTypeValue =
71+
bridge.execute(
72+
GetMinZoom(),
73+
)
74+
75+
return when (returnTypeValue) {
76+
is StringValue -> returnTypeValue.value.toDouble()
77+
is DoubleValue -> returnTypeValue.value
78+
else -> 0.0
79+
}
80+
}
81+
5482
override fun setZoom(zoom: Double) {
5583
scope.launch {
5684
bridge.execute(

MapTilerSDK/src/test/java/com/maptiler/maptilersdk/NavigationTests.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ package com.maptiler.maptilersdk
99
import com.maptiler.maptilersdk.bridge.MTBridge
1010
import com.maptiler.maptilersdk.commands.navigation.GetCenterClampedToGround
1111
import com.maptiler.maptilersdk.commands.navigation.GetCenterElevation
12+
import com.maptiler.maptilersdk.commands.navigation.GetMaxPitch
13+
import com.maptiler.maptilersdk.commands.navigation.GetMaxZoom
14+
import com.maptiler.maptilersdk.commands.navigation.GetMinPitch
15+
import com.maptiler.maptilersdk.commands.navigation.GetMinZoom
1216
import com.maptiler.maptilersdk.commands.navigation.GetZoom
1317
import com.maptiler.maptilersdk.commands.navigation.PanBy
1418
import com.maptiler.maptilersdk.commands.navigation.PanTo
@@ -34,6 +38,16 @@ class NavigationTests {
3438
assertEquals("${MTBridge.MAP_OBJECT}.getCenterElevation();", command.toJS())
3539
}
3640

41+
@Test fun getMaxZoomToJS_ReturnsCorrectJSString() {
42+
val command = GetMaxZoom()
43+
assertEquals("${MTBridge.MAP_OBJECT}.getMaxZoom();", command.toJS())
44+
}
45+
46+
@Test fun getMinZoomToJS_ReturnsCorrectJSString() {
47+
val command = GetMinZoom()
48+
assertEquals("${MTBridge.MAP_OBJECT}.getMinZoom();", command.toJS())
49+
}
50+
3751
@Test fun getZoomToJS_ReturnsCorrectJSString() {
3852
val command = GetZoom()
3953
assertEquals("${MTBridge.MAP_OBJECT}.getZoom();", command.toJS())
@@ -49,6 +63,16 @@ class NavigationTests {
4963
assertEquals("${MTBridge.MAP_OBJECT}.zoomOut();", command.toJS())
5064
}
5165

66+
@Test fun getMaxPitchToJS_ReturnsCorrectJSString() {
67+
val command = GetMaxPitch()
68+
assertEquals("${MTBridge.MAP_OBJECT}.getMaxPitch();", command.toJS())
69+
}
70+
71+
@Test fun getMinPitchToJS_ReturnsCorrectJSString() {
72+
val command = GetMinPitch()
73+
assertEquals("${MTBridge.MAP_OBJECT}.getMinPitch();", command.toJS())
74+
}
75+
5276
@Test fun setZoomToJS_ReturnsCorrectJSString() {
5377
val command = SetZoom(1.0)
5478
assertEquals("${MTBridge.MAP_OBJECT}.setZoom(1.0);", command.toJS())

0 commit comments

Comments
 (0)