[android] #4166 - move style url to map view for improved async loading
This commit is contained in:
@@ -9,6 +9,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.utils.ApiAccess;
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,6 +55,7 @@ import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ZoomButtonsController;
|
||||
|
||||
import com.almeros.android.multitouch.gesturedetectors.RotateGestureDetector;
|
||||
import com.almeros.android.multitouch.gesturedetectors.ShoveGestureDetector;
|
||||
import com.almeros.android.multitouch.gesturedetectors.TwoFingerGestureDetector;
|
||||
@@ -71,6 +72,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
|
||||
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.exceptions.IconBitmapChangedException;
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidAccessTokenException;
|
||||
import com.mapbox.mapboxsdk.exceptions.TelemetryServiceNotConfiguredException;
|
||||
@@ -82,6 +84,7 @@ import com.mapbox.mapboxsdk.maps.widgets.UserLocationView;
|
||||
import com.mapbox.mapboxsdk.telemetry.MapboxEvent;
|
||||
import com.mapbox.mapboxsdk.telemetry.MapboxEventManager;
|
||||
import com.mapbox.mapboxsdk.utils.ApiAccess;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -145,6 +148,10 @@ public class MapView extends FrameLayout {
|
||||
private int mContentPaddingRight;
|
||||
private int mContentPaddingBottom;
|
||||
|
||||
private OnMapReadyCallback mMapReadyCallback;
|
||||
private String mStyleUrl;
|
||||
private boolean mInitialLoad;
|
||||
|
||||
@UiThread
|
||||
public MapView(@NonNull Context context) {
|
||||
super(context);
|
||||
@@ -164,6 +171,7 @@ public class MapView extends FrameLayout {
|
||||
}
|
||||
|
||||
private void initialize(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
mInitialLoad = true;
|
||||
mOnMapChangedListener = new CopyOnWriteArrayList<>();
|
||||
mMapboxMap = new MapboxMap(this);
|
||||
mIcons = new ArrayList<>();
|
||||
@@ -307,6 +315,9 @@ public class MapView extends FrameLayout {
|
||||
*/
|
||||
@UiThread
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
// Force a check for an access token
|
||||
validateAccessToken(getAccessToken());
|
||||
|
||||
if (savedInstanceState != null && savedInstanceState.getBoolean(MapboxConstants.STATE_HAS_SAVED_STATE)) {
|
||||
|
||||
// Get previous camera position
|
||||
@@ -370,16 +381,10 @@ public class MapView extends FrameLayout {
|
||||
// Force a check for Telemetry
|
||||
validateTelemetryServiceConfigured();
|
||||
|
||||
// Force a check for an access token
|
||||
validateAccessToken(getAccessToken());
|
||||
|
||||
// Start Telemetry (authorization determined in initial MapboxEventManager constructor)
|
||||
MapboxEventManager.configureAndStartMapboxEventManager(getContext(), getAccessToken());
|
||||
}
|
||||
|
||||
// Force a check for an access token
|
||||
validateAccessToken(getAccessToken());
|
||||
|
||||
// Initialize EGL
|
||||
mNativeMapView.initializeDisplay();
|
||||
mNativeMapView.initializeContext();
|
||||
@@ -392,6 +397,12 @@ public class MapView extends FrameLayout {
|
||||
reloadIcons();
|
||||
reloadMarkers();
|
||||
adjustTopOffsetPixels();
|
||||
if (mInitialLoad) {
|
||||
mInitialLoad = false;
|
||||
if (mMapReadyCallback != null) {
|
||||
mMapReadyCallback.onMapReady(mMapboxMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -417,7 +428,7 @@ public class MapView extends FrameLayout {
|
||||
outState.putBoolean(MapboxConstants.STATE_HAS_SAVED_STATE, true);
|
||||
outState.putParcelable(MapboxConstants.STATE_CAMERA_POSITION, mMapboxMap.getCameraPosition());
|
||||
outState.putBoolean(MapboxConstants.STATE_DEBUG_ACTIVE, mMapboxMap.isDebugActive());
|
||||
outState.putString(MapboxConstants.STATE_STYLE_URL, mMapboxMap.getStyleUrl());
|
||||
outState.putString(MapboxConstants.STATE_STYLE_URL, mStyleUrl);
|
||||
outState.putString(MapboxConstants.STATE_ACCESS_TOKEN, mMapboxMap.getAccessToken());
|
||||
outState.putLong(MapboxConstants.STATE_DEFAULT_TRANSITION_DURATION, mNativeMapView.getDefaultTransitionDuration());
|
||||
outState.putBoolean(MapboxConstants.STATE_MY_LOCATION_ENABLED, mMapboxMap.isMyLocationEnabled());
|
||||
@@ -514,6 +525,11 @@ public class MapView extends FrameLayout {
|
||||
mNativeMapView.resume();
|
||||
mNativeMapView.update();
|
||||
mUserLocationView.resume();
|
||||
|
||||
if (mStyleUrl == null) {
|
||||
// user has failed to supply a style url
|
||||
setStyleUrl(Style.MAPBOX_STREETS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -676,10 +692,72 @@ public class MapView extends FrameLayout {
|
||||
// Styling
|
||||
//
|
||||
|
||||
void setStyleUrl(@NonNull String url) {
|
||||
/**
|
||||
* <p>
|
||||
* Loads a new map style from the specified URL.
|
||||
* </p>
|
||||
* {@code url} can take the following forms:
|
||||
* <ul>
|
||||
* <li>{@code Style.*}: load one of the bundled styles in {@link Style}.</li>
|
||||
* <li>{@code mapbox://styles/<user>/<style>}:
|
||||
* retrieves the style from a <a href="https://www.mapbox.com/account/">Mapbox account.</a>
|
||||
* {@code user} is your username. {@code style} is the ID of your custom
|
||||
* style created in <a href="https://www.mapbox.com/studio">Mapbox Studio</a>.</li>
|
||||
* <li>{@code http://...} or {@code https://...}:
|
||||
* retrieves the style over the Internet from any web server.</li>
|
||||
* <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#MAPBOX_STREETS} style.</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* This method is asynchronous and will return immediately before the style finishes loading.
|
||||
* If you wish to wait for the map to finish loading listen for the {@link MapView#DID_FINISH_LOADING_MAP} event.
|
||||
* </p>
|
||||
* If the style fails to load or an invalid style URL is set, the map view will become blank.
|
||||
* An error message will be logged in the Android logcat and {@link MapView#DID_FAIL_LOADING_MAP} event will be sent.
|
||||
*
|
||||
* @param url The URL of the map style
|
||||
* @see Style
|
||||
*/
|
||||
public void setStyleUrl(@NonNull String url) {
|
||||
mStyleUrl = url;
|
||||
mNativeMapView.setStyleUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Loads a new map style from the specified bundled style.
|
||||
* </p>
|
||||
* <p>
|
||||
* This method is asynchronous and will return immediately before the style finishes loading.
|
||||
* If you wish to wait for the map to finish loading listen for the {@link MapView#DID_FINISH_LOADING_MAP} event.
|
||||
* </p>
|
||||
* If the style fails to load or an invalid style URL is set, the map view will become blank.
|
||||
* An error message will be logged in the Android logcat and {@link MapView#DID_FAIL_LOADING_MAP} event will be sent.
|
||||
*
|
||||
* @param style The bundled style. Accepts one of the values from {@link Style}.
|
||||
* @see Style
|
||||
*/
|
||||
@UiThread
|
||||
public void setStyle(@Style.StyleUrl String style) {
|
||||
setStyleUrl(style);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Returns the map style currently displayed in the map view.
|
||||
* </p>
|
||||
* If the default style is currently displayed, a URL will be returned instead of null.
|
||||
*
|
||||
* @return The URL of the map style.
|
||||
*/
|
||||
@UiThread
|
||||
@NonNull
|
||||
public String getStyleUrl() {
|
||||
return mStyleUrl;
|
||||
}
|
||||
|
||||
//
|
||||
// Access token
|
||||
//
|
||||
@@ -855,9 +933,6 @@ public class MapView extends FrameLayout {
|
||||
}
|
||||
|
||||
long addMarker(@NonNull Marker marker) {
|
||||
if (mNativeMapView == null) {
|
||||
return 0l;
|
||||
}
|
||||
return mNativeMapView.addMarker(marker);
|
||||
}
|
||||
|
||||
@@ -1204,6 +1279,7 @@ public class MapView extends FrameLayout {
|
||||
/**
|
||||
* Helper method for tracking DragEnd gesture event
|
||||
* See {@see MapboxEvent#TYPE_MAP_DRAGEND}
|
||||
*
|
||||
* @param xCoordinate Original x screen coordinate at end of drag
|
||||
* @param yCoordinate Orginal y screen coordinate at end of drag
|
||||
*/
|
||||
@@ -2231,14 +2307,10 @@ public class MapView extends FrameLayout {
|
||||
*/
|
||||
@UiThread
|
||||
public void getMapAsync(@NonNull final OnMapReadyCallback callback) {
|
||||
|
||||
// We need to put our callback on the message queue
|
||||
post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
callback.onMapReady(mMapboxMap);
|
||||
}
|
||||
});
|
||||
if (mMapReadyCallback == null && !mInitialLoad) {
|
||||
callback.onMapReady(mMapboxMap);
|
||||
}
|
||||
mMapReadyCallback = callback;
|
||||
}
|
||||
|
||||
MapboxMap getMapboxMap() {
|
||||
|
||||
@@ -420,7 +420,6 @@ public class MapboxMap {
|
||||
*/
|
||||
@UiThread
|
||||
public void setStyleUrl(@NonNull String url) {
|
||||
mStyleUrl = url;
|
||||
mMapView.setStyleUrl(url);
|
||||
}
|
||||
|
||||
@@ -454,7 +453,7 @@ public class MapboxMap {
|
||||
@UiThread
|
||||
@NonNull
|
||||
public String getStyleUrl() {
|
||||
return mStyleUrl;
|
||||
return mMapView.getStyleUrl();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.utils.ApiAccess;
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,7 +47,6 @@ public class CameraActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
|
||||
// set a style
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
mapboxMap.setOnCameraChangeListener(new MapboxMap.OnCameraChangeListener() {
|
||||
@Override
|
||||
public void onCameraChange(CameraPosition position) {
|
||||
|
||||
@@ -46,7 +46,6 @@ public class CoordinateChangeActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
mMapboxMap = mapboxMap;
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(getNextLatLng(), 16));
|
||||
|
||||
UiSettings uiSettings = mapboxMap.getUiSettings();
|
||||
|
||||
@@ -65,12 +65,11 @@ public class DoubleMapActivity extends AppCompatActivity {
|
||||
|
||||
// MapView large
|
||||
mMapView = (MapView) view.findViewById(R.id.mapView);
|
||||
mMapView.setStyleUrl(Style.DARK);
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
mMapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
mapboxMap.setStyle(Style.DARK);
|
||||
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(18));
|
||||
try {
|
||||
TrackingSettings settings = mapboxMap.getTrackingSettings();
|
||||
@@ -84,11 +83,11 @@ public class DoubleMapActivity extends AppCompatActivity {
|
||||
|
||||
// MapView mini
|
||||
mMapViewMini = (MapView) view.findViewById(R.id.mini_map);
|
||||
mMapViewMini.setStyle(Style.LIGHT);
|
||||
mMapViewMini.onCreate(savedInstanceState);
|
||||
mMapViewMini.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
mapboxMap.setStyle(Style.LIGHT);
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(4));
|
||||
|
||||
UiSettings uiSettings = mapboxMap.getUiSettings();
|
||||
|
||||
@@ -55,7 +55,6 @@ public class DynamicMarkerChangeActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
mMapboxMap = mapboxMap;
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.506675, -0.128699), 10));
|
||||
|
||||
// Create marker
|
||||
|
||||
@@ -55,14 +55,12 @@ public class GeocoderActivity extends AppCompatActivity {
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.setAccessToken(ApiAccess.getToken(this));
|
||||
mapView.setStyle(Style.EMERALD);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
|
||||
|
||||
// Style
|
||||
mapboxMap.setStyle(Style.EMERALD);
|
||||
|
||||
// Camera position
|
||||
mapboxMap.setCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
|
||||
@@ -49,11 +49,14 @@ public class InfoWindowActivity extends AppCompatActivity {
|
||||
.snippet("H St NW with 15th St NW")
|
||||
.position(new LatLng(38.9002073, -77.03364419)));
|
||||
|
||||
mapboxMap.addMarker(new MarkerOptions()
|
||||
Marker marker = mapboxMap.addMarker(new MarkerOptions()
|
||||
.title("White House")
|
||||
.snippet("The official residence and principal workplace of the President of the United States, located at 1600 Pennsylvania Avenue NW in Washington, D.C. It has been the residence of every U.S. president since John Adams in 1800.")
|
||||
.position(new LatLng(38.897705003219784, -77.03655168667463)));
|
||||
|
||||
// open InfoWindow at startup!
|
||||
mapboxMap.selectMarker(marker);
|
||||
|
||||
mapboxMap.addMarker(new MarkerOptions().title("Intersection")
|
||||
.snippet("E St NW with 17th St NW")
|
||||
.position(new LatLng(38.8954236, -77.0394623)));
|
||||
@@ -61,7 +64,7 @@ public class InfoWindowActivity extends AppCompatActivity {
|
||||
mapboxMap.setOnInfoWindowCloseListener(new MapboxMap.OnInfoWindowCloseListener() {
|
||||
@Override
|
||||
public void onInfoWindowClose(Marker marker) {
|
||||
Toast.makeText(getApplicationContext(),"OnClose: "+marker.getTitle(),Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(getApplicationContext(), "OnClose: " + marker.getTitle(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -97,7 +100,7 @@ public class InfoWindowActivity extends AppCompatActivity {
|
||||
mapboxMap.setOnInfoWindowLongClickListener(new MapboxMap.OnInfoWindowLongClickListener() {
|
||||
@Override
|
||||
public void onInfoWindowLongClick(Marker marker) {
|
||||
Toast.makeText(getApplicationContext(),"OnLongClick: "+marker.getTitle(),Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(getApplicationContext(), "OnLongClick: " + marker.getTitle(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ public class LatLngBoundsActivity extends AppCompatActivity {
|
||||
|
||||
mMapView = (MapView) findViewById(R.id.mapView);
|
||||
mMapView.setAccessToken(ApiAccess.getToken(this));
|
||||
mMapView.setStyle(Style.DARK);
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
mMapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
|
||||
@@ -136,6 +136,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
mMapView = (MapView) findViewById(R.id.mainMapView);
|
||||
mMapView.setAccessToken(ApiAccess.getToken(this));
|
||||
changeMapStyle(mSelectedStyle);
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
mMapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
@@ -229,7 +230,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
changeMapStyle(mSelectedStyle);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -496,32 +496,32 @@ public class MainActivity extends AppCompatActivity {
|
||||
private boolean changeMapStyle(int id) {
|
||||
switch (id) {
|
||||
case R.id.actionStyleMapboxStreets:
|
||||
mMapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
mMapView.setStyleUrl(Style.MAPBOX_STREETS);
|
||||
mSelectedStyle = id;
|
||||
return true;
|
||||
|
||||
case R.id.actionStyleEmerald:
|
||||
mMapboxMap.setStyle(Style.EMERALD);
|
||||
mMapView.setStyleUrl(Style.EMERALD);
|
||||
mSelectedStyle = id;
|
||||
return true;
|
||||
|
||||
case R.id.actionStyleLight:
|
||||
mMapboxMap.setStyle(Style.LIGHT);
|
||||
mMapView.setStyleUrl(Style.LIGHT);
|
||||
mSelectedStyle = id;
|
||||
return true;
|
||||
|
||||
case R.id.actionStyleDark:
|
||||
mMapboxMap.setStyle(Style.DARK);
|
||||
mMapView.setStyleUrl(Style.DARK);
|
||||
mSelectedStyle = id;
|
||||
return true;
|
||||
|
||||
case R.id.actionStyleSatellite:
|
||||
mMapboxMap.setStyle(Style.SATELLITE);
|
||||
mMapView.setStyleUrl(Style.SATELLITE);
|
||||
mSelectedStyle = id;
|
||||
return true;
|
||||
|
||||
case R.id.actionStyleSatelliteStreets:
|
||||
mMapboxMap.setStyle(Style.SATELLITE_STREETS);
|
||||
mMapView.setStyleUrl(Style.SATELLITE_STREETS);
|
||||
mSelectedStyle = id;
|
||||
return true;
|
||||
|
||||
|
||||
@@ -39,12 +39,12 @@ public class ManualZoomActivity extends AppCompatActivity {
|
||||
|
||||
mMapView = (MapView) findViewById(R.id.manualZoomMapView);
|
||||
mMapView.setAccessToken(ApiAccess.getToken(this));
|
||||
mMapView.setStyleUrl(Style.SATELLITE_STREETS);
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
mMapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
|
||||
mMapboxMap = mapboxMap;
|
||||
mMapboxMap.setStyle(Style.SATELLITE_STREETS);
|
||||
|
||||
UiSettings uiSettings = mMapboxMap.getUiSettings();
|
||||
uiSettings.setAllGesturesEnabled(false);
|
||||
|
||||
@@ -49,8 +49,6 @@ public class MapFragmentActivity extends AppCompatActivity {
|
||||
new CameraPosition.Builder()
|
||||
.target(new LatLng(48.861431, 2.334166))
|
||||
.zoom(10)
|
||||
.bearing(0)
|
||||
.tilt(0)
|
||||
.build()));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -43,18 +43,18 @@ public class MapPaddingActivity extends AppCompatActivity {
|
||||
mMapView.setTag(true);
|
||||
mMapView.setAccessToken(ApiAccess.getToken(this));
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
|
||||
mMapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
mMapboxMap = mapboxMap;
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
|
||||
moveToBangalore();
|
||||
|
||||
int paddingLeft = (int) getResources().getDimension(R.dimen.map_padding_left);
|
||||
int paddingBottom = (int) getResources().getDimension(R.dimen.map_padding_bottom);
|
||||
int paddingRight = (int) getResources().getDimension(R.dimen.map_padding_right);
|
||||
mapboxMap.setPadding(paddingLeft, toolbar.getHeight(), paddingRight, paddingBottom);
|
||||
|
||||
moveToBangalore();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -123,14 +123,16 @@ public class MapPaddingActivity extends AppCompatActivity {
|
||||
|
||||
private void moveToBangalore() {
|
||||
toggleGps(false);
|
||||
|
||||
LatLng bangalore = new LatLng(12.9810816, 77.6368034);
|
||||
mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
.zoom(16)
|
||||
.target(bangalore)
|
||||
.bearing(40)
|
||||
.tilt(45)
|
||||
.build()));
|
||||
CameraPosition cameraPosition = new CameraPosition.Builder()
|
||||
.zoom(16)
|
||||
.target(bangalore)
|
||||
.bearing(40)
|
||||
.tilt(45)
|
||||
.build();
|
||||
|
||||
mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
|
||||
mMapboxMap.addMarker(new MarkerOptions().title("Center map").position(bangalore));
|
||||
}
|
||||
|
||||
|
||||
@@ -37,24 +37,22 @@ public class MapboxMapActivity extends AppCompatActivity {
|
||||
|
||||
mMapView = (MapView) findViewById(R.id.mapView);
|
||||
mMapView.setAccessToken(ApiAccess.getToken(this));
|
||||
mMapView.setStyle(Style.SATELLITE_STREETS);
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
|
||||
mMapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
mapboxMap.setStyle(Style.SATELLITE_STREETS);
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
.target(new LatLng(43.876550, -103.454791))
|
||||
.zoom(14)
|
||||
.bearing(0)
|
||||
.tilt(0)
|
||||
.build()));
|
||||
}
|
||||
});
|
||||
|
||||
Snackbar.make(findViewById(android.R.id.content),
|
||||
"Demo MapboxMap API.",
|
||||
"Demo MapboxMap API",
|
||||
Snackbar.LENGTH_INDEFINITE).show();
|
||||
}
|
||||
|
||||
|
||||
@@ -39,12 +39,12 @@ public class MaxMinZoomActivity extends AppCompatActivity {
|
||||
|
||||
mMapView = (MapView) findViewById(R.id.manualZoomMapView);
|
||||
mMapView.setAccessToken(ApiAccess.getToken(this));
|
||||
mMapView.setStyle(Style.SATELLITE_STREETS);
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
mMapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
|
||||
mMapboxMap = mapboxMap;
|
||||
mMapboxMap.setStyle(Style.SATELLITE_STREETS);
|
||||
|
||||
UiSettings uiSettings = mapboxMap.getUiSettings();
|
||||
uiSettings.setMinZoom(3);
|
||||
|
||||
@@ -73,6 +73,7 @@ public class OfflineActivity extends AppCompatActivity
|
||||
// Set up map
|
||||
mMapView = (MapView) findViewById(R.id.mapView);
|
||||
mMapView.setAccessToken(ApiAccess.getToken(this));
|
||||
mMapView.setStyle(Style.MAPBOX_STREETS);
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
mMapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
@@ -80,9 +81,6 @@ public class OfflineActivity extends AppCompatActivity
|
||||
Log.d(LOG_TAG, "Map is ready");
|
||||
mMapboxMap = mapboxMap;
|
||||
|
||||
// Set style
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
|
||||
// Set initial position to UNHQ in NYC
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
|
||||
@@ -47,6 +47,7 @@ public class PressForMarkerActivity extends AppCompatActivity implements MapboxM
|
||||
// Adding MapView programmatically
|
||||
mMapView = new MapView(this);
|
||||
mMapView.setAccessToken(ApiAccess.getToken(this));
|
||||
mMapView.setStyle(Style.EMERALD);
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
((ViewGroup) findViewById(R.id.activity_container)).addView(mMapView);
|
||||
|
||||
@@ -61,15 +62,10 @@ public class PressForMarkerActivity extends AppCompatActivity implements MapboxM
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
mMapboxMap = mapboxMap;
|
||||
|
||||
// select style
|
||||
mapboxMap.setStyle(Style.EMERALD);
|
||||
|
||||
// set camera
|
||||
mapboxMap.setCameraPosition(new CameraPosition.Builder()
|
||||
.target(new LatLng(45.1855569, 5.7215506))
|
||||
.zoom(11)
|
||||
.bearing(0)
|
||||
.tilt(0)
|
||||
.build());
|
||||
|
||||
// add markers
|
||||
|
||||
@@ -53,12 +53,11 @@ public class ScrollByActivity extends AppCompatActivity {
|
||||
mMapView = (MapView) findViewById(R.id.mapView);
|
||||
mMapView.setTag(true);
|
||||
mMapView.setAccessToken(ApiAccess.getToken(this));
|
||||
mMapView.setStyleUrl(Style.MAPBOX_STREETS);
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
mMapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
|
||||
UiSettings uiSettings = mapboxMap.getUiSettings();
|
||||
uiSettings.setLogoEnabled(false);
|
||||
uiSettings.setAttributionEnabled(false);
|
||||
|
||||
@@ -43,14 +43,11 @@ public class TiltActivity extends AppCompatActivity {
|
||||
mMapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
|
||||
// Move camera to Washington DC
|
||||
CameraPosition normalCameraPosition = new CameraPosition.Builder()
|
||||
.target(WASHINGTON_DC)
|
||||
.zoom(11)
|
||||
.bearing(0)
|
||||
.tilt(0)
|
||||
.build();
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(normalCameraPosition));
|
||||
|
||||
@@ -58,7 +55,6 @@ public class TiltActivity extends AppCompatActivity {
|
||||
CameraPosition tiltedCameraPosition = new CameraPosition.Builder()
|
||||
.target(WASHINGTON_DC)
|
||||
.zoom(11)
|
||||
.bearing(0)
|
||||
.tilt(45.0f)
|
||||
.build();
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(tiltedCameraPosition), 10000);
|
||||
|
||||
@@ -231,22 +231,6 @@ public class MapboxMapTest {
|
||||
mMapboxMap.setOnMyLocationTrackingModeChangeListener(mMyLocationTrackingModeChangeListener);
|
||||
assertEquals("MyLocationTrackigChangeListener should match",mMyLocationTrackingModeChangeListener, mMapboxMap.getOnMyLocationTrackingModeChangeListener());
|
||||
}
|
||||
|
||||
//
|
||||
// Style
|
||||
//
|
||||
|
||||
@Test
|
||||
public void testStyleUrl() {
|
||||
mMapboxMap.setStyleUrl("somestyle");
|
||||
assertEquals("StyleUrl should be same", "somestyle", mMapboxMap.getStyleUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyle() {
|
||||
mMapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
assertEquals("Style should be same", Style.MAPBOX_STREETS, mMapboxMap.getStyleUrl());
|
||||
}
|
||||
|
||||
//
|
||||
// CameraPosition
|
||||
|
||||
Reference in New Issue
Block a user