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

Map labels are no longer blank and using China Map Style URLs if the application is configured to use Mapbox China APIs #1558

Merged
merged 11 commits into from
Jul 25, 2018
8 changes: 4 additions & 4 deletions MapboxNavigation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
C5EF397520599120009A2C50 /* straight-line.json in Resources */ = {isa = PBXBuildFile; fileRef = C5EF397420599120009A2C50 /* straight-line.json */; };
C5F2DCA0206DBF5E002F99F6 /* Sequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5F2DC9F206DBF5E002F99F6 /* Sequence.swift */; };
C5F2DCA1206DBF5E002F99F6 /* Sequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5F2DC9F206DBF5E002F99F6 /* Sequence.swift */; };
CFD47D9020FD85EC00BC1E49 /* NetworkConfiguartion.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFD47D8F20FD85EC00BC1E49 /* NetworkConfiguartion.swift */; };
CFD47D9020FD85EC00BC1E49 /* MGLAccountManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFD47D8F20FD85EC00BC1E49 /* MGLAccountManager.swift */; };
DA23C9611F4FC05C00BA9522 /* MGLMapView+MGLNavigationAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 35D825F91E6A2DBE0088F83B /* MGLMapView+MGLNavigationAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
DA3525702010A5210048DDFC /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = DA35256E2010A5200048DDFC /* Localizable.stringsdict */; };
DAAE5F301EAE4C4700832871 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = DAAE5F321EAE4C4700832871 /* Localizable.strings */; };
Expand Down Expand Up @@ -664,7 +664,7 @@
C5E7A31B1F4F6828001CB015 /* NavigationRouteOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationRouteOptions.swift; sourceTree = "<group>"; };
C5EF397420599120009A2C50 /* straight-line.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "straight-line.json"; sourceTree = "<group>"; };
C5F2DC9F206DBF5E002F99F6 /* Sequence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sequence.swift; sourceTree = "<group>"; };
CFD47D8F20FD85EC00BC1E49 /* NetworkConfiguartion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkConfiguartion.swift; sourceTree = "<group>"; };
CFD47D8F20FD85EC00BC1E49 /* MGLAccountManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MGLAccountManager.swift; sourceTree = "<group>"; };
DA1811FD20128B0900C91918 /* he */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = he; path = he.lproj/Main.strings; sourceTree = "<group>"; };
DA1811FE20128B0900C91918 /* he */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = he; path = he.lproj/Navigation.strings; sourceTree = "<group>"; };
DA18120120128B7B00C91918 /* he */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = he; path = he.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -917,7 +917,7 @@
356B7D8A1EE166E100FE5B89 /* scripts */,
351BEC201E5BD4DC006FE110 /* Supporting files */,
C51923B51EA55CD4002AF9E1 /* Views */,
CFD47D8F20FD85EC00BC1E49 /* NetworkConfiguartion.swift */,
CFD47D8F20FD85EC00BC1E49 /* MGLAccountManager.swift */,
3EA93A10227A7DAF1861D9F5 /* Cache.swift */,
160D8278205996DA00D278D6 /* DataCache.swift */,
35726EE71F0856E900AFA1B6 /* DayStyle.swift */,
Expand Down Expand Up @@ -1859,7 +1859,7 @@
35ECAF2D2092275100DC3BC3 /* UIImage.swift in Sources */,
351BEC051E5BCC6C006FE110 /* LaneView.swift in Sources */,
C5A7EC5C1FD610A80008B9BA /* VisualInstructionComponent.swift in Sources */,
CFD47D9020FD85EC00BC1E49 /* NetworkConfiguartion.swift in Sources */,
CFD47D9020FD85EC00BC1E49 /* MGLAccountManager.swift in Sources */,
351BEC0D1E5BCC72006FE110 /* Bundle.swift in Sources */,
8DF399B21FB257B30034904C /* UIGestureRecognizer.swift in Sources */,
35B7837E1F9547B300291F9A /* Transitioning.swift in Sources */,
Expand Down
18 changes: 18 additions & 0 deletions MapboxNavigation/MGLAccountManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Foundation
import Mapbox


