Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issues with tiles in ios13 and cache size calculation #139

Merged
merged 6 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions OpenGpxTracker/GPXMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import MapCache
/// If the user opens the file in a session for the second, then tracks some seg ments and saves
/// the file again, the resulting gpx file will have two tracks.
///

class GPXMapView: MKMapView {

/// Current session of GPX location logging. Handles all background tasks and recording.
Expand Down Expand Up @@ -63,38 +64,50 @@ class GPXMapView: MKMapView {
/// initialized on MapViewDelegate
var headingImageView: UIImageView?


/// Selected tile server.
/// - SeeAlso: GPXTileServer
var tileServer: GPXTileServer = .apple {
willSet {
print("Setting map tiles overlay to: \(newValue.name)" )

// remove current overlay
if self.tileServer != .apple {
//to see apple maps we need to remove the overlay added by map cache.
self.removeOverlay(self.tileServerOverlay)
}
//add new overlay to map
if newValue != .apple {

/// Min distance to the floor of the camera
if #available(iOS 13, *) {
self.setCameraZoomRange(MKMapView.CameraZoomRange(minCenterCoordinateDistance: newValue.minCameraDistance, maxCenterCoordinateDistance: -1), animated: true)
}

//add new overlay to map if not using Apple Maps
if newValue == .apple {
if #available(iOS 13, *) {
overrideUserInterfaceStyle = .unspecified
NotificationCenter.default.post(name: .updateAppearance, object: nil, userInfo: nil)
}

} else {
// if map is third party, dark mode is disabled.
if #available(iOS 13, *) {
overrideUserInterfaceStyle = .light
NotificationCenter.default.post(name: .updateAppearance, object: nil, userInfo: nil)
}
//Update cacheConfig
var config = MapCacheConfig(withUrlTemplate: newValue.templateUrl)
config.subdomains = newValue.subdomains

if newValue.maximumZ > 0 {
config.maximumZ = newValue.maximumZ
}
if newValue.minimumZ > 0 {
config.minimumZ = newValue.minimumZ
}
let cache = MapCache(withConfig: config)
// the overlay returned substitutes Apple Maps tile overlay.
// we need to keep a reference to remove it, in case we return back to Apple Maps.
self.tileServerOverlay = useCache(cache)
}
else {
if #available(iOS 13, *) {
overrideUserInterfaceStyle = .unspecified
NotificationCenter.default.post(name: .updateAppearance, object: nil, userInfo: nil)
}
}
}
}

Expand Down
58 changes: 57 additions & 1 deletion OpenGpxTracker/GPXTileServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ enum GPXTileServer: Int {
switch self {
case .apple: return ""
case .openStreetMap: return "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
case .cartoDB: return "https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png"
// case .cartoDB: return "https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png"
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 .AnotherMap: return "http://another.map.tile.server/{z}/{x}/{y}.png"
}
Expand All @@ -70,6 +71,61 @@ enum GPXTileServer: Int {
//case .AnotherMap: return ["a","b"]
}
}
/// Maximum zoom level the tile server supports
/// Tile servers provide files till a certain level of zoom that ranges from 0 to maximumZ.
/// If map zooms more than the limit level, tiles won't be requested.
///
/// Typically the value is around 19,20 or 21.
///
/// Use negative to avoid setting a limit.
///
/// - see https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Tile_servers
///
var maximumZ: Int {
switch self {
case .apple: return -1
case .openStreetMap: return 19
case .cartoDB: return 21
case .openTopoMap: return 17
//case .AnotherMap: return 10
}
}
///
/// Minimum zoom supported by the tile server
///
/// This limits the tiles requested based on current zoom level.
/// No tiles will be requested for zooms levels lower that this.
///
/// Needs to be 0 or larger.
///
var minimumZ: Int {
switch self {
case .apple: return 0
case .openStreetMap: return 0
case .cartoDB: return 0
case .openTopoMap: return 0
//case .AnotherMap: return ["a","b"]
}
}

/// Minimum distance from the floor of the camera (in meters)
///
/// Note that there is a relationship between the mazimumZ and the camera distance to the floor.
/// Because of that, this parameter be automatically calculated in the future.
/// For existing tile servers, it was calculated with trial and error.
///
/// Negative value means no limit.
var minCameraDistance: Double {
switch self {
case .apple: return -1.0 // Not limited
case .openStreetMap: return 750.0
case .cartoDB: return 200.0
case .openTopoMap: return 2850.0
//case .AnotherMap: return 1000.0
}
}


/// Returns the number of tile servers currently defined
static var count: Int { return GPXTileServer.openTopoMap.rawValue + 1}
}
2 changes: 2 additions & 0 deletions OpenGpxTracker/MapViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ class MapViewDelegate: NSObject, MKMapViewDelegate, UIAlertViewDelegate {
print("MapView: User interaction has ended")

map.updateHeading()

//Is
}

}
3 changes: 2 additions & 1 deletion OpenGpxTracker/PreferencesTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ class PreferencesTableViewController: UITableViewController, UINavigationBarDele
case kUseOfflineCacheCell:
cell = UITableViewCell(style: .subtitle, reuseIdentifier: "CacheCell")
cell.textLabel?.text = NSLocalizedString("OFFLINE_CACHE", comment: "no comment")
cell.detailTextLabel?.text = Int(cache.size).asFileSize()
let fileSize = cache.diskCache.fileSize ?? 0
cell.detailTextLabel?.text = Int(fileSize).asFileSize()
if preferences.useCache {
cell.accessoryType = .checkmark
}
Expand Down
4 changes: 3 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ end
target 'OpenGpxTracker' do
platform :ios, '8.0'
shared_pods
pod 'MapCache', '~> 0.5.3'
pod 'MapCache', '~> 0.6.0'
#pod 'MapCache', git: 'https://github.com/merlos/MapCache.git' :branch => 'master'

end

target 'OpenGpxTracker-Watch Extension' do
Expand Down
8 changes: 4 additions & 4 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
PODS:
- CoreGPX (0.7.1)
- MapCache (0.5.3)
- MapCache (0.6.0)

DEPENDENCIES:
- CoreGPX (from `https://github.com/VincentNeo/CoreGPX.git`)
- MapCache (~> 0.5.3)
- MapCache (~> 0.6.0)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
Expand All @@ -21,8 +21,8 @@ CHECKOUT OPTIONS:

SPEC CHECKSUMS:
CoreGPX: a25d38752ebe5e5dc0ecb83c2dfc096caae3aee5
MapCache: 9d1ee8fbfa3b115ff00096792b575d85a5f862c5
MapCache: 8afa98ddc3539a384ba75b019284cded95aaccab

PODFILE CHECKSUM: 667e05785b0101bb71c48243409d9a9d922cbb99
PODFILE CHECKSUM: 7706b404bc9a04597c49524bc107c3f1d2ebe02c

COCOAPODS: 1.7.5
8 changes: 4 additions & 4 deletions Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading