mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
More map cleanup
This commit is contained in:
parent
0c70921935
commit
70e1bdb835
13 changed files with 210 additions and 126 deletions
37
Meshtastic/Views/MapKitMap/Custom/MapViewFitExtension.swift
Normal file
37
Meshtastic/Views/MapKitMap/Custom/MapViewFitExtension.swift
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
//
|
||||
// MapViewFitExtension.swift
|
||||
// Meshtastic
|
||||
//
|
||||
// Created by Garth Vander Houwen on 1/15/23.
|
||||
//
|
||||
|
||||
import MapKit
|
||||
|
||||
extension MKMapView {
|
||||
|
||||
func fitAllAnnotations(with padding: UIEdgeInsets = UIEdgeInsets(top: 100, left: 100, bottom: 100, right: 100)) {
|
||||
var zoomRect: MKMapRect = .null
|
||||
annotations.forEach({
|
||||
let annotationPoint = MKMapPoint($0.coordinate)
|
||||
let pointRect = MKMapRect(x: annotationPoint.x, y: annotationPoint.y, width: 0.01, height: 0.01)
|
||||
zoomRect = zoomRect.union(pointRect)
|
||||
})
|
||||
|
||||
setVisibleMapRect(zoomRect, edgePadding: padding, animated: true)
|
||||
}
|
||||
|
||||
func fit(annotations: [MKAnnotation], andShow show: Bool, with padding: UIEdgeInsets = UIEdgeInsets(top: 100, left: 100, bottom: 100, right: 100)) {
|
||||
var zoomRect: MKMapRect = .null
|
||||
annotations.forEach({
|
||||
let aPoint = MKMapPoint($0.coordinate)
|
||||
let rect = MKMapRect(x: aPoint.x, y: aPoint.y, width: 0.1, height: 0.1)
|
||||
zoomRect = zoomRect.isNull ? rect : zoomRect.union(rect)
|
||||
})
|
||||
|
||||
if show {
|
||||
addAnnotations(annotations)
|
||||
}
|
||||
|
||||
setVisibleMapRect(zoomRect, edgePadding: padding, animated: true)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue