diff --git a/Avenue/GPXTileServer.swift b/Avenue/GPXTileServer.swift index 521a78e..3c342e1 100644 --- a/Avenue/GPXTileServer.swift +++ b/Avenue/GPXTileServer.swift @@ -17,13 +17,13 @@ import Foundation /// A tile server is defined by an internal id (for instance .openStreetMap), a name string for displaying /// on the interface and a URL template. /// -enum GPXTileServer: Int { +enum GPXTileServer: Int, CaseIterable { /// Apple tile server case apple /// Open Street Map tile server - case openStreetMap + case openStreetMap = 4 //case AnotherMap /// CartoDB tile server @@ -35,6 +35,10 @@ enum GPXTileServer: Int { /// Wikimedia tile server case wikimedia + + /// CyclOSM tile server + case cyclOSM + ///String that describes the selected tile server. var name: String { switch self { @@ -43,6 +47,7 @@ enum GPXTileServer: Int { case .cartoDB: return "CARTO" case .openTopoMap: return "OpenTopoMap" case .wikimedia: return "Wikimedia" + case .cyclOSM: return "CyclOSM" //case .AnotherMap: return "My Map" } } @@ -56,6 +61,7 @@ enum GPXTileServer: Int { case .cartoDB: return "https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png" case .openTopoMap: return "https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png" case .wikimedia: return "https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png" + case .cyclOSM: return "https://{s}.tile-cyclosm.openstreetmap.fr/cyclosm/{z}/{x}/{y}.png" //case .AnotherMap: return "http://another.map.tile.server/{z}/{x}/{y}.png" } } @@ -83,6 +89,7 @@ enum GPXTileServer: Int { case .cartoDB: return ["a","b","c","d"] case .openTopoMap: return ["a","b","c"] case .wikimedia: return [] + case .cyclOSM: return ["a", "b", "c"] //case .AnotherMap: return ["a","b"] } } @@ -103,6 +110,7 @@ enum GPXTileServer: Int { case .cartoDB: return 25 case .openTopoMap: return 17 case .wikimedia: return 19 + case .cyclOSM: return 19 //case .AnotherMap: return 10 } } @@ -121,6 +129,7 @@ enum GPXTileServer: Int { case .cartoDB: return 0 case .openTopoMap: return 0 case .wikimedia: return 0 + case .cyclOSM: return 0 //case .AnotherMap: return ["a","b"] } } @@ -135,21 +144,11 @@ enum GPXTileServer: Int { var minCameraDistance: Double { switch self { case .apple: return -1.0 // Not limited - case .openStreetMap: return 850.0 + case .openStreetMap: return 700.0 case .cartoDB: return 0 case .openTopoMap: return 2850.0 case .wikimedia: return 350.0 - //case .AnotherMap: return 1000.0 - } - } - - var tileSize: Int { - switch self { - case .apple: return -1 // Not limited - case .openStreetMap: return 256 - case .cartoDB: return 512 - case .openTopoMap: return 256 - case .wikimedia: return 512 + case .cyclOSM: return 700.0 //case .AnotherMap: return 1000.0 } } @@ -161,9 +160,14 @@ enum GPXTileServer: Int { case .cartoDB: return "© OpenStreetMap contributors, © CARTO" case .openTopoMap: return "© OpenStreetMap contributors, SRTM, © OpenTopoMap (CC-BY-SA)" case .wikimedia: return "Wikimedia Maps | Map Data © OpenStreetMap contributors" + case .cyclOSM: return " CyclOSM | Map data © OpenStreetMap contributors" } } /// Returns the number of tile servers currently defined - static var count: Int { return GPXTileServer.openTopoMap.rawValue + 1} + static var count: Int { return GPXTileServer.cyclOSM.rawValue + 1 } + + static var allCases: [GPXTileServer] { return [.openStreetMap, .cartoDB, + .openTopoMap, .wikimedia, + .cyclOSM]} } diff --git a/Avenue/ViewController.swift b/Avenue/ViewController.swift index dd90563..11b389b 100644 --- a/Avenue/ViewController.swift +++ b/Avenue/ViewController.swift @@ -46,19 +46,19 @@ class ViewController: NSViewController, MKMapViewDelegate { /// Min distance to the floor of the camera if #available(OSX 10.15, *) { - mapView.setCameraZoomRange(MKMapView.CameraZoomRange(minCenterCoordinateDistance: newValue.minCameraDistance, maxCenterCoordinateDistance: -1), animated: true) - miniMap.setCameraZoomRange(MKMapView.CameraZoomRange(minCenterCoordinateDistance: newValue.minCameraDistance, maxCenterCoordinateDistance: -1), animated: true) + mapView.setCameraZoomRange(MKMapView.CameraZoomRange(minCenterCoordinateDistance: newValue.minCameraDistance, maxCenterCoordinateDistance: -1), animated: true) + miniMap.setCameraZoomRange(MKMapView.CameraZoomRange(minCenterCoordinateDistance: newValue.minCameraDistance, maxCenterCoordinateDistance: -1), animated: true) } //add new overlay to map if not using Apple Maps if newValue != .apple { - //MapCache is still iOS only. May arrive at later date + //Update cacheConfig var tileSize = 256 var config = MapCacheConfig(withUrlTemplate: newValue.templateUrl) if Preferences.shared.preferRetina, let retinaUrl = newValue.retinaUrl { config.urlTemplate = retinaUrl - tileSize = newValue.tileSize + tileSize = 512 } config.subdomains = newValue.subdomains @@ -201,10 +201,9 @@ class ViewController: NSViewController, MKMapViewDelegate { dropDownMenu.addItem(withTitle: " Hybrid") dropDownMenu.addItem(withTitle: " Satellite") dropDownMenu.menu?.addItem(.separator()) - dropDownMenu.addItem(withTitle: GPXTileServer.openStreetMap.name) - dropDownMenu.addItem(withTitle: GPXTileServer.cartoDB.name) - dropDownMenu.addItem(withTitle: GPXTileServer.openTopoMap.name) - dropDownMenu.addItem(withTitle: GPXTileServer.wikimedia.name) + for server in GPXTileServer.allCases { + dropDownMenu.addItem(withTitle: server.name) + } dropDownMenu.select(dropDownMenu.item(at: 0)) dropDownMenu.wantsLayer = true dropDownMenu.layer?.opacity = 0.9 @@ -377,12 +376,8 @@ class ViewController: NSViewController, MKMapViewDelegate { case 1: mapType = .hybridFlyover; tileServer = .apple case 2: mapType = .satelliteFlyover; tileServer = .apple // case 3: will be a seperator; > 4 = custom - case 4: mapType = .standard; tileServer = .openStreetMap - case 5: mapType = .standard; tileServer = .cartoDB - case 6: mapType = .standard; tileServer = .openTopoMap - case 7: mapType = .standard; tileServer = .wikimedia default: - mapType = .standard + mapType = .standard; tileServer = GPXTileServer(rawValue: sender.indexOfSelectedItem) ?? .apple } let userInfo = ["index" : sender.indexOfSelectedItem, "filePath" : self.filePath] as [String : Any] NotificationCenter.default.post(name: NSNotification.Name("EncodeRestorableState"), object: nil, userInfo: userInfo)