Mapbox: Set custom day and night style

  android, mapbox, theme-daynight

I’m writing a navigation app for iOS and Android. One of the requirements is to be able to use alternate vector data (licensing issues with clients). In the iOS version, I am able to set custom day and night style URIs (the styles contain the source entries for the alternate mapping data as well as the the actual styling, thereof) in a single call and the built-in day/night switching logic just "does the right thing". Here’s the basic iOS swift code:

let navigationService = MapboxNavigationService(route: route, simulating: simulate ? .always : .never)
let navigationOptions: NavigationOptions?

if !(dayStyle ?? "").isEmpty || !(nightStyle ?? "").isEmpty {
    var dayUrl = dayStyle ?? ""
    var nightUrl = nightStyle ?? ""
    if(dayUrl.isEmpty) { dayUrl = nightUrl }
    if(nightUrl.isEmpty) { nightUrl = dayUrl }
    let ds = CustomDayStyle()
    ds.setUrl(url: dayUrl)
    let ns = CustomNightStyle()
    ns.setUrl(url: nightUrl)
    //****************************
    // in the next line, the styles accepts an array of style instances.  The style instances
    // each have a "styleType" parameter that gets set to either .day or .night
    //****************************
    navigationOptions = NavigationOptions(styles: [ds, ns], navigationService: navigationService)
} else {
    navigationOptions = NavigationOptions(navigationService: navigationService)
}
let navigationViewController = NavigationViewController(for: route, options: navigationOptions)

In the MapBox Android SDK, however, I only see a "SetStyle" on the map object.

private void setMapStyles() {
    String dayMapStyle = permitState.getDayStyleUrl();
    String nightMapStyle = permitState.getNightStyleUrl();
    if(dayMapStyle.length() > 0 || nightMapStyle.length() > 0) {
        NavigationMapboxMap navMap = navigationView.retrieveNavigationMapboxMap();
        MapboxMap map = navMap.retrieveMap();
        //****************************
        // would like to set both styles into the map, here
        //****************************
        map.setStyle(new Style.Builder().fromUri(dayMapStyle));
    }
}

Is there a way to set both styles at once? If not, is there an event/override I can catch to set the correct style manually?

Source: Android Questions

LEAVE A COMMENT