mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Add back tile server settings
This commit is contained in:
parent
9faead1d6a
commit
82e2c03d57
2 changed files with 85 additions and 0 deletions
|
|
@ -30,6 +30,11 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
var customMapOverlay: CustomMapOverlay?
|
||||
@State private var presentCustomMapOverlayHash: CustomMapOverlay?
|
||||
|
||||
// Custom Tile Server
|
||||
@AppStorage("meshMapCustomTileServer") private var tileServerUrl = ""
|
||||
var tileRenderer: MKTileOverlayRenderer?
|
||||
let tileServer: MapTileServerLinks = .openStreetMaps
|
||||
|
||||
func makeUIView(context: Context) -> MKMapView {
|
||||
// Map View Parameters
|
||||
mapView.mapType = mapViewType
|
||||
|
|
@ -65,6 +70,10 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
mapView.showsScale = true
|
||||
mapView.showsTraffic = true
|
||||
|
||||
let overlay = TileServerOverlay() // Offline-Map-Tiles
|
||||
overlay.canReplaceMapContent = true
|
||||
mapView.addOverlay(overlay, level: .aboveLabels)
|
||||
|
||||
#if targetEnvironment(macCatalyst)
|
||||
// Show the default always visible compass and the mac only controls
|
||||
mapView.showsCompass = true
|
||||
|
|
@ -167,6 +176,29 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
mapView.showsUserLocation = true
|
||||
}
|
||||
mapView.setUserTrackingMode(userTrackingMode, animated: true)
|
||||
|
||||
if tileServerUrl.count > 0 {
|
||||
tileRenderer?.alpha = 0.0
|
||||
let overlays = mapView.overlays
|
||||
if mapView.mapType == .standard {
|
||||
let overlay = MKTileOverlay(urlTemplate: tileServerUrl)
|
||||
if overlays.contains(where: {$0 is MKPolyline}) {
|
||||
mapView.addOverlay(overlay, level: .aboveLabels)
|
||||
if let poly_overlay = overlays.filter({$0 is MKPolyline}).first {
|
||||
mapView.addOverlay(poly_overlay, level: .aboveRoads)
|
||||
}
|
||||
} else {
|
||||
mapView.addOverlay(overlay, level: .aboveRoads)
|
||||
|
||||
}
|
||||
} else {
|
||||
for overlay in overlays {
|
||||
if let ove = overlay as? MKTileOverlay {
|
||||
mapView.removeOverlay(ove)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -465,3 +497,43 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TileServerOverlay: MKTileOverlay {
|
||||
|
||||
override func url(forTilePath path: MKTileOverlayPath) -> URL { // lädt die Map-Tiles
|
||||
|
||||
if path.z <= 5 { // Es wurden nur Map-Tiles für z <= 5 geladen.
|
||||
|
||||
let fileManager = FileManager.default // Objekt zum Verwalten des Dateisystems
|
||||
|
||||
if var url = fileManager.urls(for: .cachesDirectory, in: .userDomainMask).first { // Url vom Cache-Verzeichnis
|
||||
|
||||
// Pfad wird erstellt
|
||||
|
||||
url.appendPathComponent("map")
|
||||
url.appendPathComponent("\(path.z)")
|
||||
url.appendPathComponent("\(path.x)")
|
||||
url.appendPathComponent("\(path.y).png")
|
||||
|
||||
if fileManager.fileExists(atPath: url.path) { // Wenn das Map-Tile existiert...
|
||||
|
||||
return url
|
||||
}
|
||||
else {
|
||||
|
||||
//logger.info("OSMTileOverlay: MapTiles have not been downloaded yet.")
|
||||
return Bundle.main.url(forResource: "default", withExtension: "png")!
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
//logger.error("OSMTileOverlay: Could not find cache url.")
|
||||
return Bundle.main.url(forResource: "default", withExtension: "png")!
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
return Bundle.main.url(forResource: "default", withExtension: "png")!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,6 +120,19 @@ struct AppSettings: View {
|
|||
Label("Show Route Lines", systemImage: "road.lanes")
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
|
||||
HStack {
|
||||
|
||||
Label("Tile Server", systemImage: "square.grid.3x2")
|
||||
TextField(
|
||||
"Tile Server",
|
||||
text: $userSettings.meshMapCustomTileServer,
|
||||
axis: .vertical
|
||||
)
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
.keyboardType(.asciiCapable)
|
||||
.disableAutocorrection(true)
|
||||
}
|
||||
}
|
||||
HStack {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue