Replace OSMDroid with Mapbox#7245
Conversation
| } | ||
|
|
||
| private static class SourceOption { | ||
| public static class SourceOption { |
There was a problem hiding this comment.
I think longer term, we really don't want MapConfiguratorProvider to be statically accessed, but that's a rabbit hole for another time.
| object MapFragmentReferenceLayerUtils { | ||
|
|
||
| @JvmStatic | ||
| fun getReferenceLayerFile( |
There was a problem hiding this comment.
This is only used in tests. We can remove it.
| basemap == BASEMAP_SOURCE_USGS || | ||
| basemap == BASEMAP_SOURCE_CARTO | ||
| private fun isMapbox(source: String?): Boolean { | ||
| return when (source) { |
There was a problem hiding this comment.
This could be simplified to:
when (source) {
ProjectKeys.BASEMAP_SOURCE_MAPBOX,
ProjectKeys.BASEMAP_SOURCE_OSM,
ProjectKeys.BASEMAP_SOURCE_USGS,
ProjectKeys.BASEMAP_SOURCE_CARTO -> true
else -> false
}
| val basemapSource = settings.getString(KEY_BASEMAP_SOURCE) | ||
| return if (isMapbox(basemapSource)) { | ||
| MapboxClassInstanceCreator.createMapboxMapFragment( | ||
| basemapSource ?: ProjectKeys.BASEMAP_SOURCE_MAPBOX |
There was a problem hiding this comment.
basemapSource can't be null here - isMapbox(null) returns false, so the ?: BASEMAP_SOURCE_MAPBOX fallback is unreachable.
| } | ||
| implementation project(':external-app') | ||
| implementation project(':maps') | ||
| implementation project(':osmdroid') |
There was a problem hiding this comment.
You can remove osmdroid from libs.versions.toml.
Osmdroid is still mentioned in a couple of places, like: STATE.md, MapFragment (in the comment) etc.
|
There is a crash when I try to change maps in settings: It happened on a device without Google Play Services, this case seems to be handled when we open a map (there is an error message), but in settings, it crashes the app. |
| val uri = if (configuration.uri != null) { | ||
| configuration.uri | ||
| } else if (configuration.styleSetting != null) { | ||
| configuration.styleOptions.getValue(settings.getString(configuration.styleSetting)!!) |
There was a problem hiding this comment.
getValue() returns a StyleOption, not a BasemapUri, so neither when branch matches and the style is never loaded.
| val styleOptions: Map<String, StyleOption> = emptyMap() | ||
| ) | ||
|
|
||
| class StyleOption(val name: Int, uri: BasemapUri) |
| import java.io.File | ||
| import kotlin.collections.toIntArray | ||
|
|
||
| class MapboxMapConfigurator(private val configuration: Configuration) : MapConfigurator { |
There was a problem hiding this comment.
There are a few unused imports here.
|
|
||
| override fun getDisplayName(file: File): String { | ||
| val name = MbtilesFile.readName(file) | ||
| return if (name != null) name else file.getName() |
There was a problem hiding this comment.
This could be just: return name ?: file.name
| @@ -0,0 +1,11 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
| <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
There was a problem hiding this comment.
Do we need this wrapper layout?
| // This has to happen on the main thread but we might call `initialize` from tests | ||
| MapView(context).onCreate(null) | ||
| } | ||
| OsmDroidInitializer.initialize(userAgentProvider.userAgent) |
There was a problem hiding this comment.
You can remove userAgentProvider from the constructor.
| styleOptions = mapOf( | ||
| "positron" to StyleOption( | ||
| name = R.string.carto_map_style_positron, | ||
| BasemapUri.Raster("http://1.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png") |
There was a problem hiding this comment.
Doesn't it work with https?
There was a problem hiding this comment.
I'm guessing they're HTTP because they were added 15+ years ago! Let's use the currently-recommended ones with https: https://github.com/cartodb/basemap-styles#1-web-raster-basemaps
| ), | ||
| "dark_matter" to StyleOption( | ||
| name = R.string.carto_map_style_dark_matter, | ||
| BasemapUri.Raster("http://1.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png") |
There was a problem hiding this comment.
Doesn't it work with https?
| getMapViewModel().getSettings(mapConfigurator.prefKeys).observe(viewLifecycleOwner) { | ||
| val newConfig = mapConfigurator.buildConfig(it) | ||
| onConfigChanged(newConfig) | ||
| getMapViewModel().getSettings(setOf(KEY_MAPBOX_MAP_STYLE)).observe(viewLifecycleOwner) { |
There was a problem hiding this comment.
CollectionUtils from com.google.android.gms.common.util is GMS-internal (@KeepForSdk), so it can change or disappear in any Play Services release. Collections.singleton() would be safer here.
Closes #7092
Why is this the best possible solution? Were any other approaches considered?
The one big (potentially unexpected) change here is to simplify the
MapConfiguratorinterface so thatMapFragmentimplementations don't have to deal with them at all. This abstraction mostly worked, but the implementations are by definition implementation specific, so I'd argue it was only confusing to try and abstract details for settings away from them.How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
This is a pretty massive change: all the OSM maps (OSM, USGS and Carto) are now implemented using Mapbox, and so we'll need to verify that they behave as before. It's hard to put a boundary around how the "tile set" changes here can affect behaviour. I've manually verified that reference layers work as expected, but I have limited experience in that area so it'd be good to double-check.
Before submitting this PR, please make sure you have:
./gradlew connectedAndroidTest(or./gradlew testLab) and confirmed all checks still passDateFormatsTest