diff --git a/Localizable.xcstrings b/Localizable.xcstrings index b0f415a3..967567c0 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -6814,9 +6814,6 @@ }, "Empty" : { - }, - "Enable MB Tiles" : { - }, "Enable Notifications" : { @@ -20901,9 +20898,6 @@ }, "The last 4 of the device MAC address will be appended to the short name to set the device's BLE Name. Short name can be up to 4 bytes long." : { - }, - "The latest MBTiles file shared with meshtastic will be loaded into the map." : { - }, "The maximum interval that can elapse without a node broadcasting a position" : { diff --git a/Meshtastic/Extensions/UserDefaults.swift b/Meshtastic/Extensions/UserDefaults.swift index 11049bfb..0fbd680b 100644 --- a/Meshtastic/Extensions/UserDefaults.swift +++ b/Meshtastic/Extensions/UserDefaults.swift @@ -57,7 +57,6 @@ extension UserDefaults { case enableMapTraffic case enableMapPointsOfInterest case enableOfflineMaps - case enableOfflineMapsMBTiles case mapTileServer case enableOverlayServer case mapOverlayServer @@ -121,9 +120,6 @@ extension UserDefaults { @UserDefault(.enableOfflineMaps, defaultValue: false) static var enableOfflineMaps: Bool - @UserDefault(.enableOfflineMapsMBTiles, defaultValue: false) - static var enableOfflineMapsMBTiles: Bool - @UserDefault(.mapTileServer, defaultValue: .openStreetMap) static var mapTileServer: MapTileServer diff --git a/Meshtastic/MeshtasticApp.swift b/Meshtastic/MeshtasticApp.swift index c1bcf91a..ff691440 100644 --- a/Meshtastic/MeshtasticApp.swift +++ b/Meshtastic/MeshtasticApp.swift @@ -110,48 +110,6 @@ struct MeshtasticAppleApp: App { Logger.mesh.debug("User wants to open a Channel Settings URL: \(self.incomingUrl?.absoluteString ?? "No QR Code Link")") } else if url.absoluteString.lowercased().contains("meshtastic:///") { appState.router.route(url: url) - } else { - saveChannels = false - Logger.mesh.debug("User wants to import a MBTILES offline map file: \(self.incomingUrl?.absoluteString ?? "No Tiles link")") - } - - /// Only do the map tiles stuff if it is enabled - if UserDefaults.enableOfflineMapsMBTiles { - /// we are expecting a .mbtiles map file that contains raster data - /// save it to the documents directory, and name it offline_map.mbtiles - let fileManager = FileManager.default - let documentsDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first! - let destination = documentsDirectory.appendingPathComponent("offline_map.mbtiles", isDirectory: false) - - if !self.saveChannels { - - // tell the system we want the file please - guard url.startAccessingSecurityScopedResource() else { - return - } - - // do we need to delete an old one? - if fileManager.fileExists(atPath: destination.path) { - Logger.mesh.info("Found an old map file. Deleting it") - try? fileManager.removeItem(atPath: destination.path) - } - - do { - try fileManager.copyItem(at: url, to: destination) - } catch { - Logger.mesh.error("Copy MB Tile file failed. Error: \(error.localizedDescription)") - } - - if fileManager.fileExists(atPath: destination.path) { - Logger.mesh.info("Saved the map file") - - // need to tell the map view that it needs to update and try loading the new overlay - UserDefaults.standard.set(Date().timeIntervalSince1970, forKey: "lastUpdatedLocalMapFile") - - } else { - Logger.mesh.error("Didn't save the map file") - } - } } }) .task { diff --git a/Meshtastic/Views/MapKitMap/Custom/MapViewSwiftUI.swift b/Meshtastic/Views/MapKitMap/Custom/MapViewSwiftUI.swift index 5c7291a5..bf196f6d 100644 --- a/Meshtastic/Views/MapKitMap/Custom/MapViewSwiftUI.swift +++ b/Meshtastic/Views/MapKitMap/Custom/MapViewSwiftUI.swift @@ -105,13 +105,12 @@ struct MapViewSwiftUI: UIViewRepresentable { switch selectedMapLayer { case .offline: mapView.mapType = .standard - if !UserDefaults.enableOfflineMapsMBTiles { - let overlay = TileOverlay() - overlay.canReplaceMapContent = false - overlay.minimumZ = UserDefaults.mapTileServer.zoomRange.startIndex - overlay.maximumZ = UserDefaults.mapTileServer.zoomRange.endIndex - mapView.addOverlay(overlay, level: UserDefaults.mapTilesAboveLabels ? .aboveLabels : .aboveRoads) - } + let overlay = TileOverlay() + overlay.canReplaceMapContent = false + overlay.minimumZ = UserDefaults.mapTileServer.zoomRange.startIndex + overlay.maximumZ = UserDefaults.mapTileServer.zoomRange.endIndex + mapView.addOverlay(overlay, level: UserDefaults.mapTilesAboveLabels ? .aboveLabels : .aboveRoads) + case .satellite: mapView.mapType = .satellite case .hybrid: @@ -133,32 +132,7 @@ struct MapViewSwiftUI: UIViewRepresentable { } } } - private func setMbtilesOverlay(mapView: MKMapView) { - // MBTiles Offline - if UserDefaults.enableOfflineMaps && UserDefaults.enableOfflineMapsMBTiles { - if self.customMapOverlay != self.presentCustomMapOverlayHash || self.loadedLastUpdatedLocalMapFile != self.lastUpdatedLocalMapFile { - mapView.removeOverlays(mapView.overlays) - if self.customMapOverlay != nil { - let fileManager = FileManager.default - let documentsDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first! - let tilePath = documentsDirectory.appendingPathComponent("offline_map.mbtiles", isDirectory: false).path - if fileManager.fileExists(atPath: tilePath) { - Logger.services.info("Loading local map file") - if let overlay = LocalMBTileOverlay(mbTilePath: tilePath) { - overlay.canReplaceMapContent = false// customMapOverlay.canReplaceMapContent - mapView.addOverlay(overlay) - } - } else { - Logger.services.info("Couldn't find a local map file to load") - } - } - DispatchQueue.main.async { - self.presentCustomMapOverlayHash = self.customMapOverlay - self.loadedLastUpdatedLocalMapFile = self.lastUpdatedLocalMapFile - } - } - } - } + func makeUIView(context: Context) -> MKMapView { currentMapLayer = nil mapView.delegate = context.coordinator @@ -166,8 +140,6 @@ struct MapViewSwiftUI: UIViewRepresentable { return mapView } func updateUIView(_ mapView: MKMapView, context: Context) { - // Set MBTiles overlay layer - setMbtilesOverlay(mapView: mapView) // Set selected map base layer setMapBaseLayer(mapView: mapView) // Set map tile server and weather overlay layers diff --git a/Meshtastic/Views/Nodes/NodeMap.swift b/Meshtastic/Views/Nodes/NodeMap.swift index 5630fa8f..53b0aae3 100644 --- a/Meshtastic/Views/Nodes/NodeMap.swift +++ b/Meshtastic/Views/Nodes/NodeMap.swift @@ -16,14 +16,12 @@ struct NodeMap: View { @ObservedObject var router: Router - @State var selectedMapLayer: MapLayer = UserDefaults.mapLayer @State var enableMapRecentering: Bool = UserDefaults.enableMapRecentering @State var enableMapRouteLines: Bool = UserDefaults.enableMapRouteLines @State var enableMapNodeHistoryPins: Bool = UserDefaults.enableMapNodeHistoryPins @State var enableOfflineMaps: Bool = UserDefaults.enableOfflineMaps @State var selectedTileServer: MapTileServer = UserDefaults.mapTileServer - @State var enableOfflineMapsMBTiles: Bool = UserDefaults.enableOfflineMapsMBTiles @State var enableOverlayServer: Bool = UserDefaults.enableOverlayServer @State var selectedOverlayServer: MapOverlayServer = UserDefaults.mapOverlayServer @State var mapTilesAboveLabels: Bool = UserDefaults.mapTilesAboveLabels @@ -172,46 +170,32 @@ struct NodeMap: View { } if enableOfflineMaps { VStack(alignment: .leading) { - if !enableOfflineMapsMBTiles { - Picker(selection: $selectedTileServer, - label: Text("Tile Server")) { - ForEach(MapTileServer.allCases, id: \.self) { tsl in - Text(tsl.description) - } - } - .pickerStyle(DefaultPickerStyle()) - .onChange(of: (selectedTileServer)) { newSelectedTileServer in - UserDefaults.mapTileServer = newSelectedTileServer - } - Text("Attribution:") - .fontWeight(.semibold) - .font(.footnote) - Text(LocalizedStringKey(selectedTileServer.attribution)) - .font(.footnote) - .foregroundColor(.gray) - .padding(0) - Divider() - Toggle(isOn: $mapTilesAboveLabels) { - Text("Tiles above Labels") - } - .toggleStyle(SwitchToggleStyle(tint: .accentColor)) - .onTapGesture { - self.mapTilesAboveLabels.toggle() - UserDefaults.mapTilesAboveLabels = self.mapTilesAboveLabels + Picker(selection: $selectedTileServer, + label: Text("Tile Server")) { + ForEach(MapTileServer.allCases, id: \.self) { tsl in + Text(tsl.description) } } + .pickerStyle(DefaultPickerStyle()) + .onChange(of: (selectedTileServer)) { newSelectedTileServer in + UserDefaults.mapTileServer = newSelectedTileServer + } + Text("Attribution:") + .fontWeight(.semibold) + .font(.footnote) + Text(LocalizedStringKey(selectedTileServer.attribution)) + .font(.footnote) + .foregroundColor(.gray) + .padding(0) Divider() - Toggle(isOn: $enableOfflineMapsMBTiles) { - Text("Enable MB Tiles") + Toggle(isOn: $mapTilesAboveLabels) { + Text("Tiles above Labels") } .toggleStyle(SwitchToggleStyle(tint: .accentColor)) .onTapGesture { - self.enableOfflineMapsMBTiles.toggle() - UserDefaults.enableOfflineMapsMBTiles = self.enableOfflineMapsMBTiles + self.mapTilesAboveLabels.toggle() + UserDefaults.mapTilesAboveLabels = self.mapTilesAboveLabels } - Text("The latest MBTiles file shared with meshtastic will be loaded into the map.") - .font(.footnote) - .foregroundColor(.gray) } } }