Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,38 @@ class LocalizationActivity : AppCompatActivity(), OnMapReadyCallback {
Toast.makeText(this, R.string.change_language_instruction, Toast.LENGTH_LONG).show()
mapView.onCreate(savedInstanceState)
mapView.getMapAsync(this)
}

fabLocalize.setOnClickListener {
mapIsLocalized = if (mapIsLocalized) {
localizationPlugin?.setMapLanguage(MapLocale(MapLocale.FRENCH))
Toast.makeText(this, R.string.map_not_localized, Toast.LENGTH_SHORT).show()
false
} else {
localizationPlugin?.matchMapLanguageWithDeviceDefault()
Toast.makeText(this, R.string.map_localized, Toast.LENGTH_SHORT).show()
true
override fun onMapReady(mapboxMap: MapboxMap) {
mapboxMap.setStyle(Style.MAPBOX_STREETS) { style ->
this.mapboxMap = mapboxMap
localizationPlugin = LocalizationPlugin(mapView, mapboxMap, style).also { localizationPlugin ->
localizationPlugin.matchMapLanguageWithDeviceDefault()
}
}

fabCamera.setOnClickListener {
val locale = nextMapLocale
localizationPlugin?.setMapLanguage(locale)
localizationPlugin?.setCameraToLocaleCountry(locale, 25)
}
fabLocalize.setOnClickListener {
mapIsLocalized = if (mapIsLocalized) {
localizationPlugin?.setMapLanguage(MapLocale(MapLocale.FRENCH))
Toast.makeText(this, R.string.map_not_localized, Toast.LENGTH_SHORT).show()
false
} else {
localizationPlugin?.matchMapLanguageWithDeviceDefault()
Toast.makeText(this, R.string.map_localized, Toast.LENGTH_SHORT).show()
true
}
}

fabStyles.setOnClickListener {
mapboxMap?.setStyle(Style.Builder().fromUri(Utils.nextStyle))
}
}
fabCamera.setOnClickListener {
val locale = nextMapLocale
localizationPlugin?.apply {
setMapLanguage(locale)
setCameraToLocaleCountry(locale, 25)
}
}

override fun onMapReady(mapboxMap: MapboxMap) {
this.mapboxMap = mapboxMap
mapboxMap.setStyle(Style.MAPBOX_STREETS) {
localizationPlugin = LocalizationPlugin(mapView, mapboxMap, it)
localizationPlugin?.matchMapLanguageWithDeviceDefault()
fabStyles.setOnClickListener {
mapboxMap.setStyle(Style.Builder().fromUri(Utils.nextStyle))
}
}
}

Expand Down Expand Up @@ -145,6 +148,14 @@ class LocalizationActivity : AppCompatActivity(), OnMapReadyCallback {
localizationPlugin?.setMapLanguage(MapLocale.KOREAN)
return true
}
R.id.vietnamese -> {
localizationPlugin?.setMapLanguage(MapLocale.VIETNAMESE)
return true
}
R.id.italian -> {
localizationPlugin?.setMapLanguage(MapLocale.ITALIAN)
return true
}
R.id.local -> {
localizationPlugin?.setMapLanguage(MapLocale.LOCAL_NAME)
return true
Expand All @@ -159,7 +170,10 @@ class LocalizationActivity : AppCompatActivity(), OnMapReadyCallback {

companion object {

private val LOCALES = arrayOf(MapLocale.CANADA, MapLocale.GERMANY, MapLocale.CHINA, MapLocale.US, MapLocale.CANADA_FRENCH, MapLocale.JAPAN, MapLocale.KOREA, MapLocale.FRANCE, MapLocale.SPAIN)
private val LOCALES = arrayOf(MapLocale.CANADA, MapLocale.GERMANY, MapLocale.CHINA,
MapLocale.US, MapLocale.CANADA_FRENCH, MapLocale.JAPAN, MapLocale.KOREA,
MapLocale.FRANCE, MapLocale.SPAIN, MapLocale.VIETNAM, MapLocale.ITALY, MapLocale.UK
)

private var index: Int = 0

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/menu/menu_languages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@
android:title="Korean"
app:showAsAction="never"/>

<item
android:id="@+id/vietnamese"
android:title="Vietnamese"
app:showAsAction="never"/>

<item
android:id="@+id/italian"
android:title="Italian"
app:showAsAction="never"/>

<item
android:id="@+id/local"
android:title="Local names"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,19 @@ public final class MapLocale {
*/
public static final String KOREAN = "name_ko";

/**
* Vietnamese (if available)
*/
public static final String VIETNAMESE = "name_vi";

/**
* Italy (if available)
*/
public static final String ITALIAN = "name_it";

@Retention(SOURCE)
@StringDef( {LOCAL_NAME, ARABIC, CHINESE, SIMPLIFIED_CHINESE, TRADITIONAL_CHINESE, ENGLISH,
FRENCH, GERMAN, JAPANESE, KOREAN, PORTUGUESE, RUSSIAN, SPANISH})
FRENCH, GERMAN, JAPANESE, KOREAN, PORTUGUESE, RUSSIAN, SPANISH, VIETNAMESE, ITALIAN})
public @interface Languages {
}

Expand All @@ -117,96 +127,110 @@ public final class MapLocale {
*/

/**
* USA Bounding box excluding Hawaii and Alaska extracted from Open Street Map
* Approximate USA bounding box, excluding Hawaii and Alaska
*/
static final LatLngBounds USA_BBOX = new LatLngBounds.Builder()
.include(new LatLng(49.388611, -124.733253))
.include(new LatLng(24.544245, -66.954811)).build();

/**
* UK Bounding Box extracted from Open Street Map
* Approximate UK bounding box
*/
static final LatLngBounds UK_BBOX = new LatLngBounds.Builder()
.include(new LatLng(59.360249, -8.623555))
.include(new LatLng(49.906193, 1.759)).build();

/**
* Canada Bounding Box extracted from Open Street Map
* Approximate Canada bounding box
*/
static final LatLngBounds CANADA_BBOX = new LatLngBounds.Builder()
.include(new LatLng(83.110626, -141.0))
.include(new LatLng(41.67598, -52.636291)).build();

/**
* China Bounding Box extracted from Open Street Map
* Approximate China bounding box
*/
static final LatLngBounds CHINA_BBOX = new LatLngBounds.Builder()
.include(new LatLng(53.56086, 73.557693))
.include(new LatLng(15.775416, 134.773911)).build();

/**
* Taiwan Bounding Box extracted from Open Street Map
* Approximate Taiwan bounding box
*/
static final LatLngBounds TAIWAN_BBOX = new LatLngBounds.Builder()
.include(new LatLng(26.389444, 118.115255566105))
.include(new LatLng(21.733333, 122.107778)).build();

/**
* Germany Bounding Box extracted from Open Street Map
* Approximate Germany bounding box
*/
static final LatLngBounds GERMANY_BBOX = new LatLngBounds.Builder()
.include(new LatLng(55.055637, 5.865639))
.include(new LatLng(47.275776, 15.039889)).build();

/**
* Korea Bounding Box extracted from Open Street Map
* Approximate Korea bounding box
*/
static final LatLngBounds KOREA_BBOX = new LatLngBounds.Builder()
.include(new LatLng(38.612446, 125.887108))
.include(new LatLng(33.190945, 129.584671)).build();

/**
* Japan Bounding Box extracted from Open Street Map
* Approximate Japan bounding box
*/
static final LatLngBounds JAPAN_BBOX = new LatLngBounds.Builder()
.include(new LatLng(45.52314, 122.93853))
.include(new LatLng(24.249472, 145.820892)).build();

/**
* France Bounding Box extracted from Open Street Map
* Approximate France bounding box
*/
static final LatLngBounds FRANCE_BBOX = new LatLngBounds.Builder()
.include(new LatLng(51.092804, -5.142222))
.include(new LatLng(41.371582, 9.561556)).build();

/**
* Russian Bounding box extracted from Open Street Map
* Approximate Russian bounding box
*/
static final LatLngBounds RUSSIA_BBOX = new LatLngBounds.Builder()
.include(new LatLng(81.856903, -168.997849))
.include(new LatLng(41.185902, 19.638861)).build();

/**
* Spain Bounding box extracted from Open Street Map
* Approximate Spain bounding box
*/
static final LatLngBounds SPAIN_BBOX = new LatLngBounds.Builder()
.include(new LatLng(27.4335426, -18.3936845))
.include(new LatLng(43.9933088, 4.5918885)).build();

/**
* Portugal Bounding box extracted from Open Street Map
* Approximate Portugal bounding box
*/
static final LatLngBounds PORTUGAL_BBOX = new LatLngBounds.Builder()
.include(new LatLng(27.4335426, -18.3936845))
.include(new LatLng(42.280468655, -6.3890876937)).build();

/**
* Brazil Bounding box extracted from Open Street Map
* Approximate Brazil bounding box
*/
static final LatLngBounds BRAZIL_BBOX = new LatLngBounds.Builder()
.include(new LatLng(5.2842873, -33.8689056))
.include(new LatLng(-28.6341164, -73.9830625)).build();

/**
* Approximate Vietnam bounding box
*/
static final LatLngBounds VIETNAM_BBOX = new LatLngBounds.Builder()
.include(new LatLng(8.383333, 102.216667))
.include(new LatLng(23.666667, 109.466667)).build();
Copy link
Contributor

Choose a reason for hiding this comment

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

This is only part of the bounding box for Vietnam in OpenStreetMap, which includes some disputed territories.

If I understand correctly, these bounding boxes are used to center the map over the country most closely associated with a particular language by default. Even though the documented use case for these bounding boxes would be quite benign, getCountryBounds() is a public method that an application could use in other ways. The precision of these bounding boxes could raise questions about the inconsistent handling of disputed territories, of which there are now at least two examples.

Going forward, it may be prudent to replace these bounding boxes with zoom levels and simple point features roughly centered over each country’s mainland, or at least to align them to the bounding boxes returned by the Mapbox Geocoding API or the geometries in Mapbox Boundaries.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point @1ec5, but in my opinion, this shouldn't be a huge issue since we're providing rough bounding boxes, not precise polygons. Additionally, using a point and a zoom level is pixel density-dependent and wouldn't be easy to hardcode as a constant.

How about we add the "Approximate" keyword to the Javadoc to not set the wrong expectations?

Copy link
Contributor

@1ec5 1ec5 Feb 24, 2020

Choose a reason for hiding this comment

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

I’d agree except that the Vietnam bounding box is about half as wide as it would be if it included the disputed South China Sea Islands, while the China boundary extends well to the south to include them. The comments currently cite OpenStreetMap, but the bounding boxes don’t match OpenStreetMap either.

If there’s a technical constraint preventing us from using the same bounding boxes as the Mapbox Geocoding API or Mapbox Boundaries, then I think the comments should warn developers to convert the bounding boxes to points before use and shouldn’t mention OSM.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback, you two. I'll touch up this pr once 8.3 is actually out.


/**
* Approximate Italy bounding box
*/
static final LatLngBounds ITALY_BBOX = new LatLngBounds.Builder()
.include(new LatLng(36.619987291,6.7499552751))
.include(new LatLng(47.1153931748,18.4802470232)).build();

/*
* Some MapLocales already defined (these match with the predefined ones in the Locale class)
*/
Expand Down Expand Up @@ -291,6 +315,16 @@ public final class MapLocale {
*/
public static final MapLocale BRAZIL = new MapLocale(PORTUGUESE, BRAZIL_BBOX);

/**
* Useful constant for country.
*/
public static final MapLocale VIETNAM = new MapLocale(VIETNAMESE, VIETNAM_BBOX);

/**
* Useful constant for country.
*/
public static final MapLocale ITALY = new MapLocale(ITALIAN, ITALY_BBOX);

/**
* Maps out the Matching pair of {@link Locale} and {@link MapLocale}. In other words, if I have a
* {@link Locale#CANADA}, this should be matched up with {@link MapLocale#CANADA}.
Expand All @@ -313,6 +347,8 @@ public final class MapLocale {
LOCALE_SET.put(new Locale("es", "ES"), SPAIN);
LOCALE_SET.put(new Locale("pt", "PT"), PORTUGAL);
LOCALE_SET.put(new Locale("pt", "BR"), BRAZIL);
LOCALE_SET.put(new Locale("vi", "VN"), VIETNAM);
LOCALE_SET.put(Locale.ITALY, MapLocale.ITALY);

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
Locale zh_CN_Hans = new Locale.Builder().setLanguage("zh").setRegion("CN").setScript("Hans").build();
Expand Down