extension MGLAccountManager{

static let mapboxChinaBaseAPIURL = "https://api.mapbox.cn"
static let mapboxChinaBaseURLHost = "api.mapbox.cn"
static let mapboxChinaDayStyleURL = "mapbox://styles/mapbox/streets-zh-v1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move the style URLs to the MGLStyle extension?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually u r right. I'll modify that.

static let mapboxChinaNightStyleURL = "mapbox://styles/mapbox/dark-zh-v1"

// Value of whether the map is China map or not
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the /** syntax, so that Quick Help and jazzy can pick this up as a documentation comment.

public class var hasChinaBaseURL : Bool{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is public, let’s make it available to Objective-C code using @objc.

let apiBaseURL = Bundle.main.object(forInfoDictionaryKey:"MGLMapboxAPIBaseURL") as? String
return apiBaseURL == mapboxChinaBaseAPIURL
}

}
12 changes: 7 additions & 5 deletions MapboxNavigation/MGLStyle.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import Foundation
import Mapbox


extension MGLStyle {
// Returns the URL to the current version of the Mapbox Navigation Guidance Day style.
@objc
public class var navigationGuidanceDayStyleURL: URL { get { return URL(string: "mapbox://styles/mapbox/navigation-guidance-day-v2")! } }
public class var navigationGuidanceDayStyleURL: URL { get { return URL(string: (MGLAccountManager.hasChinaBaseURL ? MGLAccountManager.mapboxChinaDayStyleURL : "mapbox://styles/mapbox/navigation-guidance-day-v2"))! } }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with using constants for the China URLs since each gets reused. However, consider turning them into URL-typed static constants within MGLStyle. (There’s no need for string constants if we have constant URLs.)

extension MGLStyle {
    static let streetsChineseURL = URL(string: "mapbox://styles/mapbox/streets-zh-v1")!
}


// Returns the URL to the current version of the Mapbox Navigation Guidance Night style.
@objc
public class var navigationGuidanceNightStyleURL: URL { get { return URL(string: "mapbox://styles/mapbox/navigation-guidance-night-v2")! } }
public class var navigationGuidanceNightStyleURL: URL { get { return URL(string: (MGLAccountManager.hasChinaBaseURL ? MGLAccountManager.mapboxChinaNightStyleURL : "mapbox://styles/mapbox/navigation-guidance-night-v2"))! } }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability, put this code on multiple lines instead of using a ternary operator. (×4)


@objc
// Returns the URL to the given version of the navigation guidance style. Available version are 1, 2, and 3.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a note that the version is ignored when the API base URL is api.mapbox.cn. (×2)

Also, while you’re here, would you mind turning all four of these comments into proper documentation comments using the /** syntax? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

public class func navigationGuidanceDayStyleURL(version: Int) -> URL {
return URL(string: "mapbox://styles/mapbox/navigation-guidance-day-v\(version)")!
return URL(string: (MGLAccountManager.hasChinaBaseURL ? MGLAccountManager.mapboxChinaDayStyleURL :"mapbox://styles/mapbox/navigation-guidance-day-v\(version)"))!
}

@objc

// Returns the URL to the given version of the navigation guidance style. Available version are 2, and 3.
public class func navigationGuidanceNightStyleURL(version: Int) -> URL {
return URL(string: "mapbox://styles/mapbox/navigation-guidance-night-v\(version)")!
return URL(string: (MGLAccountManager.hasChinaBaseURL ? MGLAccountManager.mapboxChinaNightStyleURL :"mapbox://styles/mapbox/navigation-guidance-night-v\(version)"))!
}
}
2 changes: 1 addition & 1 deletion MapboxNavigation/NavigationMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ open class NavigationMapView: MGLMapView, UIGestureRecognizerDelegate {
to call this method on the value of `NavigationViewController.mapView`.
*/
@objc public func localizeLabels() {
guard NetworkConfiguration.sharedConfiguration.hasChinaBaseURL == false else{
guard MGLAccountManager.hasChinaBaseURL == false else{
return
}

Expand Down
23 changes: 0 additions & 23 deletions MapboxNavigation/NetworkConfiguartion.swift

This file was deleted.