-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Replace OSMDroid with Mapbox #7245
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
base: master
Are you sure you want to change the base?
Changes from all commits
1aa55cb
e18fe42
fccb958
b2e4882
af9ed2e
056696b
b1b37e3
d8996a9
0b3c703
7d6605f
741e2b7
ba6dd33
28e1498
b408252
5fce5e4
c9e1640
1e9988a
b50be62
f5c47c6
9062d7a
3e57fef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ import android.content.Context | |
| import android.os.Handler | ||
| import com.google.android.gms.maps.MapView | ||
| import org.odk.collect.android.geo.MapConfiguratorProvider | ||
| import org.odk.collect.osmdroid.OsmDroidInitializer | ||
| import org.odk.collect.settings.SettingsProvider | ||
| import org.odk.collect.settings.keys.ProjectKeys | ||
| import org.odk.collect.utilities.UserAgentProvider | ||
|
|
@@ -30,7 +29,7 @@ class MapsInitializer @Inject constructor( | |
| val availableBaseMaps = MapConfiguratorProvider.getIds() | ||
| val baseMapSetting = | ||
| settingsProvider.getUnprotectedSettings().getString(ProjectKeys.KEY_BASEMAP_SOURCE) | ||
| if (!availableBaseMaps.contains(baseMapSetting)) { | ||
| if (!availableBaseMaps.contains(baseMapSetting) && availableBaseMaps.isNotEmpty()) { | ||
| settingsProvider.getUnprotectedSettings().save( | ||
| ProjectKeys.KEY_BASEMAP_SOURCE, | ||
| availableBaseMaps[0] | ||
|
|
@@ -54,7 +53,6 @@ class MapsInitializer @Inject constructor( | |
| // This has to happen on the main thread but we might call `initialize` from tests | ||
| MapView(context).onCreate(null) | ||
| } | ||
| OsmDroidInitializer.initialize(userAgentProvider.userAgent) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove |
||
| } catch (ignore: Exception) { | ||
| // ignored | ||
| } catch (ignore: Error) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,38 +6,23 @@ | |
| import static org.odk.collect.settings.keys.ProjectKeys.BASEMAP_SOURCE_OSM; | ||
| import static org.odk.collect.settings.keys.ProjectKeys.BASEMAP_SOURCE_USGS; | ||
| import static org.odk.collect.settings.keys.ProjectKeys.KEY_BASEMAP_SOURCE; | ||
| import static org.odk.collect.settings.keys.ProjectKeys.KEY_CARTO_MAP_STYLE; | ||
| import static org.odk.collect.settings.keys.ProjectKeys.KEY_GOOGLE_MAP_STYLE; | ||
| import static org.odk.collect.settings.keys.ProjectKeys.KEY_USGS_MAP_STYLE; | ||
| import static org.odk.collect.strings.localization.LocalizedApplicationKt.getLocalizedString; | ||
|
|
||
| import android.content.Context; | ||
|
|
||
| import androidx.annotation.NonNull; | ||
|
|
||
| import com.google.android.gms.maps.GoogleMap; | ||
|
|
||
| import org.odk.collect.android.application.Collect; | ||
| import org.odk.collect.android.application.MapboxClassInstanceCreator; | ||
| import org.odk.collect.googlemaps.GoogleMapConfigurator; | ||
| import org.odk.collect.googlemaps.GoogleMapConfigurator.GoogleMapTypeOption; | ||
| import org.odk.collect.android.injection.DaggerUtils; | ||
| import org.odk.collect.googlemaps.GoogleMapConfigurator; | ||
| import org.odk.collect.maps.MapConfigurator; | ||
| import org.odk.collect.osmdroid.OsmDroidMapConfigurator; | ||
| import org.odk.collect.osmdroid.OsmDroidMapConfigurator.WmsOption; | ||
| import org.odk.collect.osmdroid.WebMapService; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class MapConfiguratorProvider { | ||
|
|
||
| private static SourceOption[] sourceOptions; | ||
| private static final String USGS_URL_BASE = | ||
| "https://basemap.nationalmap.gov/arcgis/rest/services"; | ||
| private static final String OSM_COPYRIGHT = "© OpenStreetMap contributors"; | ||
| private static final String CARTO_COPYRIGHT = "© CARTO"; | ||
| private static final String CARTO_ATTRIBUTION = OSM_COPYRIGHT + ", " + CARTO_COPYRIGHT; | ||
| private static final String USGS_ATTRIBUTION = "Map services and data available from U.S. Geological Survey,\nNational Geospatial Program."; | ||
|
|
||
| private MapConfiguratorProvider() { | ||
|
|
||
|
|
@@ -55,14 +40,7 @@ public static void initOptions(Context context) { | |
|
|
||
| ArrayList<SourceOption> sourceOptions = new ArrayList<>(); | ||
|
|
||
| GoogleMapConfigurator googleMapsConfigurator = new GoogleMapConfigurator( | ||
| KEY_GOOGLE_MAP_STYLE, org.odk.collect.strings.R.string.basemap_source_google, | ||
| new GoogleMapTypeOption(GoogleMap.MAP_TYPE_NORMAL, org.odk.collect.strings.R.string.streets), | ||
| new GoogleMapTypeOption(GoogleMap.MAP_TYPE_TERRAIN, org.odk.collect.strings.R.string.terrain), | ||
| new GoogleMapTypeOption(GoogleMap.MAP_TYPE_HYBRID, org.odk.collect.strings.R.string.hybrid), | ||
| new GoogleMapTypeOption(GoogleMap.MAP_TYPE_SATELLITE, org.odk.collect.strings.R.string.satellite) | ||
| ); | ||
|
|
||
| GoogleMapConfigurator googleMapsConfigurator = new GoogleMapConfigurator(); | ||
| if (googleMapsConfigurator.isAvailable(context)) { | ||
| sourceOptions.add(new SourceOption(BASEMAP_SOURCE_GOOGLE, org.odk.collect.strings.R.string.basemap_source_google, | ||
| googleMapsConfigurator | ||
|
|
@@ -71,49 +49,24 @@ public static void initOptions(Context context) { | |
|
|
||
| if (isMapboxSupported()) { | ||
| sourceOptions.add(new SourceOption(BASEMAP_SOURCE_MAPBOX, org.odk.collect.strings.R.string.basemap_source_mapbox, | ||
| MapboxClassInstanceCreator.createMapboxMapConfigurator() | ||
| MapboxClassInstanceCreator.createMapboxMapConfigurator(BASEMAP_SOURCE_MAPBOX) | ||
| )); | ||
|
|
||
| sourceOptions.add(new SourceOption(BASEMAP_SOURCE_OSM, org.odk.collect.strings.R.string.basemap_source_osm, | ||
| MapboxClassInstanceCreator.createMapboxMapConfigurator(BASEMAP_SOURCE_OSM) | ||
| )); | ||
| sourceOptions.add(new SourceOption(BASEMAP_SOURCE_USGS, org.odk.collect.strings.R.string.basemap_source_usgs, | ||
| MapboxClassInstanceCreator.createMapboxMapConfigurator(BASEMAP_SOURCE_USGS) | ||
| )); | ||
| sourceOptions.add(new SourceOption(BASEMAP_SOURCE_CARTO, org.odk.collect.strings.R.string.basemap_source_carto, | ||
| MapboxClassInstanceCreator.createMapboxMapConfigurator(BASEMAP_SOURCE_CARTO) | ||
| )); | ||
| } | ||
|
|
||
| sourceOptions.add(new SourceOption(BASEMAP_SOURCE_OSM, org.odk.collect.strings.R.string.basemap_source_osm, | ||
| new OsmDroidMapConfigurator( | ||
| new WebMapService( | ||
| "Mapnik", 0, 19, 256, OSM_COPYRIGHT, | ||
| "https://tile.openstreetmap.org/{z}/{x}/{y}.png" | ||
| ) | ||
| ) | ||
| )); | ||
| sourceOptions.add(new SourceOption(BASEMAP_SOURCE_USGS, org.odk.collect.strings.R.string.basemap_source_usgs, | ||
| new OsmDroidMapConfigurator( | ||
| KEY_USGS_MAP_STYLE, org.odk.collect.strings.R.string.basemap_source_usgs, | ||
| new WmsOption("topographic", org.odk.collect.strings.R.string.topographic, new WebMapService( | ||
| getLocalizedString(getApplication(), org.odk.collect.strings.R.string.openmap_usgs_topo), 0, 18, 256, USGS_ATTRIBUTION, | ||
| USGS_URL_BASE + "/USGSTopo/MapServer/tile/{z}/{y}/{x}" | ||
| )), | ||
| new WmsOption("hybrid", org.odk.collect.strings.R.string.hybrid, new WebMapService( | ||
| getLocalizedString(getApplication(), org.odk.collect.strings.R.string.openmap_usgs_sat), 0, 18, 256, USGS_ATTRIBUTION, | ||
| USGS_URL_BASE + "/USGSImageryTopo/MapServer/tile/{z}/{y}/{x}" | ||
| )), | ||
| new WmsOption("satellite", org.odk.collect.strings.R.string.satellite, new WebMapService( | ||
| getLocalizedString(getApplication(), org.odk.collect.strings.R.string.openmap_usgs_img), 0, 18, 256, USGS_ATTRIBUTION, | ||
| USGS_URL_BASE + "/USGSImageryOnly/MapServer/tile/{z}/{y}/{x}" | ||
| )) | ||
| ) | ||
| )); | ||
| sourceOptions.add(new SourceOption(BASEMAP_SOURCE_CARTO, org.odk.collect.strings.R.string.basemap_source_carto, | ||
| new OsmDroidMapConfigurator( | ||
| KEY_CARTO_MAP_STYLE, org.odk.collect.strings.R.string.basemap_source_carto, | ||
| new WmsOption("positron", org.odk.collect.strings.R.string.carto_map_style_positron, new WebMapService( | ||
| getLocalizedString(getApplication(), org.odk.collect.strings.R.string.openmap_cartodb_positron), 0, 18, 256, CARTO_ATTRIBUTION, | ||
| "http://1.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png" | ||
| )), | ||
| new WmsOption("dark_matter", org.odk.collect.strings.R.string.carto_map_style_dark_matter, new WebMapService( | ||
| getLocalizedString(getApplication(), org.odk.collect.strings.R.string.openmap_cartodb_darkmatter), 0, 18, 256, CARTO_ATTRIBUTION, | ||
| "http://1.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png" | ||
| )) | ||
| ) | ||
| )); | ||
| initOptions(sourceOptions); | ||
| } | ||
|
|
||
| public static void initOptions(List<SourceOption> sourceOptions) { | ||
| MapConfiguratorProvider.sourceOptions = sourceOptions.toArray(new SourceOption[]{}); | ||
| } | ||
|
|
||
|
|
@@ -174,12 +127,12 @@ private static Collect getApplication() { | |
| return Collect.getInstance(); | ||
| } | ||
|
|
||
| private static class SourceOption { | ||
| public static class SourceOption { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think longer term, we really don't want |
||
| private final String id; // preference value to store | ||
| private final int labelId; // string resource ID | ||
| private final MapConfigurator cftor; | ||
|
|
||
| private SourceOption(String id, int labelId, MapConfigurator cftor) { | ||
| public SourceOption(String id, int labelId, MapConfigurator cftor) { | ||
| this.id = id; | ||
| this.labelId = labelId; | ||
| this.cftor = cftor; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,29 +4,31 @@ import org.odk.collect.android.application.MapboxClassInstanceCreator | |
| import org.odk.collect.googlemaps.GoogleMapFragment | ||
| import org.odk.collect.maps.MapFragment | ||
| import org.odk.collect.maps.MapFragmentFactory | ||
| import org.odk.collect.osmdroid.OsmDroidMapFragment | ||
| import org.odk.collect.settings.SettingsProvider | ||
| import org.odk.collect.settings.keys.ProjectKeys.BASEMAP_SOURCE_CARTO | ||
| import org.odk.collect.settings.keys.ProjectKeys.BASEMAP_SOURCE_MAPBOX | ||
| import org.odk.collect.settings.keys.ProjectKeys.BASEMAP_SOURCE_OSM | ||
| import org.odk.collect.settings.keys.ProjectKeys.BASEMAP_SOURCE_USGS | ||
| import org.odk.collect.settings.keys.ProjectKeys | ||
| import org.odk.collect.settings.keys.ProjectKeys.KEY_BASEMAP_SOURCE | ||
|
|
||
| class MapFragmentFactoryImpl(private val settingsProvider: SettingsProvider) : MapFragmentFactory { | ||
|
|
||
| override fun createMapFragment(): MapFragment { | ||
| val settings = settingsProvider.getUnprotectedSettings() | ||
|
|
||
| return when { | ||
| isBasemapOSM(settings.getString(KEY_BASEMAP_SOURCE)) -> OsmDroidMapFragment() | ||
| settings.getString(KEY_BASEMAP_SOURCE) == BASEMAP_SOURCE_MAPBOX -> MapboxClassInstanceCreator.createMapboxMapFragment() | ||
| else -> GoogleMapFragment() | ||
| val basemapSource = settings.getString(KEY_BASEMAP_SOURCE) | ||
| return if (isMapbox(basemapSource)) { | ||
| MapboxClassInstanceCreator.createMapboxMapFragment( | ||
| basemapSource ?: ProjectKeys.BASEMAP_SOURCE_MAPBOX | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ) | ||
| } else { | ||
| GoogleMapFragment() | ||
| } | ||
| } | ||
|
|
||
| private fun isBasemapOSM(basemap: String?): Boolean { | ||
| return basemap == BASEMAP_SOURCE_OSM || | ||
| basemap == BASEMAP_SOURCE_USGS || | ||
| basemap == BASEMAP_SOURCE_CARTO | ||
| private fun isMapbox(source: String?): Boolean { | ||
| return when (source) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be simplified to: |
||
| ProjectKeys.BASEMAP_SOURCE_MAPBOX -> true | ||
| ProjectKeys.BASEMAP_SOURCE_OSM -> true | ||
| ProjectKeys.BASEMAP_SOURCE_USGS -> true | ||
| ProjectKeys.BASEMAP_SOURCE_CARTO -> true | ||
| else -> false | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.