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
4 changes: 4 additions & 0 deletions MapboxNavigation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +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 */; };
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 @@ -663,6 +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>"; };
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 @@ -915,6 +917,7 @@
356B7D8A1EE166E100FE5B89 /* scripts */,
351BEC201E5BD4DC006FE110 /* Supporting files */,
C51923B51EA55CD4002AF9E1 /* Views */,
CFD47D8F20FD85EC00BC1E49 /* NetworkConfiguartion.swift */,
3EA93A10227A7DAF1861D9F5 /* Cache.swift */,
160D8278205996DA00D278D6 /* DataCache.swift */,
35726EE71F0856E900AFA1B6 /* DayStyle.swift */,
Expand Down Expand Up @@ -1856,6 +1859,7 @@
35ECAF2D2092275100DC3BC3 /* UIImage.swift in Sources */,
351BEC051E5BCC6C006FE110 /* LaneView.swift in Sources */,
C5A7EC5C1FD610A80008B9BA /* VisualInstructionComponent.swift in Sources */,
CFD47D9020FD85EC00BC1E49 /* NetworkConfiguartion.swift in Sources */,
351BEC0D1E5BCC72006FE110 /* Bundle.swift in Sources */,
8DF399B21FB257B30034904C /* UIGestureRecognizer.swift in Sources */,
35B7837E1F9547B300291F9A /* Transitioning.swift in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions MapboxNavigation/NavigationMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,10 @@ 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{
return
}

guard let style = style else {
return
}
Expand Down
23 changes: 23 additions & 0 deletions MapboxNavigation/NetworkConfiguartion.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Foundation

class NetworkConfiguration : NSObject{
Copy link
Contributor

Choose a reason for hiding this comment

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

Per mapbox/mapbox-gl-native#12417, it seems like the hasChinaAPIBaseURL property should go on an extension of MGLAccountManager instead of this singleton.

@objc static let sharedConfiguration = NetworkConfiguration()

// The current API base URL of map
private var apiBaseURL : String?

// The PRC base URL for Mapbox APIs other than the telemetry API.
private let mapboxChinaBaseAPIURL = "https://api.mapbox.cn"

// The base URL host for Mapbox China
public let mapboxChinaBaseURLHost = "api.mapbox.cn"
Copy link
Contributor

Choose a reason for hiding this comment

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

MGLNetworkConfiguration is a private class in the map SDK. Is there a need to make these symbols public in the navigation SDK?

Copy link
Contributor Author

@m-stephen m-stephen Jul 17, 2018

Choose a reason for hiding this comment

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

If it can make public, that is really helpful for only change the map endpoint. But for a further consideration, I wanna to make this module easily change the map endpoint, api-directions endpoint and integrate Chinese TTS service.


// The URL String of China map style.
public let mapboxChinaStyleURL = "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.

This property is currently unused. Let’s leave it out until we need it. Normally it’s the responsibility of the map SDK to handle style URLs anyways.

Copy link
Contributor Author

@m-stephen m-stephen Jul 17, 2018

Choose a reason for hiding this comment

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

This property is used for my next PR. I'll change the codes in `MGLStyle.swift' sth like:

  (NetworkConfiguration.sharedConfiguration.hasChinaBaseURL ? 
  NetworkConfiguration.sharedConfiguration.mapboxChinaStyleURL : 
  "mapbox://styles/mapbox/navigation-guidance-day-v2")

It will be the default style of .cn map for China navigation.


// Value of whether the map is China map or not
public var hasChinaBaseURL : Bool{
apiBaseURL = Bundle.main.object(forInfoDictionaryKey:"MGLMapboxAPIBaseURL") as? String
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to store this base URL upfront? I think it would be more straightforward to execute this code on demand, as part of hasChinaBaseURL. It’s likely that Bundle already caches these info dictionary values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you deep diving into our map SDK, this key have already load in +(void)load function in MGLNetworkConfiguration.m
image
So that's NP we write here. Of course, if our map SDK didn't do this, we should execute this code on demand.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, the value doesn’t change, but my suggestion is to call object(forInfoDictionaryKey:) at the point of use anyways, because it shouldn’t affect performance significantly even if we call it several times in a row.

Copy link
Contributor

Choose a reason for hiding this comment

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

This can be a local variable.

return apiBaseURL == mapboxChinaBaseAPIURL
}
}