Skip to content

Commit 9cce4dd

Browse files
AnkaAnka
authored andcommitted
RD-1258: Add Max and Min Zoom and Pitch Getters - Swift SDK
1 parent 1c6be45 commit 9cce4dd

File tree

7 files changed

+192
-0
lines changed

7 files changed

+192
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// Copyright (c) 2025, MapTiler
3+
// All rights reserved.
4+
// SPDX-License-Identifier: BSD 3-Clause
5+
//
6+
// GetMaxPitch.swift
7+
// MapTilerSDK
8+
//
9+
10+
package struct GetMaxPitch: MTCommand {
11+
package func toJS() -> JSString {
12+
return "\(MTBridge.mapObject).getMaxPitch();"
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// Copyright (c) 2025, MapTiler
3+
// All rights reserved.
4+
// SPDX-License-Identifier: BSD 3-Clause
5+
//
6+
// GetMaxZoom.swift
7+
// MapTilerSDK
8+
//
9+
10+
package struct GetMaxZoom: MTCommand {
11+
package func toJS() -> JSString {
12+
return "\(MTBridge.mapObject).getMaxZoom();"
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// Copyright (c) 2025, MapTiler
3+
// All rights reserved.
4+
// SPDX-License-Identifier: BSD 3-Clause
5+
//
6+
// GetMinPitch.swift
7+
// MapTilerSDK
8+
//
9+
10+
package struct GetMinPitch: MTCommand {
11+
package func toJS() -> JSString {
12+
return "\(MTBridge.mapObject).getMinPitch();"
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// Copyright (c) 2025, MapTiler
3+
// All rights reserved.
4+
// SPDX-License-Identifier: BSD 3-Clause
5+
//
6+
// GetMinZoom.swift
7+
// MapTilerSDK
8+
//
9+
10+
package struct GetMinZoom: MTCommand {
11+
package func toJS() -> JSString {
12+
return "\(MTBridge.mapObject).getMinZoom();"
13+
}
14+
}

Sources/MapTilerSDK/Map/Extensions/MTNavigable/MTMapView+MTNavigable.swift

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,42 @@ extension MTMapView: MTNavigable {
313313
runCommandWithDoubleReturnValue(GetPitch(), completion: completionHandler)
314314
}
315315

316+
/// Returns the map's maximum pitch (tilt).
317+
///
318+
/// The map's maximum pitch, measured in degrees away from the plane of the screen.
319+
/// - Parameter completionHandler: A handler block to execute when function finishes.
320+
@available(iOS, deprecated: 16.0, message: "Prefer the async version for modern concurrency handling")
321+
public func getMaxPitch(completionHandler: @escaping (Result<Double, MTError>) -> Void) {
322+
runCommandWithDoubleReturnValue(GetMaxPitch(), completion: completionHandler)
323+
}
324+
325+
/// Returns the map's maximum zoom.
326+
///
327+
/// The map's maximum zoom level.
328+
/// - Parameter completionHandler: A handler block to execute when function finishes.
329+
@available(iOS, deprecated: 16.0, message: "Prefer the async version for modern concurrency handling")
330+
public func getMaxZoom(completionHandler: @escaping (Result<Double, MTError>) -> Void) {
331+
runCommandWithDoubleReturnValue(GetMaxZoom(), completion: completionHandler)
332+
}
333+
334+
/// Returns the map's minimum pitch (tilt).
335+
///
336+
/// The map's minimum pitch, measured in degrees away from the plane of the screen.
337+
/// - Parameter completionHandler: A handler block to execute when function finishes.
338+
@available(iOS, deprecated: 16.0, message: "Prefer the async version for modern concurrency handling")
339+
public func getMinPitch(completionHandler: @escaping (Result<Double, MTError>) -> Void) {
340+
runCommandWithDoubleReturnValue(GetMinPitch(), completion: completionHandler)
341+
}
342+
343+
/// Returns the map's minimum zoom.
344+
///
345+
/// The map's minimum zoom level.
346+
/// - Parameter completionHandler: A handler block to execute when function finishes.
347+
@available(iOS, deprecated: 16.0, message: "Prefer the async version for modern concurrency handling")
348+
public func getMinZoom(completionHandler: @escaping (Result<Double, MTError>) -> Void) {
349+
runCommandWithDoubleReturnValue(GetMinZoom(), completion: completionHandler)
350+
}
351+
316352
/// Pans the map by the specified offset.
317353
/// - Parameters:
318354
/// - offset: The x and y coordinates by which to pan the map.
@@ -624,6 +660,70 @@ extension MTMapView {
624660
}
625661
}
626662

663+
/// Returns the map's maximum pitch (tilt).
664+
///
665+
/// The map's maximum pitch, measured in degrees away from the plane of the screen.
666+
public func getMaxPitch() async -> Double {
667+
await withCheckedContinuation { continuation in
668+
getMaxPitch { result in
669+
switch result {
670+
case .success(let result):
671+
continuation.resume(returning: result)
672+
case .failure:
673+
continuation.resume(returning: .nan)
674+
}
675+
}
676+
}
677+
}
678+
679+
/// Returns the map's maximum zoom.
680+
///
681+
/// The map's maximum zoom level.
682+
public func getMaxZoom() async -> Double {
683+
await withCheckedContinuation { continuation in
684+
getMaxZoom { result in
685+
switch result {
686+
case .success(let result):
687+
continuation.resume(returning: result)
688+
case .failure:
689+
continuation.resume(returning: .nan)
690+
}
691+
}
692+
}
693+
}
694+
695+
/// Returns the map's minimum pitch (tilt).
696+
///
697+
/// The map's minimum pitch, measured in degrees away from the plane of the screen.
698+
public func getMinPitch() async -> Double {
699+
await withCheckedContinuation { continuation in
700+
getMinPitch { result in
701+
switch result {
702+
case .success(let result):
703+
continuation.resume(returning: result)
704+
case .failure:
705+
continuation.resume(returning: .nan)
706+
}
707+
}
708+
}
709+
}
710+
711+
/// Returns the map's minimum zoom.
712+
///
713+
/// The map's minimum zoom level.
714+
public func getMinZoom() async -> Double {
715+
await withCheckedContinuation { continuation in
716+
getMinZoom { result in
717+
switch result {
718+
case .success(let result):
719+
continuation.resume(returning: result)
720+
case .failure:
721+
continuation.resume(returning: .nan)
722+
}
723+
}
724+
}
725+
}
726+
627727
/// Pans the map by the specified offset.
628728
/// - Parameters:
629729
/// - offset: The x and y coordinates by which to pan the map.

Sources/MapTilerSDK/Map/Extensions/MTNavigable/MTNavigable.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ public protocol MTNavigable {
110110
/// Returns the map's current pitch.
111111
func getPitch() async -> Double
112112

113+
/// Returns the map's maximum pitch.
114+
func getMaxPitch() async -> Double
115+
116+
/// Returns the map's maximum zoom.
117+
func getMaxZoom() async -> Double
118+
119+
/// Returns the map's minimum pitch.
120+
func getMinPitch() async -> Double
121+
122+
/// Returns the map's minimum zoom.
123+
func getMinZoom() async -> Double
124+
113125
/// Returns the map's current center.
114126
func getCenter() async -> CLLocationCoordinate2D
115127

Tests/MapTilerSDKTests/MTNavigationTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,30 @@ struct MTNavigationTests {
7474
#expect(GetPitch().toJS() == getPitchJS)
7575
}
7676

77+
@Test func getMaxPitchCommand_shouldMatchJS() async throws {
78+
let getMaxPitchJS = "\(MTBridge.mapObject).getMaxPitch();"
79+
80+
#expect(GetMaxPitch().toJS() == getMaxPitchJS)
81+
}
82+
83+
@Test func getMaxZoomCommand_shouldMatchJS() async throws {
84+
let getMaxZoomJS = "\(MTBridge.mapObject).getMaxZoom();"
85+
86+
#expect(GetMaxZoom().toJS() == getMaxZoomJS)
87+
}
88+
89+
@Test func getMinPitchCommand_shouldMatchJS() async throws {
90+
let getMinPitchJS = "\(MTBridge.mapObject).getMinPitch();"
91+
92+
#expect(GetMinPitch().toJS() == getMinPitchJS)
93+
}
94+
95+
@Test func getMinZoomCommand_shouldMatchJS() async throws {
96+
let getMinZoomJS = "\(MTBridge.mapObject).getMinZoom();"
97+
98+
#expect(GetMinZoom().toJS() == getMinZoomJS)
99+
}
100+
77101
@Test func getCenterClampedToGroundCommand_shouldMatchJS() async throws {
78102
let getCenterClampedToGroundJS = "\(MTBridge.mapObject).getCenterClampedToGround();"
79103

0 commit comments

Comments
 (0)