https://github.com/stleamist/mkzoomlevel
An implementation of logarithmic zoom level getter & setter missed in MKMapView.
https://github.com/stleamist/mkzoomlevel
ios map mapkit mkmapview swift
Last synced: 4 months ago
JSON representation
An implementation of logarithmic zoom level getter & setter missed in MKMapView.
- Host: GitHub
- URL: https://github.com/stleamist/mkzoomlevel
- Owner: stleamist
- License: mit
- Created: 2020-05-18T07:02:37.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-12-21T15:00:12.000Z (about 5 years ago)
- Last Synced: 2025-04-22T16:43:13.904Z (10 months ago)
- Topics: ios, map, mapkit, mkmapview, swift
- Language: Swift
- Homepage:
- Size: 331 KB
- Stars: 21
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MKZoomLevel
MKZoomLevel is an implementation of zoom level getter & setter for MKMapView that works exactly the same as the private `_zoomLevel` property without resetting the camera angle.
## Features
- It returns exactly the same value as the internal `_zoomLevel` value as well as when the orientation or the angle is changed, which is in the `MKMapView`’s private API.
- It preserves the value of `heading` and `pitch` of the `camera` property for a new zoom level as they are, rather than resetting the camera angle.
- It returns the latest zoom level even when the animation of region change is not finished, in contrast with the `camera` property.
## Usage
```swift
import MapKit
import MKZoomLevel
let mapView = MKMapView()
// Get the zoom level
mapView.zoomLevel
// Set the zoom level
mapView.zoomLevel = 16.0
// Set the zoom level with an animation
mapView.setZoomLevel(16.0, animated: true)
```
## Installation
### Swift Package Manager
Add this repository as a dependency in your [`Package.swift`](https://developer.apple.com/documentation/swift_packages/package):
```swift
// swift-tools-version:5.0
import PackageDescription
let package = Package(
...,
dependencies: [
.package(url: "https://github.com/stleamist/MKZoomLevel.git", .upToNextMajor(from: "1.2.0"))
],
...
)
```
### Xcode
Select File \> Swift Packages \> Add Package Dependency, then enter the following URL:
```
https://github.com/stleamist/MKZoomLevel.git
```
For more details, see [Adding Package Dependencies to Your App](https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app).
## License
MKZoomLevel is released under the MIT license. See [LICENSE](/LICENSE) for details.