Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] Fix style urls
Browse files Browse the repository at this point in the history
Fixes #5193
  • Loading branch information
Cameron committed Jun 3, 2016
1 parent c9c6ea7 commit 0bfe951
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 188 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.mapbox.mapboxsdk.constants;

import android.support.annotation.StringDef;

import com.mapbox.mapboxsdk.maps.MapView;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

Expand All @@ -15,156 +17,32 @@
*/
public class Style {

/**
* Mapbox Streets: A complete basemap, perfect for incorporating your own data.
*/
private static final String MAPBOX_STREETS_BASE = "mapbox://styles/mapbox/streets-v%d";
/**
* Outdoors: A general-purpose style tailored to outdoor activities.
*/
private static final String OUTDOORS_BASE = "mapbox://styles/mapbox/outdoors-v%d";
/**
* Light: Subtle light backdrop for data visualizations.
*/
private static final String LIGHT_BASE = "mapbox://styles/mapbox/light-v%d";
/**
* Dark: Subtle dark backdrop for data visualizations.
*/
private static final String DARK_BASE = "mapbox://styles/mapbox/dark-v%d";
/**
* Satellite: A beautiful global satellite and aerial imagery layer.
*/
private static final String SATELLITE_BASE = "mapbox://styles/mapbox/satellite-v%d";
/**
* Satellite Streets: Global satellite and aerial imagery with unobtrusive labels.
*/
private static final String SATELLITE_STREETS_BASE = "mapbox://styles/mapbox/satellite-streets-v%d";

/**
* Satellite Streets: Global satellite and aerial imagery with unobtrusive labels (Version 8).
*/
private static final String SATELLITE_STREETS_V8 = "mapbox://styles/mapbox/satellite-hybrid-v8";

/**
* Get versioned url of Mapbox streets style.
* <ul>
* <li>Current default version is 9.</li>
* </ul>
* <p>
* More information on the Mapbox styles API can be found on https://www.mapbox.com/api-documentation/#styles
* </p>
*
* @param version the version of the style.
* @return uri to load style from
*/
public static String getMapboxStreetsUrl(int version) {
return String.format(MapboxConstants.MAPBOX_LOCALE, MAPBOX_STREETS_BASE, version);
}

/**
* Get versioned url of Outdoors streets style.
* <ul>
* <li>Current version is 9.</li>
* </ul>
* <p>
* More information on the Mapbox styles API can be found on https://www.mapbox.com/api-documentation/#styles
* </p>
*
* @param version the version of the style.
* @return uri to load style from
*/
public static String getOutdoorsStyleUrl(int version) {
return String.format(MapboxConstants.MAPBOX_LOCALE, OUTDOORS_BASE, version);
}

/**
* Get versioned url of Light style.
* <ul>
* <li>Current default version is 9.</li>
* </ul>
* <p>
* More information on the Mapbox styles API can be found on https://www.mapbox.com/api-documentation/#styles
* </p>
*
* @param version the version of the style.
* @return uri to load style from
*/
public static String getLightStyleUrl(int version) {
return String.format(MapboxConstants.MAPBOX_LOCALE, LIGHT_BASE, version);
}

/**
* Get versioned url of Dark style.
* <ul>
* <li>Current default version is 9.</li>
* </ul>
* <p>
* More information on the Mapbox styles API can be found on https://www.mapbox.com/api-documentation/#styles
* </p>
*
* @param version the version of the style.
* @return uri to load style from
*/
public static String getDarkStyleUrl(int version) {
return String.format(MapboxConstants.MAPBOX_LOCALE, DARK_BASE, version);
}

/**
* Get versioned url of Satellite style.
* <ul>
* <li>Current version is 9.</li>
* </ul>
* <p>
* More information on the Mapbox styles API can be found on https://www.mapbox.com/api-documentation/#styles
* </p>
*
* @param version the version of the style.
* @return uri to load style from
*/
public static String getSatelliteStyleUrl(int version) {
return String.format(MapboxConstants.MAPBOX_LOCALE, SATELLITE_BASE, version);
}

/**
* Get versioned url of Satellite streets style.
* <ul>
* <li>Current version is 9.</li>
* </ul>
* <p>
* More information on the Mapbox styles API can be found on https://www.mapbox.com/api-documentation/#styles
* </p>
*
* @param version the version of the style.
* @return uri to load style from
* Indicates the parameter accepts one of the values from {@link Style}. Using one of these
* constants means your map style will always use the latest version and may change as we
* improve the style
*/
public static String getSatelliteStreetsStyleUrl(int version) {
if (version == 8) {
return SATELLITE_STREETS_V8;
}
return String.format(MapboxConstants.MAPBOX_LOCALE, SATELLITE_STREETS_BASE, version);
}

/**
* Indicates the parameter accepts one of the values from {@link Style}.
*
* @deprecated use dedicated versioned methods in {@link Style} instead.
*/
@StringDef({MAPBOX_STREETS, EMERALD, LIGHT, DARK, SATELLITE, SATELLITE_STREETS})
@StringDef({MAPBOX_STREETS, OUTDOORS, EMERALD, LIGHT, DARK, SATELLITE, SATELLITE_STREETS})
@Retention(RetentionPolicy.SOURCE)
@Deprecated
public @interface StyleUrl {
}

// IMPORTANT: If you change any of these you also need to edit them in strings.xml

/**
* Mapbox Streets: A complete basemap, perfect for incorporating your own data.
*
* @deprecated use {@link #getMapboxStreetsUrl(int)} instead.
* Mapbox Streets: A complete basemap, perfect for incorporating your own data. Using this
* constant means your map style will always use the latest version and may change as we
* improve the style.
*/
@Deprecated
public static final String MAPBOX_STREETS = "mapbox://styles/mapbox/streets-v9";

/**
* Outdoors: A general-purpose style tailored to outdoor activities. Using this constant means
* your map style will always use the latest version and may change as we improve the style.
*/
public static final String OUTDOORS = "mapbox://styles/mapbox/outdoors-v9";

/**
* Emerald: A versatile style, with emphasis on road networks and public transit.
*
Expand All @@ -174,34 +52,27 @@ public static String getSatelliteStreetsStyleUrl(int version) {
public static final String EMERALD = "mapbox://styles/mapbox/emerald-v8";

/**
* Light: Subtle light backdrop for data visualizations.
*
* @deprecated use {@link #getLightStyleUrl(int)} instead.
* Light: Subtle light backdrop for data visualizations. Using this constant means your map
* style will always use the latest version and may change as we improve the style.
*/
@Deprecated
public static final String LIGHT = "mapbox://styles/mapbox/light-v9";

/**
* Dark: Subtle dark backdrop for data visualizations.
*
* @deprecated use {@link #getDarkStyleUrl(int)} (int)} instead.
* Dark: Subtle dark backdrop for data visualizations. Using this constant means your map style
* will always use the latest version and may change as we improve the style.
*/
@Deprecated
public static final String DARK = "mapbox://styles/mapbox/dark-v9";

/**
* Satellite: A beautiful global satellite and aerial imagery layer.
*
* @deprecated use {@link #getSatelliteStyleUrl(int)} instead.
* Satellite: A beautiful global satellite and aerial imagery layer. Using this constant means
* your map style will always use the latest version and may change as we improve the style.
*/
@Deprecated
public static final String SATELLITE = "mapbox://styles/mapbox/satellite-v9";

/**
* Satellite Streets: Global satellite and aerial imagery with unobtrusive labels.
*
* @deprecated use {@link #getSatelliteStreetsStyleUrl(int)} (int)} instead.
* Satellite Streets: Global satellite and aerial imagery with unobtrusive labels. Using this
* constant means your map style will always use the latest version and may change as we
* improve the style.
*/
@Deprecated
public static final String SATELLITE_STREETS = "mapbox://styles/mapbox/satellite-streets-v9";
}
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ void cycleDebugOptions() {
* <li>{@code asset://...}:
* reads the style from the APK {@code assets/} directory.
* This is used to load a style bundled with your app.</li>
* <li>{@code null}: loads the default {@link Style#getMapboxStreetsUrl(int)} style.</li>
* <li>{@code null}: loads the default {@link Style#MAPBOX_STREETS} style.</li>
* </ul>
* <p>
* This method is asynchronous and will return immediately before the style finishes loading.
Expand Down Expand Up @@ -2708,7 +2708,7 @@ static class StyleInitializer {
private boolean mDefaultStyle;

StyleInitializer(@NonNull Context context) {
mStyle = Style.getMapboxStreetsUrl(context.getResources().getInteger(R.integer.style_version));
mStyle = Style.MAPBOX_STREETS;
mDefaultStyle = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public void cycleDebugOptions() {
* <li>{@code asset://...}:
* reads the style from the APK {@code assets/} directory.
* This is used to load a style bundled with your app.</li>
* <li>{@code null}: loads the default {@link Style#getMapboxStreetsUrl(int)} style.</li>
* <li>{@code null}: loads the default {@link Style#MAPBOX_STREETS} style.</li>
* </ul>
* <p>
* This method is asynchronous and will return immediately before the style finishes loading.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
<string name="infoWindowAddress">Address</string>

<!-- these are public -->
<!-- {@deprecated Use Style.getXStyleUrl(int version) instead.} -->
<!-- Using one of these constants means your map style will always use the latest version and
may change as we improve the style. -->
<string name="style_mapbox_streets">mapbox://styles/mapbox/streets-v9</string>
<string name="style_outdoors">mapbox://styles/mapbox/outdoors-v9</string>
<!-- Note: Emerald style has been deprecated and will be removed in a future release-->
<string name="style_emerald">mapbox://styles/mapbox/emerald-v8</string>
<string name="style_light">mapbox://styles/mapbox/light-v9</string>
<string name="style_dark">mapbox://styles/mapbox/dark-v9</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {
MapboxMapOptions options = new MapboxMapOptions()
.attributionTintColor(Color.RED)
.accessToken(getString(R.string.mapbox_access_token))
.styleUrl(Style.getMapboxStreetsUrl(AppConstant.STYLE_VERSION))
.styleUrl(Style.MAPBOX_STREETS)
.camera(new CameraPosition.Builder()
.target(new LatLng(45.520486, -122.673541))
.zoom(12)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
Expand All @@ -17,6 +18,7 @@
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.R;

import java.text.DecimalFormat;
import java.util.ArrayList;

Expand Down Expand Up @@ -50,7 +52,7 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {
@Override
public void onMapReady(final MapboxMap map) {
mapboxMap = map;
mapboxMap.setStyleUrl(Style.getOutdoorsStyleUrl(9));
mapboxMap.setStyleUrl(Style.OUTDOORS);
resetMap();

mapboxMap.setOnMapLongClickListener(new MapboxMap.OnMapLongClickListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@
import android.view.MenuItem;

import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;

public class LatLngBoundsActivity extends AppCompatActivity {

Expand All @@ -43,7 +42,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setStyleUrl(Style.getDarkStyleUrl(AppConstant.STYLE_VERSION));
mMapView.setStyleUrl(Style.DARK);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@

import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;

public class ManualZoomActivity extends AppCompatActivity {

Expand All @@ -39,7 +38,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

mMapView = (MapView) findViewById(R.id.manualZoomMapView);
mMapView.setStyleUrl(Style.getSatelliteStyleUrl(AppConstant.STYLE_VERSION));
mMapView.setStyleUrl(Style.SATELLITE);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;

public class MapFragmentActivity extends AppCompatActivity {

Expand All @@ -40,7 +39,7 @@ protected void onCreate(Bundle savedInstanceState) {
FragmentTransaction transaction = getFragmentManager().beginTransaction();

MapboxMapOptions options = new MapboxMapOptions();
options.styleUrl(Style.getOutdoorsStyleUrl(AppConstant.STYLE_VERSION));
options.styleUrl(Style.OUTDOORS);

options.scrollGesturesEnabled(false);
options.zoomGesturesEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.SupportMapFragment;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;

public class SupportMapFragmentActivity extends AppCompatActivity {

Expand All @@ -40,7 +39,7 @@ protected void onCreate(Bundle savedInstanceState) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

MapboxMapOptions options = new MapboxMapOptions();
options.styleUrl(Style.getSatelliteStreetsStyleUrl(AppConstant.STYLE_VERSION));
options.styleUrl(Style.SATELLITE_STREETS);

options.scrollGesturesEnabled(false);
options.zoomGesturesEnabled(false);
Expand Down
Loading

0 comments on commit 0bfe951

Please sign in to comment.