[android] - decouple style loading from OnMapReady
This commit is contained in:
@@ -117,6 +117,11 @@ public class MapboxConstants {
|
||||
*/
|
||||
public static final String FRAG_ARG_MAPBOXMAPOPTIONS = "MapboxMapOptions";
|
||||
|
||||
/**
|
||||
* Layer Id of annotations layer
|
||||
*/
|
||||
public static final String LAYER_ID_ANNOTATIONS = "com.mapbox.annotations.points";
|
||||
|
||||
// Save instance state keys
|
||||
public static final String STATE_HAS_SAVED_STATE = "mapbox_savedState";
|
||||
public static final String STATE_CAMERA_POSITION = "mapbox_cameraPosition";
|
||||
@@ -126,7 +131,6 @@ public class MapboxConstants {
|
||||
public static final String STATE_TILT_ENABLED = "mapbox_tiltEnabled";
|
||||
public static final String STATE_DOUBLE_TAP_ENABLED = "mapbox_doubleTapEnabled";
|
||||
public static final String STATE_DEBUG_ACTIVE = "mapbox_debugActive";
|
||||
public static final String STATE_STYLE_URL = "mapbox_styleUrl";
|
||||
public static final String STATE_COMPASS_ENABLED = "mapbox_compassEnabled";
|
||||
public static final String STATE_COMPASS_GRAVITY = "mapbox_compassGravity";
|
||||
public static final String STATE_COMPASS_MARGIN_LEFT = "mapbox_compassMarginLeft";
|
||||
|
||||
@@ -11,7 +11,6 @@ import android.support.annotation.RequiresPermission;
|
||||
import android.support.annotation.StyleRes;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.mapbox.android.core.location.LocationEngine;
|
||||
import com.mapbox.android.core.location.LocationEngineCallback;
|
||||
import com.mapbox.android.core.location.LocationEngineProvider;
|
||||
@@ -123,7 +122,12 @@ public final class LocationComponent {
|
||||
/**
|
||||
* Indicates whether the component has been initialized.
|
||||
*/
|
||||
private boolean isInitialized;
|
||||
private boolean isComponentInitialized;
|
||||
|
||||
/**
|
||||
* Indicates whether the style has been initialized.
|
||||
*/
|
||||
private boolean isStyleInitialized;
|
||||
|
||||
/**
|
||||
* Indicates that the component is enabled and should be displaying location if Mapbox components are available and
|
||||
@@ -182,7 +186,6 @@ public final class LocationComponent {
|
||||
this.staleStateManager = staleStateManager;
|
||||
this.compassEngine = compassEngine;
|
||||
this.internalLocationEngineProvider = internalLocationEngineProvider;
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -835,16 +838,17 @@ public final class LocationComponent {
|
||||
* Internal use.
|
||||
*/
|
||||
public void onFinishLoadingStyle() {
|
||||
if (isInitialized) {
|
||||
isStyleInitialized = true;
|
||||
if (isComponentInitialized) {
|
||||
locationLayerController.initializeComponents(options);
|
||||
locationCameraController.initializeOptions(options);
|
||||
onLocationLayerStart();
|
||||
}
|
||||
onLocationLayerStart();
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private void onLocationLayerStart() {
|
||||
if (!isInitialized || !isComponentStarted) {
|
||||
if (!isComponentInitialized || !isComponentStarted) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -874,7 +878,7 @@ public final class LocationComponent {
|
||||
}
|
||||
|
||||
private void onLocationLayerStop() {
|
||||
if (!isInitialized || !isLayerReady || !isComponentStarted) {
|
||||
if (!isComponentInitialized || !isLayerReady || !isComponentStarted) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -891,10 +895,10 @@ public final class LocationComponent {
|
||||
}
|
||||
|
||||
private void initialize(@NonNull Context context, @NonNull LocationComponentOptions options) {
|
||||
if (isInitialized) {
|
||||
if (isComponentInitialized) {
|
||||
return;
|
||||
}
|
||||
isInitialized = true;
|
||||
isComponentInitialized = true;
|
||||
this.options = options;
|
||||
|
||||
mapboxMap.addOnMapClickListener(onMapClickListener);
|
||||
@@ -924,6 +928,10 @@ public final class LocationComponent {
|
||||
setRenderMode(RenderMode.NORMAL);
|
||||
setCameraMode(CameraMode.NONE);
|
||||
|
||||
if (isStyleInitialized) {
|
||||
onFinishLoadingStyle();
|
||||
}
|
||||
|
||||
onLocationLayerStart();
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,6 @@ final class LocationLayerController implements MapboxAnimator.OnLayerAnimationsV
|
||||
this.layerSourceProvider = layerSourceProvider;
|
||||
this.bitmapProvider = bitmapProvider;
|
||||
this.locationFeature = featureProvider.generateLocationFeature(locationFeature, options);
|
||||
initializeComponents(options);
|
||||
setRenderMode(RenderMode.NORMAL);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapbox.mapboxsdk.MapStrictMode;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
@@ -25,8 +24,8 @@ import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Responsible for managing attribution interactions on the map.
|
||||
@@ -180,10 +179,14 @@ public class AttributionDialogManager implements View.OnClickListener, DialogInt
|
||||
|
||||
List<String> attributions = new ArrayList<>();
|
||||
String attribution;
|
||||
for (Source source : mapboxMap.getStyle().getSources()) {
|
||||
attribution = source.getAttribution();
|
||||
if (!attribution.isEmpty()) {
|
||||
attributions.add(source.getAttribution());
|
||||
|
||||
Style style = mapboxMap.getStyle();
|
||||
if (style != null) {
|
||||
for (Source source : mapboxMap.getStyle().getSources()) {
|
||||
attribution = source.getAttribution();
|
||||
if (!attribution.isEmpty()) {
|
||||
attributions.add(source.getAttribution());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@ import com.mapbox.mapboxsdk.MapStrictMode;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.annotations.Annotation;
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.location.LocationComponent;
|
||||
import com.mapbox.mapboxsdk.maps.renderer.MapRenderer;
|
||||
@@ -34,7 +32,6 @@ import com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.GLSurfaceViewMapRenderer
|
||||
import com.mapbox.mapboxsdk.maps.renderer.textureview.TextureViewMapRenderer;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.CompassView;
|
||||
import com.mapbox.mapboxsdk.net.ConnectivityReceiver;
|
||||
import com.mapbox.mapboxsdk.offline.OfflineRegionDefinition;
|
||||
import com.mapbox.mapboxsdk.storage.FileSource;
|
||||
import com.mapbox.mapboxsdk.utils.BitmapUtils;
|
||||
|
||||
@@ -484,69 +481,6 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <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 to {@link OnDidFinishLoadingStyleListener} callback.
|
||||
* </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 provided to the {@link OnDidFailLoadingMapListener}
|
||||
* callback.
|
||||
*
|
||||
* @param url The URL of the map style
|
||||
* @see Style
|
||||
*/
|
||||
public void setStyleUrl(@NonNull String url) {
|
||||
if (nativeMapView != null) {
|
||||
// null-checking the nativeMapView as it can be mistakenly called after it's been destroyed
|
||||
nativeMapView.setStyleUrl(url);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a new style from the specified offline region definition and moves the map camera to that region.
|
||||
*
|
||||
* @param definition the offline region definition
|
||||
* @see OfflineRegionDefinition
|
||||
*/
|
||||
public void setOfflineRegionDefinition(@NonNull OfflineRegionDefinition definition) {
|
||||
double minZoom = definition.getMinZoom();
|
||||
double maxZoom = definition.getMaxZoom();
|
||||
|
||||
CameraPosition cameraPosition = new CameraPosition.Builder()
|
||||
.target(definition.getBounds().getCenter())
|
||||
.zoom(minZoom)
|
||||
.build();
|
||||
setStyleUrl(definition.getStyleURL());
|
||||
|
||||
if (mapboxMap == null) {
|
||||
mapboxMapOptions.camera(cameraPosition);
|
||||
mapboxMapOptions.minZoomPreference(minZoom);
|
||||
mapboxMapOptions.maxZoomPreference(maxZoom);
|
||||
} else {
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
|
||||
mapboxMap.setMinZoomPreference(minZoom);
|
||||
mapboxMap.setMaxZoomPreference(maxZoom);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Rendering
|
||||
//
|
||||
@@ -971,7 +905,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
*/
|
||||
@UiThread
|
||||
public void getMapAsync(final @NonNull OnMapReadyCallback callback) {
|
||||
if (mapCallback.isInitialLoad() || mapboxMap == null) {
|
||||
if (mapboxMap == null) {
|
||||
// Add callback to the list only if the style hasn't loaded, or the drawing surface isn't ready
|
||||
mapCallback.addOnMapReadyCallback(callback);
|
||||
} else {
|
||||
@@ -1013,34 +947,24 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
* The initial render callback waits for rendering to happen before making the map visible for end-users.
|
||||
* We wait for the second DID_FINISH_RENDERING_FRAME map change event as the first will still show a black surface.
|
||||
*/
|
||||
private class InitialRenderCallback implements OnDidFinishLoadingStyleListener, OnDidFinishRenderingFrameListener {
|
||||
private class InitialRenderCallback implements OnDidFinishRenderingFrameListener {
|
||||
|
||||
private int renderCount;
|
||||
private boolean styleLoaded;
|
||||
|
||||
InitialRenderCallback() {
|
||||
addOnDidFinishLoadingStyleListener(this);
|
||||
addOnDidFinishRenderingFrameListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDidFinishLoadingStyle() {
|
||||
styleLoaded = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDidFinishRenderingFrame(boolean fully) {
|
||||
if (styleLoaded) {
|
||||
renderCount++;
|
||||
if (renderCount == 2) {
|
||||
MapView.this.setForeground(null);
|
||||
removeOnDidFinishRenderingFrameListener(this);
|
||||
}
|
||||
renderCount++;
|
||||
if (renderCount == 2) {
|
||||
MapView.this.setForeground(null);
|
||||
removeOnDidFinishRenderingFrameListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void onDestroy() {
|
||||
removeOnDidFinishLoadingStyleListener(this);
|
||||
removeOnDidFinishRenderingFrameListener(this);
|
||||
}
|
||||
}
|
||||
@@ -1140,7 +1064,6 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
OnCameraIsChangingListener, OnCameraDidChangeListener {
|
||||
|
||||
private final List<OnMapReadyCallback> onMapReadyCallbackList = new ArrayList<>();
|
||||
private boolean initialLoad = true;
|
||||
|
||||
MapCallback() {
|
||||
addOnWillStartLoadingMapListener(this);
|
||||
@@ -1152,11 +1075,9 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
}
|
||||
|
||||
void initialised() {
|
||||
if (!initialLoad) {
|
||||
// Style has loaded before the drawing surface has been initialized, delivering OnMapReady
|
||||
mapboxMap.onPreMapReady();
|
||||
onMapReady();
|
||||
}
|
||||
mapboxMap.onPreMapReady();
|
||||
onMapReady();
|
||||
mapboxMap.onPostMapReady();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1176,10 +1097,6 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
}
|
||||
}
|
||||
|
||||
boolean isInitialLoad() {
|
||||
return initialLoad;
|
||||
}
|
||||
|
||||
void addOnMapReadyCallback(OnMapReadyCallback callback) {
|
||||
onMapReadyCallbackList.add(callback);
|
||||
}
|
||||
@@ -1196,7 +1113,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
|
||||
@Override
|
||||
public void onWillStartLoadingMap() {
|
||||
if (mapboxMap != null && !initialLoad) {
|
||||
if (mapboxMap != null) {
|
||||
mapboxMap.onStartLoadingMap();
|
||||
}
|
||||
}
|
||||
@@ -1204,15 +1121,8 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
@Override
|
||||
public void onDidFinishLoadingStyle() {
|
||||
if (mapboxMap != null) {
|
||||
if (initialLoad) {
|
||||
initialLoad = false;
|
||||
mapboxMap.onPreMapReady();
|
||||
onMapReady();
|
||||
} else {
|
||||
mapboxMap.onFinishLoadingStyle();
|
||||
}
|
||||
mapboxMap.onFinishLoadingStyle();
|
||||
}
|
||||
initialLoad = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,6 @@ import android.support.annotation.Size;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapbox.android.gestures.AndroidGesturesManager;
|
||||
import com.mapbox.android.gestures.MoveGestureDetector;
|
||||
import com.mapbox.android.gestures.RotateGestureDetector;
|
||||
@@ -36,8 +35,10 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.location.LocationComponent;
|
||||
import com.mapbox.mapboxsdk.log.Logger;
|
||||
import com.mapbox.mapboxsdk.offline.OfflineRegionDefinition;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -68,13 +69,15 @@ public final class MapboxMap {
|
||||
@Nullable
|
||||
private MapboxMap.OnFpsChangedListener onFpsChangedListener;
|
||||
|
||||
private List<Style.OnStyleLoaded> styleLoadedCallbacks = new ArrayList<>();
|
||||
|
||||
@Nullable
|
||||
private Style style;
|
||||
|
||||
MapboxMap(NativeMapView map, Transform transform, UiSettings ui, Projection projection,
|
||||
OnGesturesManagerInteractionListener listener, AnnotationManager annotations,
|
||||
CameraChangeDispatcher cameraChangeDispatcher) {
|
||||
this.nativeMapView = map;
|
||||
this.style = new Style(nativeMapView);
|
||||
this.uiSettings = ui;
|
||||
this.projection = projection;
|
||||
this.annotationManager = annotations.bind(this);
|
||||
@@ -95,6 +98,26 @@ public final class MapboxMap {
|
||||
setPrefetchesTiles(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Style of the map asynchronously.
|
||||
*/
|
||||
public void getStyle(@NonNull Style.OnStyleLoaded onStyleLoaded) {
|
||||
if (style == null) {
|
||||
styleLoadedCallbacks.add(onStyleLoaded);
|
||||
} else {
|
||||
onStyleLoaded.onStyleLoaded(style);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Style of the map.
|
||||
* <p>
|
||||
* Returns null when style is being loaded.
|
||||
* </p>
|
||||
*
|
||||
* @return the style of the map
|
||||
*/
|
||||
@Nullable
|
||||
public Style getStyle() {
|
||||
return style;
|
||||
}
|
||||
@@ -122,7 +145,6 @@ public final class MapboxMap {
|
||||
void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
outState.putParcelable(MapboxConstants.STATE_CAMERA_POSITION, transform.getCameraPosition());
|
||||
outState.putBoolean(MapboxConstants.STATE_DEBUG_ACTIVE, nativeMapView.getDebug());
|
||||
outState.putString(MapboxConstants.STATE_STYLE_URL, nativeMapView.getStyleUrl());
|
||||
uiSettings.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@@ -143,11 +165,6 @@ public final class MapboxMap {
|
||||
}
|
||||
|
||||
nativeMapView.setDebug(savedInstanceState.getBoolean(MapboxConstants.STATE_DEBUG_ACTIVE));
|
||||
|
||||
final String styleUrl = savedInstanceState.getString(MapboxConstants.STATE_STYLE_URL);
|
||||
if (!TextUtils.isEmpty(styleUrl)) {
|
||||
nativeMapView.setStyleUrl(savedInstanceState.getString(MapboxConstants.STATE_STYLE_URL));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,6 +183,17 @@ public final class MapboxMap {
|
||||
annotationManager.adjustTopOffsetPixels(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the OnMapReadyCallback has finished executing.
|
||||
* <p>
|
||||
* Invalidation of the camera position is required to update the added components in
|
||||
* OnMapReadyCallback with the correct transformation.
|
||||
* </p>
|
||||
*/
|
||||
void onPostMapReady() {
|
||||
transform.invalidateCameraPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the map will start loading style.
|
||||
*/
|
||||
@@ -178,6 +206,7 @@ public final class MapboxMap {
|
||||
*/
|
||||
void onFinishLoadingStyle() {
|
||||
locationComponent.onFinishLoadingStyle();
|
||||
locationComponent.onStart();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -622,6 +651,40 @@ public final class MapboxMap {
|
||||
return nativeMapView.getWidth();
|
||||
}
|
||||
|
||||
//
|
||||
// Offline
|
||||
//
|
||||
|
||||
/**
|
||||
* Loads a new style from the specified offline region definition and moves the map camera to that region.
|
||||
*
|
||||
* @param definition the offline region definition
|
||||
* @see OfflineRegionDefinition
|
||||
*/
|
||||
public void setOfflineRegionDefinition(@NonNull OfflineRegionDefinition definition) {
|
||||
setOfflineRegionDefinition(definition, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a new style from the specified offline region definition and moves the map camera to that region.
|
||||
*
|
||||
* @param definition the offline region definition
|
||||
* @see OfflineRegionDefinition
|
||||
*/
|
||||
public void setOfflineRegionDefinition(@NonNull OfflineRegionDefinition definition,
|
||||
@Nullable Style.OnStyleLoaded callback) {
|
||||
double minZoom = definition.getMinZoom();
|
||||
double maxZoom = definition.getMaxZoom();
|
||||
CameraPosition cameraPosition = new CameraPosition.Builder()
|
||||
.target(definition.getBounds().getCenter())
|
||||
.zoom(minZoom)
|
||||
.build();
|
||||
moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
|
||||
setMinZoomPreference(minZoom);
|
||||
setMaxZoomPreference(maxZoom);
|
||||
setStyle(new Style.Builder().fromUrl(definition.getStyleURL()), callback);
|
||||
}
|
||||
|
||||
//
|
||||
// Debug
|
||||
//
|
||||
@@ -675,8 +738,31 @@ public final class MapboxMap {
|
||||
// Styling
|
||||
//
|
||||
|
||||
public Style setStyle(Style.Builder builder) {
|
||||
return style = builder.build(nativeMapView);
|
||||
public void setStyle(@Style.StyleUrl String style) {
|
||||
this.setStyle(style, null);
|
||||
}
|
||||
|
||||
public void setStyle(@Style.StyleUrl String style, final Style.OnStyleLoaded callback) {
|
||||
this.setStyle(new Style.Builder().fromUrl(style), callback);
|
||||
}
|
||||
|
||||
public void setStyle(Style.Builder builder) {
|
||||
this.setStyle(builder, null);
|
||||
}
|
||||
|
||||
public void setStyle(Style.Builder builder, final Style.OnStyleLoaded callback) {
|
||||
builder.build(nativeMapView, new Style.OnStyleLoaded() {
|
||||
@Override
|
||||
public void onStyleLoaded(Style style) {
|
||||
MapboxMap.this.style = style;
|
||||
if (callback != null) {
|
||||
callback.onStyleLoaded(style);
|
||||
}
|
||||
for (Style.OnStyleLoaded styleLoadedCallback : styleLoadedCallbacks) {
|
||||
styleLoadedCallback.onStyleLoaded(style);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -687,14 +773,14 @@ public final class MapboxMap {
|
||||
private void setStyleUrl(@NonNull MapboxMapOptions options) {
|
||||
String style = options.getStyleUrl();
|
||||
if (!TextUtils.isEmpty(style)) {
|
||||
setStyle(new Style.Builder().withStyleUrl(style));
|
||||
setStyle(new Style.Builder().fromUrl(style));
|
||||
}
|
||||
}
|
||||
|
||||
private void setStyleJson(@NonNull MapboxMapOptions options) {
|
||||
String styleJson = options.getStyleJson();
|
||||
if (!TextUtils.isEmpty(styleJson)) {
|
||||
setStyle(new Style.Builder().withStyleJson(styleJson));
|
||||
setStyle(new Style.Builder().fromJson(styleJson));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,8 @@ final class NativeMapView {
|
||||
// Flag to indicating destroy was called
|
||||
private boolean destroyed = false;
|
||||
|
||||
private Style style;
|
||||
|
||||
// Holds the pointer to JNI NativeMapView
|
||||
@Keep
|
||||
long nativePtr = 0;
|
||||
@@ -186,9 +188,10 @@ final class NativeMapView {
|
||||
nativeSetStyleUrl(url);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getStyleUrl() {
|
||||
if (checkState("getStyleUrl")) {
|
||||
return null;
|
||||
return "";
|
||||
}
|
||||
return nativeGetStyleUrl();
|
||||
}
|
||||
@@ -200,9 +203,10 @@ final class NativeMapView {
|
||||
nativeSetStyleJson(newStyleJson);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getStyleJson() {
|
||||
if (checkState("getStyleJson")) {
|
||||
return null;
|
||||
return "";
|
||||
}
|
||||
return nativeGetStyleJson();
|
||||
}
|
||||
@@ -933,6 +937,9 @@ final class NativeMapView {
|
||||
@Keep
|
||||
private void onWillStartLoadingMap() {
|
||||
stateCallback.onWillStartLoadingMap();
|
||||
if (style != null) {
|
||||
style.onWillStartLoadingStyle();
|
||||
}
|
||||
}
|
||||
|
||||
@Keep
|
||||
@@ -967,6 +974,7 @@ final class NativeMapView {
|
||||
|
||||
@Keep
|
||||
private void onDidFinishLoadingStyle() {
|
||||
style.onDidFinishLoadingStyle();
|
||||
stateCallback.onDidFinishLoadingStyle();
|
||||
}
|
||||
|
||||
@@ -1331,6 +1339,11 @@ final class NativeMapView {
|
||||
});
|
||||
}
|
||||
|
||||
// TODO remove dependency of Style on NativeMapView
|
||||
public void setStyle(Style style) {
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
//
|
||||
// Image conversion
|
||||
//
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.support.annotation.IntRange;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringDef;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
import com.mapbox.mapboxsdk.style.light.Light;
|
||||
@@ -15,6 +16,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Style {
|
||||
|
||||
@@ -22,35 +24,23 @@ public class Style {
|
||||
private final HashMap<String, Source> sources = new HashMap<>();
|
||||
private final HashMap<String, Layer> layers = new HashMap<>();
|
||||
|
||||
public Style(NativeMapView nativeMapView) {
|
||||
private final OnStyleLoaded onStyleLoaded;
|
||||
private final Builder builder;
|
||||
private boolean styleLoaded;
|
||||
|
||||
public Style(Builder builder, NativeMapView nativeMapView, OnStyleLoaded styleLoaded) {
|
||||
this.builder = builder;
|
||||
this.nativeMapView = nativeMapView;
|
||||
this.onStyleLoaded = styleLoaded;
|
||||
}
|
||||
|
||||
public void loadStyle(@StyleUrl String styleUrl) {
|
||||
for (Source source : sources.values()) {
|
||||
if (source != null) {
|
||||
source.setDetached();
|
||||
nativeMapView.removeSource(source);
|
||||
}
|
||||
}
|
||||
|
||||
for (Layer layer : layers.values()) {
|
||||
if (layer != null) {
|
||||
layer.setDetached();
|
||||
nativeMapView.removeLayer(layer);
|
||||
}
|
||||
}
|
||||
|
||||
nativeMapView.setStyleUrl(styleUrl);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getUrl(){
|
||||
@NonNull
|
||||
public String getUrl() {
|
||||
return nativeMapView.getStyleUrl();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getJson(){
|
||||
@NonNull
|
||||
public String getJson() {
|
||||
return nativeMapView.getStyleJson();
|
||||
}
|
||||
|
||||
@@ -336,6 +326,59 @@ public class Style {
|
||||
return nativeMapView.getLight();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called when the underlying map will start loading a new style. This method will clean up this style
|
||||
* by setting the java sources and layers in a detached state and removing them from core.
|
||||
*/
|
||||
public void onWillStartLoadingStyle() {
|
||||
for (Source source : sources.values()) {
|
||||
if (source != null) {
|
||||
source.setDetached();
|
||||
nativeMapView.removeSource(source);
|
||||
}
|
||||
}
|
||||
|
||||
for (Layer layer : layers.values()) {
|
||||
if (layer != null) {
|
||||
layer.setDetached();
|
||||
nativeMapView.removeLayer(layer);
|
||||
}
|
||||
}
|
||||
|
||||
sources.clear();
|
||||
layers.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the underlying map has finished loading this style.
|
||||
* This method will add all components added to the builder that were defined with the 'with' prefix.
|
||||
*/
|
||||
public void onDidFinishLoadingStyle() {
|
||||
if (!styleLoaded) {
|
||||
styleLoaded = true;
|
||||
for (Source source : builder.sources) {
|
||||
addSource(source);
|
||||
}
|
||||
|
||||
for (Layer layer : builder.layers) {
|
||||
addLayerBelow(layer, MapboxConstants.LAYER_ID_ANNOTATIONS);
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Bitmap> stringBitmapEntry : builder.images.entrySet()) {
|
||||
addImage(stringBitmapEntry.getKey(), stringBitmapEntry.getValue());
|
||||
}
|
||||
|
||||
if (builder.transitionOptions != null) {
|
||||
setTransition(builder.transitionOptions);
|
||||
}
|
||||
|
||||
if (onStyleLoaded != null) {
|
||||
onStyleLoaded.onStyleLoaded(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Builder
|
||||
//
|
||||
@@ -347,9 +390,9 @@ public class Style {
|
||||
private List<Source> sources = new ArrayList<>();
|
||||
// TODO allow adding below and at index
|
||||
private List<Layer> layers = new ArrayList<>();
|
||||
private HashMap<String, Bitmap> images = new HashMap<>();
|
||||
private TransitionOptions transitionOptions;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Loads a new map style asynchronous from the specified URL.
|
||||
@@ -380,8 +423,8 @@ public class Style {
|
||||
* @param url The URL of the map style
|
||||
* @see Style
|
||||
*/
|
||||
public Builder withStyleUrl(@StyleUrl String url) {
|
||||
this.styleUrl = styleUrl;
|
||||
public Builder fromUrl(String url) {
|
||||
this.styleUrl = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -393,7 +436,7 @@ public class Style {
|
||||
* will be triggered.
|
||||
* </p>
|
||||
*/
|
||||
public Builder withStyleJson(String styleJson) {
|
||||
public Builder fromJson(String styleJson) {
|
||||
this.styleJson = styleJson;
|
||||
return this;
|
||||
}
|
||||
@@ -403,6 +446,7 @@ public class Style {
|
||||
return this;
|
||||
}
|
||||
|
||||
// TODO add layer at support!
|
||||
public Builder withLayer(Layer layer) {
|
||||
layers.add(layer);
|
||||
return this;
|
||||
@@ -413,24 +457,40 @@ public class Style {
|
||||
return this;
|
||||
}
|
||||
|
||||
Style build(NativeMapView nativeMapView) {
|
||||
Style style = new Style(nativeMapView);
|
||||
for (Source source : sources) {
|
||||
style.addSource(source);
|
||||
// TODO add SDF support!
|
||||
public Builder withImage(String name, Bitmap image) {
|
||||
images.put(name, image);
|
||||
return this;
|
||||
}
|
||||
|
||||
Style build(NativeMapView nativeMapView, OnStyleLoaded styleLoaded) {
|
||||
Style style = new Style(this, nativeMapView, styleLoaded);
|
||||
nativeMapView.setStyle(style);
|
||||
|
||||
if (styleUrl != null) {
|
||||
nativeMapView.setStyleUrl(styleUrl);
|
||||
} else if (styleJson != null) {
|
||||
nativeMapView.setStyleJson(styleJson);
|
||||
} else {
|
||||
// user didn't provide a `from` component,
|
||||
// flag the style as loaded,
|
||||
// add components defined added using the `with` prefix.
|
||||
style.onDidFinishLoadingStyle();
|
||||
}
|
||||
|
||||
for (Layer layer : layers) {
|
||||
style.addLayer(layer);
|
||||
}
|
||||
|
||||
if (transitionOptions != null) {
|
||||
style.setTransition(transitionOptions);
|
||||
}
|
||||
return style;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
public interface OnStyleLoaded {
|
||||
void onStyleLoaded(Style style);
|
||||
}
|
||||
|
||||
//
|
||||
// Style URL constants
|
||||
//
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.view.Gravity;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -57,6 +57,11 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
initLocation
|
||||
}
|
||||
|
||||
override fun validateTestSetup() {
|
||||
super.validateTestSetup()
|
||||
assertThat(mapboxMap.getStyle(), notNullValue())
|
||||
}
|
||||
|
||||
@Before
|
||||
override fun beforeTest() {
|
||||
super.beforeTest()
|
||||
@@ -152,7 +157,8 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
mapboxMap.setStyle(Style.LIGHT)
|
||||
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
component.activateLocationComponent(context, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -231,6 +237,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun locationComponentOptions_loadsForegroundBitmapFromNameOption() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -272,6 +279,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun locationComponentOptions_loadsGpsNameWithGpsRenderMode() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -302,6 +310,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun locationComponentOptions_customIconNameRevertsToDefault() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -335,6 +344,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun locationComponentOptions_customGpsIconNameChangeBackWithMode() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -368,6 +378,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun stillStaleAfterResuming() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -402,6 +413,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun stillNotStaleAfterResuming() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -424,6 +436,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun locationComponentOptions_accuracyRingWithColor() {
|
||||
validateTestSetup()
|
||||
val color = Color.parseColor("#4A90E2")
|
||||
val rgbaColor = ColorUtils.colorToRgbaString(color)
|
||||
|
||||
@@ -454,6 +467,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun forceLocationUpdate_doesMoveLocationLayerIconToCorrectPosition() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -474,6 +488,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun disablingComponentHidesPuck() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -496,6 +511,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun disablingComponentAndChangingStyleAllowsToEnableAgain() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -505,7 +521,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
component.isLocationComponentEnabled = false
|
||||
mapboxMap.setStyle(Style.LIGHT)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
|
||||
component.isLocationComponentEnabled = true
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
@@ -517,6 +533,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_isDisabledOnStart() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -534,6 +551,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_keepsEnabledWhenStoppedAndStarted() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -550,6 +568,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_keepsDisabledWhenStoppedAndStarted() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -567,6 +586,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_ableToChangeStyleAfterResuming() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -576,7 +596,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
component.onStop()
|
||||
component.onStart()
|
||||
|
||||
mapboxMap.setStyle(Style.DARK)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.DARK))
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
}
|
||||
}
|
||||
@@ -585,12 +605,13 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_interruptedDuringStyleChange() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
mapboxMap.setStyle(Style.DARK)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.DARK))
|
||||
component.onStop()
|
||||
component.onStart()
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
@@ -601,6 +622,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_forceLocationUpdateAfterStopped() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -618,6 +640,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_acceptAndReuseLocationUpdatesBeforeLayerStarted() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -638,13 +661,14 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_lifecycleChangeRightAfterStyleReload() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.setStyle(Style.LIGHT)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
component.onStop()
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
component.onStart()
|
||||
@@ -666,6 +690,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun mapChange_settingComponentStyle() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -691,6 +716,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun mapChange_forcingLocation() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -713,6 +739,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun mapChange_settingMapStyleBeforeComponentCreation() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -738,6 +765,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun animators_layerBearingCorrect() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -747,6 +775,8 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
location.bearing = 77f
|
||||
component.forceLocationUpdate(location)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS + MAP_RENDER_DELAY)
|
||||
assertThat(mapboxMap.style, notNullValue())
|
||||
assertThat(mapboxMap.style?.getSource(LOCATION_SOURCE), notNullValue())
|
||||
assertEquals(77.0, mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getNumberProperty(PROPERTY_GPS_BEARING) as Double, 0.1)
|
||||
|
||||
location.bearing = 92f
|
||||
|
||||
@@ -79,7 +79,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY)
|
||||
assertThat(mapboxMap.getStyle().getSource(LOCATION_SOURCE), notNullValue())
|
||||
assertThat(mapboxMap.getStyle()!!.getSource(LOCATION_SOURCE), notNullValue())
|
||||
}
|
||||
}
|
||||
executeComponentTest(componentAction)
|
||||
@@ -212,7 +212,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
mapboxMap.setStyleUrl(Style.LIGHT)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
@@ -220,7 +220,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
assertThat(component.renderMode, `is`(equalTo(RenderMode.NORMAL)))
|
||||
|
||||
// Check that the Source has been re-added to the new map style
|
||||
val source: GeoJsonSource? = mapboxMap.getStyle().getSourceAs(LOCATION_SOURCE)
|
||||
val source: GeoJsonSource? = mapboxMap.getStyle()!!.getSourceAs(LOCATION_SOURCE)
|
||||
assertThat(source, notNullValue())
|
||||
|
||||
// Check that all layers visibilities are set to visible
|
||||
@@ -253,7 +253,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
|
||||
assertThat(renderCheck.invoke(), `is`(true))
|
||||
|
||||
mapboxMap.setStyleUrl(Style.LIGHT)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import com.mapbox.mapboxsdk.style.layers.Property
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
|
||||
|
||||
fun MapboxMap.querySourceFeatures(sourceId: String): List<Feature> {
|
||||
return this.style.getSourceAs<GeoJsonSource>(sourceId)?.querySourceFeatures(null) ?: emptyList()
|
||||
return this.style!!.getSourceAs<GeoJsonSource>(sourceId)?.querySourceFeatures(null) ?: emptyList()
|
||||
}
|
||||
|
||||
fun MapboxMap.queryRenderedFeatures(location: Location, layerId: String): List<Feature> {
|
||||
@@ -25,7 +25,7 @@ fun MapboxMap.queryRenderedFeatures(location: Location, layerId: String): List<F
|
||||
}
|
||||
|
||||
fun MapboxMap.isLayerVisible(layerId: String): Boolean {
|
||||
return this.style.getLayer(layerId)?.visibility?.value?.equals(Property.VISIBLE)!!
|
||||
return this.style!!.getLayer(layerId)?.visibility?.value?.equals(Property.VISIBLE)!!
|
||||
}
|
||||
|
||||
fun MapboxMap.waitForSource(uiController: UiController, sourceId: String) {
|
||||
@@ -99,7 +99,7 @@ class MapboxTestingUtils {
|
||||
|
||||
fun MapboxMap.addImageFromDrawable(string: String, drawable: Drawable) {
|
||||
val bitmapFromDrawable = getBitmapFromDrawable(drawable)
|
||||
this.style.addImage(string, bitmapFromDrawable)
|
||||
this.style!!.addImage(string, bitmapFromDrawable)
|
||||
}
|
||||
|
||||
private fun getBitmapFromDrawable(drawable: Drawable): Bitmap {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.location.utils
|
||||
import android.support.test.espresso.IdlingResource
|
||||
import com.mapbox.mapboxsdk.maps.MapView
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
|
||||
/**
|
||||
* Resource, that's idling until the provided style is loaded.
|
||||
@@ -39,6 +40,6 @@ class StyleChangeIdlingResource : IdlingResource {
|
||||
setIdle()
|
||||
}
|
||||
})
|
||||
mapboxMap.setStyleUrl(styleUrl)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(styleUrl))
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
|
||||
@@ -67,9 +68,12 @@ public class MapboxMapTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
|
||||
long transitionDuration = 600;
|
||||
mapboxMap.setTransitionDuration(transitionDuration);
|
||||
mapboxMap.getStyle().setTransition(new TransitionOptions(transitionDuration, 0));
|
||||
assertEquals(
|
||||
"TransitionDuration should match", transitionDuration, mapboxMap.getTransitionDuration(), 0
|
||||
"TransitionDuration should match",
|
||||
transitionDuration,
|
||||
mapboxMap.getStyle().getTransition().getDuration(),
|
||||
0
|
||||
);
|
||||
}));
|
||||
}
|
||||
@@ -79,9 +83,12 @@ public class MapboxMapTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
|
||||
long transitionDelay = 50;
|
||||
mapboxMap.setTransitionDelay(transitionDelay);
|
||||
mapboxMap.getStyle().setTransition(new TransitionOptions(600, transitionDelay));
|
||||
assertEquals(
|
||||
"TransitionDelay should match", transitionDelay, mapboxMap.getTransitionDelay(), 0
|
||||
"TransitionDelay should match",
|
||||
transitionDelay,
|
||||
mapboxMap.getStyle().getTransition().getDelay(),
|
||||
0
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.style
|
||||
|
||||
import android.support.test.espresso.UiController
|
||||
import com.mapbox.geojson.Feature
|
||||
import com.mapbox.geojson.FeatureCollection
|
||||
import com.mapbox.geojson.Point
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
|
||||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest
|
||||
import com.mapbox.mapboxsdk.testapp.activity.maplayout.SimpleMapActivity
|
||||
import org.junit.Test
|
||||
|
||||
class CustomGeometrySourceTest : BaseActivityTest() {
|
||||
|
||||
override fun getActivityClass(): Class<*> = SimpleMapActivity::class.java
|
||||
|
||||
@Test
|
||||
fun sourceUpdateAfterStyleChange() {
|
||||
validateTestSetup()
|
||||
invoke(mapboxMap) { uiController: UiController, mapboxMap: MapboxMap ->
|
||||
val style = mapboxMap.style
|
||||
|
||||
val source = GeoJsonSource(
|
||||
"source-id",
|
||||
FeatureCollection.fromFeature(
|
||||
Feature.fromGeometry(
|
||||
Point.fromLngLat(0.0, 0.0)
|
||||
)
|
||||
)
|
||||
)
|
||||
style.addSource(source)
|
||||
|
||||
style.loadStyle(Style.DARK)
|
||||
|
||||
uiController.loopMainThreadForAtLeast(300)
|
||||
|
||||
source.setGeoJson(
|
||||
FeatureCollection.fromFeature(
|
||||
Feature.fromGeometry(
|
||||
Point.fromLngLat(1.0, 1.0)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun layerUpdateAfterStyleChange() {
|
||||
validateTestSetup()
|
||||
invoke(mapboxMap) { uiController: UiController, mapboxMap: MapboxMap ->
|
||||
val style = mapboxMap.style
|
||||
|
||||
val source = GeoJsonSource(
|
||||
"source-id",
|
||||
FeatureCollection.fromFeature(
|
||||
Feature.fromGeometry(
|
||||
Point.fromLngLat(0.0, 0.0)
|
||||
)
|
||||
)
|
||||
)
|
||||
style.addSource(source)
|
||||
|
||||
val layer = SymbolLayer("test", "source-id")
|
||||
style.addLayer(layer)
|
||||
|
||||
style.loadStyle(Style.DARK)
|
||||
|
||||
layer.setProperties(iconImage("bus-15"))
|
||||
|
||||
uiController.loopMainThreadForAtLeast(300)
|
||||
|
||||
layer.setProperties(iconImage("bus-15"))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import com.mapbox.mapboxsdk.testapp.activity.render.RenderTestActivity;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.SnapshotterIdlingResource;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -58,6 +59,7 @@ public class RenderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testRender() {
|
||||
onView(withId(android.R.id.content)).check(matches(isDisplayed()));
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ class CustomGeometrySourceTest : BaseActivityTest() {
|
||||
override fun getActivityClass(): Class<*> = GridSourceActivity::class.java
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
fun sourceNotLeakingThreadsTest() {
|
||||
validateTestSetup()
|
||||
waitAction(4000)
|
||||
@@ -39,9 +40,9 @@ class CustomGeometrySourceTest : BaseActivityTest() {
|
||||
fun threadsShutdownWhenSourceRemovedTest() {
|
||||
validateTestSetup()
|
||||
invoke(mapboxMap) { uiController, mapboxMap ->
|
||||
mapboxMap.getStyle().removeLayer(ID_GRID_LAYER)
|
||||
mapboxMap.style!!.removeLayer(ID_GRID_LAYER)
|
||||
uiController.loopMainThreadForAtLeast(3000)
|
||||
mapboxMap.getStyle().removeSource(ID_GRID_SOURCE)
|
||||
mapboxMap.style!!.removeSource(ID_GRID_SOURCE)
|
||||
uiController.loopMainThreadForAtLeast(1000)
|
||||
Assert.assertTrue("There should be no threads running when the source is removed.",
|
||||
Thread.getAllStackTraces().keys.filter {
|
||||
@@ -55,12 +56,12 @@ class CustomGeometrySourceTest : BaseActivityTest() {
|
||||
fun threadsRestartedWhenSourceReAddedTest() {
|
||||
validateTestSetup()
|
||||
invoke(mapboxMap) { uiController, mapboxMap ->
|
||||
mapboxMap.getStyle().removeLayer((rule.activity as GridSourceActivity).layer)
|
||||
mapboxMap.style!!.removeLayer((rule.activity as GridSourceActivity).layer)
|
||||
uiController.loopMainThreadForAtLeast(3000)
|
||||
mapboxMap.getStyle().removeSource(ID_GRID_SOURCE)
|
||||
mapboxMap.style!!.removeSource(ID_GRID_SOURCE)
|
||||
uiController.loopMainThreadForAtLeast(1000)
|
||||
mapboxMap.getStyle().addSource((rule.activity as GridSourceActivity).source)
|
||||
mapboxMap.getStyle().addLayer((rule.activity as GridSourceActivity).layer)
|
||||
mapboxMap.style!!.addSource((rule.activity as GridSourceActivity).source)
|
||||
mapboxMap.style!!.addLayer((rule.activity as GridSourceActivity).layer)
|
||||
uiController.loopMainThreadForAtLeast(1000)
|
||||
Assert.assertTrue("Threads should be restarted when the source is re-added to the map.",
|
||||
Thread.getAllStackTraces().keys.filter {
|
||||
|
||||
@@ -242,7 +242,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
Expression expression3 = eq(literal("Łukasz"), literal("lukasz"), collator(literal(false), eq(literal(2),
|
||||
literal(1))));
|
||||
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle()
|
||||
.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
Layer layer = new CircleLayer("layer", "source")
|
||||
.withProperties(circleColor(
|
||||
switchCase(
|
||||
@@ -282,7 +283,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle()
|
||||
.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
@@ -304,7 +306,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle()
|
||||
.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
@@ -326,7 +329,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle()
|
||||
.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
@@ -355,7 +359,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle()
|
||||
.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
@@ -386,7 +391,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle()
|
||||
.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
@@ -477,7 +483,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle()
|
||||
.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
|
||||
@@ -39,11 +39,11 @@ public class ImageTest extends BaseActivityTest {
|
||||
Bitmap bitmapSet = ((BitmapDrawable) drawable).getBitmap();
|
||||
mapboxMap.getStyle().addImage(IMAGE_ID, bitmapSet);
|
||||
|
||||
Bitmap bitmapGet = mapboxMap.getImage(IMAGE_ID);
|
||||
Bitmap bitmapGet = mapboxMap.getStyle().getImage(IMAGE_ID);
|
||||
assertTrue(bitmapGet.sameAs(bitmapSet));
|
||||
|
||||
mapboxMap.removeImage(IMAGE_ID);
|
||||
assertNull(mapboxMap.getImage(IMAGE_ID));
|
||||
mapboxMap.getStyle().removeImage(IMAGE_ID);
|
||||
assertNull(mapboxMap.getStyle().getImage(IMAGE_ID));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,9 @@ public class RuntimeStyleTests extends BaseActivityTest {
|
||||
|
||||
// Test inserting with invalid above-id
|
||||
try {
|
||||
mapboxMap.getStyle().addLayerAbove(new CircleLayer("invalid-id-layer-test", source.getId()), "no-such-layer-here-man");
|
||||
mapboxMap.getStyle().addLayerAbove(
|
||||
new CircleLayer("invalid-id-layer-test", source.getId()), "no-such-layer-here-man"
|
||||
);
|
||||
fail("Should have thrown exception");
|
||||
} catch (CannotAddLayerException ex) {
|
||||
// Yeah
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.support.test.espresso.UiController;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
@@ -37,8 +38,8 @@ public class StyleLoaderTest extends BaseActivityTest {
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
try {
|
||||
String expected = ResourceUtils.readRawResource(rule.getActivity(), R.raw.local_style);
|
||||
mapboxMap.setStyleJson(expected);
|
||||
String actual = mapboxMap.getStyleJson();
|
||||
mapboxMap.setStyle(new Style.Builder().fromJson(expected));
|
||||
String actual = mapboxMap.getStyle().getJson();
|
||||
assertEquals("Style json should match", expected, actual);
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
@@ -55,7 +56,7 @@ public class StyleLoaderTest extends BaseActivityTest {
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
try {
|
||||
String expected = ResourceUtils.readRawResource(rule.getActivity(), R.raw.local_style);
|
||||
mapboxMap.setStyleJson(expected);
|
||||
mapboxMap.setStyle(new Style.Builder().fromJson(expected));
|
||||
|
||||
// fake activity stop/start
|
||||
MapView mapView = (MapView) rule.getActivity().findViewById(R.id.mapView);
|
||||
@@ -65,8 +66,8 @@ public class StyleLoaderTest extends BaseActivityTest {
|
||||
mapView.onStart();
|
||||
mapView.onResume();
|
||||
|
||||
String actual = mapboxMap.getStyleJson();
|
||||
assertEquals("Style URL should be empty", "", mapboxMap.getStyleUrl());
|
||||
String actual = mapboxMap.getStyle().getJson();
|
||||
assertEquals("Style URL should be empty", "", mapboxMap.getStyle().getUrl());
|
||||
assertEquals("Style json should match", expected, actual);
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
|
||||
@@ -10,12 +10,14 @@ import android.support.test.espresso.IdlingResource;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallback {
|
||||
|
||||
private boolean styleLoaded;
|
||||
private MapboxMap mapboxMap;
|
||||
private IdlingResource.ResourceCallback resourceCallback;
|
||||
|
||||
@@ -25,11 +27,22 @@ public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallb
|
||||
handler.post(() -> {
|
||||
MapView mapView = activity.findViewById(R.id.mapView);
|
||||
if (mapView != null) {
|
||||
mapView.getMapAsync(OnMapReadyIdlingResource.this);
|
||||
mapView.addOnDidFinishLoadingStyleListener(() -> {
|
||||
styleLoaded = true;
|
||||
if (resourceCallback != null) {
|
||||
resourceCallback.onTransitionToIdle();
|
||||
}
|
||||
});
|
||||
mapView.getMapAsync(this::initMap);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initMap(MapboxMap mapboxMap) {
|
||||
this.mapboxMap = mapboxMap;
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getClass().getSimpleName();
|
||||
@@ -37,7 +50,7 @@ public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallb
|
||||
|
||||
@Override
|
||||
public boolean isIdleNow() {
|
||||
return mapboxMap != null;
|
||||
return styleLoaded;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,8 +66,5 @@ public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallb
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
Assert.assertNotNull("MapboxMap should not be null", mapboxMap);
|
||||
this.mapboxMap = mapboxMap;
|
||||
if (resourceCallback != null) {
|
||||
resourceCallback.onTransitionToIdle();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
public class SingleActivity extends AppCompatActivity {
|
||||
@@ -14,8 +15,9 @@ public class SingleActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_single);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(new Style.Builder().fromUrl(Style.MAPBOX_STREETS)));
|
||||
}
|
||||
|
||||
public MapView getMapView() {
|
||||
|
||||
@@ -72,14 +72,15 @@ public class AnimatedSymbolLayerActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_animated_marker);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
this.mapboxMap = map;
|
||||
this.style = mapboxMap.getStyle();
|
||||
setupCars();
|
||||
animateRandomRoutes();
|
||||
animateTaxi();
|
||||
map.setStyle(Style.MAPBOX_STREETS, style -> {
|
||||
setupCars();
|
||||
animateRandomRoutes();
|
||||
animateTaxi();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.IconUtils;
|
||||
|
||||
@@ -31,10 +32,12 @@ public class DynamicMarkerChangeActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_dynamic_marker);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.setTag(false);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
|
||||
DynamicMarkerChangeActivity.this.mapboxMap = mapboxMap;
|
||||
// Create marker
|
||||
MarkerOptions markerOptions = new MarkerOptions()
|
||||
@@ -46,7 +49,7 @@ public class DynamicMarkerChangeActivity extends AppCompatActivity {
|
||||
marker = mapboxMap.addMarker(markerOptions);
|
||||
});
|
||||
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
FloatingActionButton fab = findViewById(R.id.fab);
|
||||
fab.setColorFilter(ContextCompat.getColor(this, R.color.primary));
|
||||
fab.setOnClickListener(view -> {
|
||||
if (mapboxMap != null) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import timber.log.Timber;
|
||||
@@ -65,15 +66,14 @@ public class CameraAnimationTypeActivity extends AppCompatActivity implements On
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_camera_animation_types);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
if (mapView != null) {
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(this);
|
||||
}
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Style.MAPBOX_STREETS));
|
||||
mapboxMap.getUiSettings().setAttributionEnabled(false);
|
||||
mapboxMap.getUiSettings().setLogoEnabled(false);
|
||||
mapboxMap.addOnCameraIdleListener(cameraIdleListener);
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.FontCache;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
|
||||
@@ -71,6 +72,7 @@ public class GestureDetectorActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
GestureDetectorActivity.this.mapboxMap = mapboxMap;
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
initializeMap();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.view.LockableBottomSheetBehavior;
|
||||
|
||||
@@ -52,20 +53,26 @@ public class LatLngBoundsActivity extends AppCompatActivity implements View.OnCl
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_latlngbounds);
|
||||
initBottomSheet();
|
||||
initMapView(savedInstanceState);
|
||||
}
|
||||
|
||||
private void initMapView(Bundle savedInstanceState) {
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
initMap();
|
||||
disableGestures();
|
||||
moveToBounds(bottomSheet.getMeasuredHeight(), BOUNDS_PADDING_DIVIDER_SMALL, ANIMATION_DURATION_SHORT);
|
||||
loadStyle();
|
||||
});
|
||||
}
|
||||
|
||||
private void initMap() {
|
||||
disableGestures();
|
||||
addMarkers();
|
||||
initFab();
|
||||
initBottomSheet();
|
||||
moveToBounds(bottomSheet.getMeasuredHeight(), BOUNDS_PADDING_DIVIDER_SMALL, ANIMATION_DURATION_SHORT);
|
||||
private void loadStyle() {
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Style.MAPBOX_STREETS), style -> {
|
||||
addMarkers();
|
||||
initFab();
|
||||
});
|
||||
}
|
||||
|
||||
private void disableGestures() {
|
||||
@@ -96,7 +103,7 @@ public class LatLngBoundsActivity extends AppCompatActivity implements View.OnCl
|
||||
bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
|
||||
@Override
|
||||
public void onStateChanged(@NonNull View bottomSheet, int newState) {
|
||||
if (newState == BottomSheetBehavior.STATE_SETTLING) {
|
||||
if (newState == BottomSheetBehavior.STATE_SETTLING && mapboxMap != null) {
|
||||
moveToBounds(0, BOUNDS_PADDING_DIVIDER_LARGE, ANIMATION_DURATION_LONG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,11 +31,10 @@ public class ManualZoomActivity extends AppCompatActivity {
|
||||
setContentView(R.layout.activity_manual_zoom);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.setStyleUrl(Style.SATELLITE);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
ManualZoomActivity.this.mapboxMap = mapboxMap;
|
||||
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Style.SATELLITE));
|
||||
UiSettings uiSettings = ManualZoomActivity.this.mapboxMap.getUiSettings();
|
||||
uiSettings.setAllGesturesEnabled(false);
|
||||
});
|
||||
|
||||
@@ -25,7 +25,7 @@ public class MaxMinZoomActivity extends AppCompatActivity implements OnMapReadyC
|
||||
@Override
|
||||
public boolean onMapClick(@NonNull LatLng point) {
|
||||
if (mapboxMap != null) {
|
||||
mapboxMap.setStyle(Style.OUTDOORS);
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Style.OUTDOORS));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
@@ -35,15 +34,17 @@ public class CustomLayerActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_custom_layer);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(39.91448, -243.60947), 10));
|
||||
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> initFab());
|
||||
});
|
||||
}
|
||||
|
||||
fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
private void initFab() {
|
||||
fab = findViewById(R.id.fab);
|
||||
fab.setColorFilter(ContextCompat.getColor(this, R.color.primary));
|
||||
fab.setOnClickListener(view -> {
|
||||
if (mapboxMap != null) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
public class DeviceIndependentTestActivity extends AppCompatActivity implements OnMapReadyCallback {
|
||||
@@ -27,6 +28,7 @@ public class DeviceIndependentTestActivity extends AppCompatActivity implements
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
}
|
||||
|
||||
public MapboxMap getMapboxMap() {
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.google.gson.JsonElement;
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import java.util.List;
|
||||
@@ -37,6 +38,9 @@ public class QueryRenderedFeaturesBoxCountActivity extends AppCompatActivity {
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
QueryRenderedFeaturesBoxCountActivity.this.mapboxMap = mapboxMap;
|
||||
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Style.MAPBOX_STREETS));
|
||||
|
||||
selectionBox.setOnClickListener(view -> {
|
||||
// Query
|
||||
int top = selectionBox.getTop() - mapView.getTop();
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.FillLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
@@ -48,15 +49,10 @@ public class QueryRenderedFeaturesBoxHighlightActivity extends AppCompatActivity
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
QueryRenderedFeaturesBoxHighlightActivity.this.mapboxMap = mapboxMap;
|
||||
|
||||
Style style = mapboxMap.getStyle();
|
||||
|
||||
// Add layer / source
|
||||
final GeoJsonSource source = new GeoJsonSource("highlighted-shapes-source");
|
||||
style.addSource(source);
|
||||
style.addLayer(
|
||||
new FillLayer("highlighted-shapes-layer", "highlighted-shapes-source")
|
||||
.withProperties(fillColor(Color.RED))
|
||||
);
|
||||
final Layer layer = new FillLayer("highlighted-shapes-layer", "highlighted-shapes-source")
|
||||
.withProperties(fillColor(Color.RED));
|
||||
|
||||
selectionBox.setOnClickListener(view -> {
|
||||
// Query
|
||||
@@ -77,6 +73,12 @@ public class QueryRenderedFeaturesBoxHighlightActivity extends AppCompatActivity
|
||||
// Update source data
|
||||
source.setGeoJson(FeatureCollection.fromFeatures(features));
|
||||
});
|
||||
|
||||
mapboxMap.setStyle(new Style.Builder()
|
||||
.fromUrl(Style.MAPBOX_STREETS)
|
||||
.withSource(source)
|
||||
.withLayer(layer)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.feature;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.RectF;
|
||||
import android.os.Bundle;
|
||||
@@ -10,6 +11,8 @@ import android.widget.Toast;
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.BackgroundLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
@@ -20,6 +23,8 @@ import java.util.List;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.rgb;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage;
|
||||
|
||||
/**
|
||||
@@ -45,20 +50,31 @@ public class QueryRenderedFeaturesBoxSymbolCountActivity extends AppCompatActivi
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
QueryRenderedFeaturesBoxSymbolCountActivity.this.mapboxMap = mapboxMap;
|
||||
|
||||
// Add a symbol layer (also works with annotations)
|
||||
try {
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("symbols-source", ResourceUtils.readRawResource(
|
||||
QueryRenderedFeaturesBoxSymbolCountActivity.this, R.raw.test_points_utrecht)));
|
||||
} catch (IOException ioException) {
|
||||
Timber.e(ioException, "Could not load geojson");
|
||||
return;
|
||||
String testPoints = ResourceUtils.readRawResource(mapView.getContext(), R.raw.test_points_utrecht);
|
||||
Bitmap markerImage = BitmapFactory.decodeResource(getResources(), R.drawable.mapbox_marker_icon_default);
|
||||
|
||||
mapboxMap.setStyle(new Style.Builder()
|
||||
.withLayer(
|
||||
new BackgroundLayer("bg")
|
||||
.withProperties(
|
||||
backgroundColor(rgb(120, 161, 226))
|
||||
)
|
||||
)
|
||||
.withLayer(
|
||||
new SymbolLayer("symbols-layer", "symbols-source")
|
||||
.withProperties(
|
||||
iconImage("test-icon")
|
||||
)
|
||||
)
|
||||
.withSource(
|
||||
new GeoJsonSource("symbols-source", testPoints)
|
||||
)
|
||||
.withImage("test-icon", markerImage)
|
||||
);
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
mapboxMap.getStyle().addImage(
|
||||
"test-icon",
|
||||
BitmapFactory.decodeResource(getResources(),
|
||||
R.drawable.mapbox_marker_icon_default)
|
||||
);
|
||||
mapboxMap.getStyle().addLayer(new SymbolLayer("symbols-layer", "symbols-source").withProperties(iconImage("test-icon")));
|
||||
|
||||
selectionBox.setOnClickListener(view -> {
|
||||
// Query
|
||||
|
||||
@@ -66,7 +66,6 @@ public class QueryRenderedFeaturesPropertiesActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_query_features_point);
|
||||
|
||||
|
||||
// Initialize map as normal
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
|
||||
@@ -5,12 +5,13 @@ import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.FeatureCollection;
|
||||
import com.mapbox.geojson.Point;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
@@ -29,6 +30,7 @@ import static com.mapbox.mapboxsdk.style.expressions.Expression.neq;
|
||||
public class QuerySourceFeaturesActivity extends AppCompatActivity {
|
||||
|
||||
public MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -38,47 +40,53 @@ public class QuerySourceFeaturesActivity extends AppCompatActivity {
|
||||
// Initialize map as normal
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
JsonObject properties = new JsonObject();
|
||||
properties.addProperty("key1", "value1");
|
||||
final GeoJsonSource source = new GeoJsonSource("test-source",
|
||||
FeatureCollection.fromFeatures(new Feature[] {
|
||||
Feature.fromGeometry(Point.fromLngLat(17.1, 51), properties),
|
||||
Feature.fromGeometry(Point.fromLngLat(17.2, 51), properties),
|
||||
Feature.fromGeometry(Point.fromLngLat(17.3, 51), properties),
|
||||
Feature.fromGeometry(Point.fromLngLat(17.4, 51), properties),
|
||||
}));
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
mapView.getMapAsync(map -> {
|
||||
this.mapboxMap = map;
|
||||
mapboxMap.getStyle(this::initStyle);
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
});
|
||||
}
|
||||
|
||||
Expression visible = eq(get("key1"), literal("value1"));
|
||||
Expression invisible = neq(get("key1"), literal("value1"));
|
||||
private void initStyle(Style style) {
|
||||
JsonObject properties = new JsonObject();
|
||||
properties.addProperty("key1", "value1");
|
||||
final GeoJsonSource source = new GeoJsonSource("test-source",
|
||||
FeatureCollection.fromFeatures(new Feature[] {
|
||||
Feature.fromGeometry(Point.fromLngLat(17.1, 51), properties),
|
||||
Feature.fromGeometry(Point.fromLngLat(17.2, 51), properties),
|
||||
Feature.fromGeometry(Point.fromLngLat(17.3, 51), properties),
|
||||
Feature.fromGeometry(Point.fromLngLat(17.4, 51), properties),
|
||||
}));
|
||||
style.addSource(source);
|
||||
|
||||
CircleLayer layer = new CircleLayer("test-layer", source.getId())
|
||||
.withFilter(visible);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
Expression visible = eq(get("key1"), literal("value1"));
|
||||
Expression invisible = neq(get("key1"), literal("value1"));
|
||||
|
||||
// Add a click listener
|
||||
mapboxMap.addOnMapClickListener(point -> {
|
||||
// Query
|
||||
List<Feature> features = source.querySourceFeatures(eq(get("key1"), literal("value1")));
|
||||
Toast.makeText(QuerySourceFeaturesActivity.this, String.format("Found %s features",
|
||||
features.size()), Toast.LENGTH_SHORT).show();
|
||||
CircleLayer layer = new CircleLayer("test-layer", source.getId())
|
||||
.withFilter(visible);
|
||||
style.addLayer(layer);
|
||||
|
||||
return false;
|
||||
});
|
||||
// Add a click listener
|
||||
mapboxMap.addOnMapClickListener(point -> {
|
||||
// Query
|
||||
List<Feature> features = source.querySourceFeatures(eq(get("key1"), literal("value1")));
|
||||
Toast.makeText(QuerySourceFeaturesActivity.this, String.format("Found %s features",
|
||||
features.size()), Toast.LENGTH_SHORT).show();
|
||||
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
fab.setColorFilter(ContextCompat.getColor(this, R.color.primary));
|
||||
fab.setOnClickListener(view -> {
|
||||
Expression visibility = layer.getFilter();
|
||||
if (visibility != null && visibility.equals(visible)) {
|
||||
layer.setFilter(invisible);
|
||||
fab.setImageResource(R.drawable.ic_layers_clear);
|
||||
} else {
|
||||
layer.setFilter(visible);
|
||||
fab.setImageResource(R.drawable.ic_layers);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
fab.setColorFilter(ContextCompat.getColor(this, R.color.primary));
|
||||
fab.setOnClickListener(view -> {
|
||||
Expression visibility = layer.getFilter();
|
||||
if (visibility != null && visibility.equals(visible)) {
|
||||
layer.setFilter(invisible);
|
||||
fab.setImageResource(R.drawable.ic_layers_clear);
|
||||
} else {
|
||||
layer.setFilter(visible);
|
||||
fab.setImageResource(R.drawable.ic_layers);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition
|
||||
import com.mapbox.mapboxsdk.constants.Style
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMapOptions
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.maps.SupportMapFragment
|
||||
import com.mapbox.mapboxsdk.testapp.R
|
||||
import kotlinx.android.synthetic.main.activity_recyclerview.*
|
||||
|
||||
@@ -23,14 +23,14 @@ public class PrintActivity extends AppCompatActivity implements MapboxMap.Snapsh
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_print);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> PrintActivity.this.mapboxMap = mapboxMap);
|
||||
|
||||
final View fab = findViewById(R.id.fab);
|
||||
if (fab != null) {
|
||||
fab.setOnClickListener(view -> {
|
||||
if (mapboxMap != null) {
|
||||
if (mapboxMap.getStyle() != null) {
|
||||
mapboxMap.snapshot(PrintActivity.this);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -41,7 +41,7 @@ public class SnapshotActivity extends AppCompatActivity implements OnMapReadyCal
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
mapboxMap.setStyleUrl(Style.OUTDOORS);
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Style.OUTDOORS));
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
if (fab != null) {
|
||||
fab.setColorFilter(ContextCompat.getColor(SnapshotActivity.this, R.color.primary));
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import com.mapbox.mapboxsdk.maps.MapView
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import com.mapbox.mapboxsdk.location.LocationComponent
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.testapp.R
|
||||
import kotlinx.android.synthetic.main.activity_location_layer_fragment.*
|
||||
import java.lang.Exception
|
||||
@@ -104,10 +105,12 @@ class LocationFragmentActivity : AppCompatActivity() {
|
||||
mapView.onCreate(savedInstanceState)
|
||||
mapView.getMapAsync {
|
||||
mapboxMap = it
|
||||
component = mapboxMap.locationComponent
|
||||
component?.activateLocationComponent(activity)
|
||||
component?.isLocationComponentEnabled = true
|
||||
component?.locationEngine?.getLastLocation(this)
|
||||
it.setStyle(Style.MAPBOX_STREETS) { _ ->
|
||||
component = mapboxMap.locationComponent
|
||||
component?.activateLocationComponent(activity)
|
||||
component?.isLocationComponentEnabled = true
|
||||
component?.locationEngine?.getLastLocation(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.mapbox.mapboxsdk.location.modes.RenderMode;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import java.util.List;
|
||||
@@ -34,11 +35,10 @@ public class LocationMapChangeActivity extends AppCompatActivity implements OnMa
|
||||
|
||||
stylesFab.setOnClickListener(v -> {
|
||||
if (mapboxMap != null) {
|
||||
mapboxMap.setStyleUrl(Utils.getNextStyle());
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Utils.getNextStyle()));
|
||||
}
|
||||
});
|
||||
|
||||
mapView.setStyleUrl(Utils.getNextStyle());
|
||||
mapView.onCreate(savedInstanceState);
|
||||
|
||||
if (PermissionsManager.areLocationPermissionsGranted(this)) {
|
||||
@@ -73,12 +73,14 @@ public class LocationMapChangeActivity extends AppCompatActivity implements OnMa
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
this.mapboxMap = mapboxMap;
|
||||
activateLocationComponent();
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Utils.getNextStyle()),
|
||||
style -> activateLocationComponent());
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private void activateLocationComponent() {
|
||||
LocationComponent locationComponent = mapboxMap.getLocationComponent();
|
||||
locationComponent.onStart();
|
||||
locationComponent.activateLocationComponent(this);
|
||||
locationComponent.setLocationComponentEnabled(true);
|
||||
locationComponent.setRenderMode(RenderMode.COMPASS);
|
||||
|
||||
@@ -12,6 +12,8 @@ import android.view.MenuItem;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapbox.android.core.location.LocationEngineRequest;
|
||||
import com.mapbox.android.core.permissions.PermissionsListener;
|
||||
import com.mapbox.android.core.permissions.PermissionsManager;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
@@ -121,32 +123,34 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
this.mapboxMap = mapboxMap;
|
||||
|
||||
int[] padding;
|
||||
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
padding = new int[] {0, 750, 0, 0};
|
||||
} else {
|
||||
padding = new int[] {0, 250, 0, 0};
|
||||
}
|
||||
mapboxMap.getStyle(style -> {
|
||||
int[] padding;
|
||||
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
padding = new int[] {0, 750, 0, 0};
|
||||
} else {
|
||||
padding = new int[] {0, 250, 0, 0};
|
||||
}
|
||||
|
||||
LocationComponentOptions options = LocationComponentOptions.builder(this)
|
||||
.padding(padding)
|
||||
.layerBelow("waterway-label")
|
||||
.build();
|
||||
LocationComponentOptions options = LocationComponentOptions.builder(this)
|
||||
.padding(padding)
|
||||
.layerBelow("waterway-label")
|
||||
.build();
|
||||
|
||||
locationComponent = mapboxMap.getLocationComponent();
|
||||
locationComponent.activateLocationComponent(this, true,
|
||||
new LocationEngineRequest.Builder(750)
|
||||
.setFastestInterval(750)
|
||||
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
|
||||
.build()
|
||||
);
|
||||
locationComponent.applyStyle(options);
|
||||
locationComponent.setLocationComponentEnabled(true);
|
||||
locationComponent.addOnLocationClickListener(this);
|
||||
locationComponent.addOnCameraTrackingChangedListener(this);
|
||||
locationComponent.setCameraMode(cameraMode);
|
||||
setRendererMode(renderMode);
|
||||
locationComponent.forceLocationUpdate(lastLocation);
|
||||
locationComponent = mapboxMap.getLocationComponent();
|
||||
locationComponent.activateLocationComponent(this, true,
|
||||
new LocationEngineRequest.Builder(750)
|
||||
.setFastestInterval(750)
|
||||
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
|
||||
.build()
|
||||
);
|
||||
locationComponent.applyStyle(options);
|
||||
locationComponent.setLocationComponentEnabled(true);
|
||||
locationComponent.addOnLocationClickListener(this);
|
||||
locationComponent.addOnCameraTrackingChangedListener(this);
|
||||
locationComponent.setCameraMode(cameraMode);
|
||||
setRendererMode(renderMode);
|
||||
locationComponent.forceLocationUpdate(lastLocation);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -187,6 +191,10 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
|
||||
}
|
||||
|
||||
private void toggleStyle() {
|
||||
if (locationComponent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
customStyle = !customStyle;
|
||||
locationComponent.applyStyle(
|
||||
this,
|
||||
@@ -194,11 +202,19 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
|
||||
}
|
||||
|
||||
private void toggleMapStyle() {
|
||||
String styleUrl = mapboxMap.getStyleUrl().contentEquals(Style.DARK) ? Style.LIGHT : Style.DARK;
|
||||
mapboxMap.setStyle(styleUrl);
|
||||
if (locationComponent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String styleUrl = Style.DARK.equals(mapboxMap.getStyle().getUrl()) ? Style.LIGHT : Style.DARK;
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(styleUrl));
|
||||
}
|
||||
|
||||
private void disableGesturesManagement() {
|
||||
if (locationComponent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
LocationComponentOptions options = locationComponent
|
||||
.getLocationComponentOptions()
|
||||
.toBuilder()
|
||||
@@ -208,6 +224,10 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
|
||||
}
|
||||
|
||||
private void enableGesturesManagement() {
|
||||
if (locationComponent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
LocationComponentOptions options = locationComponent
|
||||
.getLocationComponentOptions()
|
||||
.toBuilder()
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapbox.android.core.location.LocationEngine;
|
||||
import com.mapbox.android.core.location.LocationEngineProvider;
|
||||
import com.mapbox.android.core.location.LocationEngineRequest;
|
||||
@@ -18,6 +17,7 @@ import com.mapbox.mapboxsdk.location.modes.RenderMode;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import java.util.List;
|
||||
@@ -107,16 +107,18 @@ public class ManualLocationUpdatesActivity extends AppCompatActivity implements
|
||||
@SuppressLint("MissingPermission")
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
locationComponent = mapboxMap.getLocationComponent();
|
||||
locationComponent.activateLocationComponent(
|
||||
this,
|
||||
locationEngine,
|
||||
new LocationEngineRequest.Builder(500)
|
||||
.setFastestInterval(500)
|
||||
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
|
||||
.build());
|
||||
locationComponent.setLocationComponentEnabled(true);
|
||||
locationComponent.setRenderMode(RenderMode.COMPASS);
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Style.MAPBOX_STREETS), style -> {
|
||||
locationComponent = mapboxMap.getLocationComponent();
|
||||
locationComponent.activateLocationComponent(
|
||||
this,
|
||||
locationEngine,
|
||||
new LocationEngineRequest.Builder(500)
|
||||
.setFastestInterval(500)
|
||||
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
|
||||
.build());
|
||||
locationComponent.setLocationComponentEnabled(true);
|
||||
locationComponent.setRenderMode(RenderMode.COMPASS);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,10 +16,11 @@ import android.widget.BaseAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.layers.Property;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
@@ -81,8 +82,9 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
|
||||
}
|
||||
|
||||
private void setupMapView(Bundle savedInstanceState) {
|
||||
mapView = findViewById(R.id.mapView);
|
||||
|
||||
MapboxMapOptions mapboxMapOptions = setupMapboxMapOptions();
|
||||
mapView = new MapView(this, mapboxMapOptions);
|
||||
((ViewGroup) findViewById(R.id.coordinator_layout)).addView(mapView);
|
||||
mapView.addOnDidFinishLoadingStyleListener(() -> {
|
||||
if (mapboxMap != null) {
|
||||
setupNavigationView(mapboxMap.getStyle().getLayers());
|
||||
@@ -90,17 +92,23 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
|
||||
});
|
||||
|
||||
mapView.setTag(true);
|
||||
mapView.setStyleUrl(STYLES[currentStyleIndex]);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(this);
|
||||
mapView.addOnDidFinishLoadingStyleListener(() -> Timber.d("Style loaded"));
|
||||
}
|
||||
|
||||
protected MapboxMapOptions setupMapboxMapOptions() {
|
||||
MapboxMapOptions mapboxMapOptions = new MapboxMapOptions();
|
||||
mapboxMapOptions.styleUrl(Style.MAPBOX_STREETS);
|
||||
return mapboxMapOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
|
||||
setupNavigationView(mapboxMap.getStyle().getLayers());
|
||||
mapboxMap.setStyle(
|
||||
new Style.Builder().fromUrl(STYLES[currentStyleIndex]), style -> setupNavigationView(style.getLayers())
|
||||
);
|
||||
setupZoomView();
|
||||
setFpsView();
|
||||
}
|
||||
@@ -113,7 +121,7 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
|
||||
}
|
||||
|
||||
private void setupNavigationView(List<Layer> layerList) {
|
||||
Timber.v("New style loaded with JSON: %s", mapboxMap.getStyleJson());
|
||||
Timber.v("New style loaded with JSON: %s", mapboxMap.getStyle().getJson());
|
||||
final LayerListAdapter adapter = new LayerListAdapter(this, layerList);
|
||||
ListView listView = findViewById(R.id.listView);
|
||||
listView.setAdapter(adapter);
|
||||
@@ -161,7 +169,7 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
|
||||
if (currentStyleIndex == STYLES.length) {
|
||||
currentStyleIndex = 0;
|
||||
}
|
||||
mapboxMap.setStyleUrl(STYLES[currentStyleIndex]);
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(STYLES[currentStyleIndex]));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -82,7 +82,6 @@ public class DoubleMapActivity extends AppCompatActivity {
|
||||
// MapView mini
|
||||
mapViewMini = view.findViewById(R.id.mini_map);
|
||||
mapViewMini.onCreate(savedInstanceState);
|
||||
mapViewMini.setStyleUrl(Style.LIGHT);
|
||||
mapViewMini.getMapAsync(mapboxMap -> {
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder().target(MACHU_PICCHU)
|
||||
@@ -90,6 +89,7 @@ public class DoubleMapActivity extends AppCompatActivity {
|
||||
.build()
|
||||
)
|
||||
);
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Style.LIGHT));
|
||||
|
||||
UiSettings uiSettings = mapboxMap.getUiSettings();
|
||||
uiSettings.setAllGesturesEnabled(false);
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.maplayout;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
/**
|
||||
@@ -24,20 +20,17 @@ public class LocalGlyphActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_local_glyph);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
// Set initial position to Suzhou
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
.target(new LatLng(31.3003, 120.7457))
|
||||
.zoom(11)
|
||||
.bearing(0)
|
||||
.tilt(0)
|
||||
.build()));
|
||||
}
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
// Set initial position to Suzhou
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
.target(new LatLng(31.3003, 120.7457))
|
||||
.zoom(11)
|
||||
.bearing(0)
|
||||
.tilt(0)
|
||||
.build()));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import timber.log.Timber;
|
||||
@@ -17,7 +17,6 @@ import timber.log.Timber;
|
||||
public class MapChangeActivity extends AppCompatActivity {
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -38,8 +37,8 @@ public class MapChangeActivity extends AppCompatActivity {
|
||||
mapView.addOnWillStartRenderingFrameListener(() -> Timber.v("OnWillStartRenderingFrame"));
|
||||
mapView.addOnWillStartRenderingMapListener(() -> Timber.v("OnWillStartRenderingMap"));
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
|
||||
new LatLng(55.754020, 37.620948), 12), 9000);
|
||||
});
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.UiSettings;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
/**
|
||||
@@ -26,7 +27,7 @@ public class MapPaddingActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_map_padding);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.setTag(true);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
|
||||
@@ -39,6 +40,11 @@ public class MapPaddingActivity extends AppCompatActivity {
|
||||
int paddingTop = (int) getResources().getDimension(R.dimen.map_padding_top);
|
||||
mapboxMap.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
|
||||
|
||||
UiSettings settings = mapboxMap.getUiSettings();
|
||||
settings.setLogoMargins(paddingLeft, 0, 0, paddingBottom);
|
||||
settings.setCompassMargins(0, paddingTop, paddingRight, 0);
|
||||
settings.setAttributionEnabled(false);
|
||||
|
||||
moveToBangalore();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.graphics.*
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.view.View
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.testapp.R
|
||||
import kotlinx.android.synthetic.main.activity_overlay.*
|
||||
|
||||
@@ -19,6 +20,9 @@ class OverlayMapActivity : AppCompatActivity() {
|
||||
setContentView(R.layout.activity_overlay)
|
||||
mapView.onCreate(savedInstanceState)
|
||||
parentView.addView(OverlayView(this))
|
||||
mapView.getMapAsync {
|
||||
it.setStyle(Style.MAPBOX_STREETS)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.mapbox.mapboxsdk.testapp.activity.maplayout;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
/**
|
||||
@@ -17,8 +17,11 @@ public class SimpleMapActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_map_simple);
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(
|
||||
new Style.Builder().fromUrl(Style.MAPBOX_STREETS)
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,14 +27,13 @@ class MergeOfflineRegionsActivity : AppCompatActivity() {
|
||||
// forcing offline state
|
||||
Mapbox.setConnected(false)
|
||||
|
||||
mapView.setStyleUrl(TEST_STYLE)
|
||||
|
||||
mapView.onCreate(savedInstanceState)
|
||||
load_region_btn.setOnClickListener {
|
||||
copyAsset()
|
||||
}
|
||||
mapView.getMapAsync {
|
||||
it.isDebugActive = true
|
||||
it.setStyle(Style.Builder().fromUrl(TEST_STYLE))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +58,9 @@ class MergeOfflineRegionsActivity : AppCompatActivity() {
|
||||
FileSource.getResourcesCachePath(this) + "/" + TEST_DB_FILE_NAME,
|
||||
object : OfflineManager.MergeOfflineRegionsCallback {
|
||||
override fun onMerge(offlineRegions: Array<OfflineRegion>) {
|
||||
mapView.setStyleUrl(TEST_STYLE)
|
||||
mapView.getMapAsync{
|
||||
it.setStyle(Style.Builder().fromUrl(TEST_STYLE))
|
||||
}
|
||||
Toast.makeText(
|
||||
this@MergeOfflineRegionsActivity,
|
||||
String.format("Merged %d regions.", offlineRegions.size),
|
||||
|
||||
@@ -76,12 +76,11 @@ public class OfflineActivity extends AppCompatActivity
|
||||
|
||||
// Set up map
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.setStyleUrl(STYLE_URL);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
Timber.d("Map is ready");
|
||||
OfflineActivity.this.mapboxMap = mapboxMap;
|
||||
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(STYLE_URL));
|
||||
// Set initial position to UNHQ in NYC
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
|
||||
@@ -40,7 +40,7 @@ public class UpdateMetadataActivity extends AppCompatActivity implements Adapter
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_metadata_update);
|
||||
|
||||
ListView listView = (ListView) findViewById(R.id.listView);
|
||||
ListView listView = findViewById(R.id.listView);
|
||||
listView.setAdapter(adapter = new OfflineRegionMetadataAdapter(this));
|
||||
listView.setEmptyView(findViewById(android.R.id.empty));
|
||||
listView.setOnItemClickListener(this);
|
||||
@@ -73,11 +73,11 @@ public class UpdateMetadataActivity extends AppCompatActivity implements Adapter
|
||||
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
ViewGroup container = (ViewGroup) findViewById(R.id.container);
|
||||
ViewGroup container = findViewById(R.id.container);
|
||||
container.removeAllViews();
|
||||
container.addView(mapView = new MapView(view.getContext()));
|
||||
mapView.setOfflineRegionDefinition(adapter.getItem(position).getDefinition());
|
||||
mapView.onCreate(null);
|
||||
mapView.getMapAsync(map -> map.setOfflineRegionDefinition(adapter.getItem(position).getDefinition()));
|
||||
mapView.onStart();
|
||||
mapView.onResume();
|
||||
return true;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class MapSnapshotterActivity extends AppCompatActivity {
|
||||
|
||||
// Find the grid view and start snapshotting as soon
|
||||
// as the view is measured
|
||||
grid = (GridLayout) findViewById(R.id.snapshot_grid);
|
||||
grid = findViewById(R.id.snapshot_grid);
|
||||
grid.getViewTreeObserver()
|
||||
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,7 @@ import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.storage.FileSource;
|
||||
import com.mapbox.mapboxsdk.storage.Resource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
@@ -18,7 +18,6 @@ import timber.log.Timber;
|
||||
public class UrlTransformActivity extends AppCompatActivity {
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
/**
|
||||
* Be sure to use an isolated class so the activity is not leaked when
|
||||
@@ -48,7 +47,7 @@ public class UrlTransformActivity extends AppCompatActivity {
|
||||
|
||||
mapView.getMapAsync(map -> {
|
||||
Timber.i("Map loaded");
|
||||
mapboxMap = map;
|
||||
map.setStyle(Style.MAPBOX_STREETS);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.mapbox.mapboxsdk.geometry.LatLngQuad;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.RasterLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.ImageSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
@@ -52,22 +53,24 @@ public class AnimatedImageSourceActivity extends AppCompatActivity implements On
|
||||
public void onMapReady(@NonNull final MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
|
||||
// add source
|
||||
LatLngQuad quad = new LatLngQuad(
|
||||
map.setStyle(Style.MAPBOX_STREETS, style -> {
|
||||
// add source
|
||||
LatLngQuad quad = new LatLngQuad(
|
||||
new LatLng(46.437, -80.425),
|
||||
new LatLng(46.437, -71.516),
|
||||
new LatLng(37.936, -71.516),
|
||||
new LatLng(37.936, -80.425));
|
||||
mapboxMap.getStyle().addSource(new ImageSource(ID_IMAGE_SOURCE, quad, R.drawable.southeast_radar_0));
|
||||
mapboxMap.getStyle().addSource(new ImageSource(ID_IMAGE_SOURCE, quad, R.drawable.southeast_radar_0));
|
||||
|
||||
// add layer
|
||||
RasterLayer layer = new RasterLayer(ID_IMAGE_LAYER, ID_IMAGE_SOURCE);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
// add layer
|
||||
RasterLayer layer = new RasterLayer(ID_IMAGE_LAYER, ID_IMAGE_SOURCE);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
// loop refresh geojson
|
||||
handler = new Handler();
|
||||
runnable = new RefreshImageRunnable(mapboxMap, handler);
|
||||
handler.postDelayed(runnable, 100);
|
||||
// loop refresh geojson
|
||||
handler = new Handler();
|
||||
runnable = new RefreshImageRunnable(mapboxMap, handler);
|
||||
handler.postDelayed(runnable, 100);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -43,13 +43,14 @@ public class BuildingFillExtrusionActivity extends AppCompatActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_building_layer);
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
Style style = map.getStyle();
|
||||
setupBuildings(style);
|
||||
setupLight();
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
|
||||
setupBuildings(style);
|
||||
setupLight();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -74,18 +74,18 @@ public class CircleLayerActivity extends AppCompatActivity implements View.OnCli
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
addBusStopSource();
|
||||
addBusStopCircleLayer();
|
||||
initFloatingActionButtons();
|
||||
isLoadingStyle = false;
|
||||
|
||||
mapboxMap.setStyle(Style.SATELLITE_STREETS, style -> {
|
||||
addBusStopSource();
|
||||
addBusStopCircleLayer();
|
||||
initFloatingActionButtons();
|
||||
isLoadingStyle = false;
|
||||
});
|
||||
});
|
||||
|
||||
mapView.addOnDidFinishLoadingStyleListener(new MapView.OnDidFinishLoadingStyleListener() {
|
||||
@Override
|
||||
public void onDidFinishLoadingStyle() {
|
||||
addBusStop();
|
||||
isLoadingStyle = false;
|
||||
}
|
||||
mapView.addOnDidFinishLoadingStyleListener(() -> {
|
||||
addBusStop();
|
||||
isLoadingStyle = false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ public class CircleLayerActivity extends AppCompatActivity implements View.OnCli
|
||||
}
|
||||
|
||||
private void loadNewStyle() {
|
||||
mapboxMap.setStyleUrl(getNextStyle());
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(getNextStyle()));
|
||||
}
|
||||
|
||||
private void addBusStop() {
|
||||
|
||||
@@ -47,51 +47,54 @@ public class CustomSpriteActivity extends AppCompatActivity {
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
final FloatingActionButton fab = findViewById(R.id.fab);
|
||||
fab.setColorFilter(ContextCompat.getColor(CustomSpriteActivity.this, R.color.primary));
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
private Point point;
|
||||
map.getStyle(style -> {
|
||||
final FloatingActionButton fab = findViewById(R.id.fab);
|
||||
fab.setColorFilter(ContextCompat.getColor(CustomSpriteActivity.this, R.color.primary));
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (point == null) {
|
||||
Timber.i("First click -> Car");
|
||||
// Add an icon to reference later
|
||||
mapboxMap.getStyle().addImage(CUSTOM_ICON, BitmapFactory.decodeResource(getResources(), R.drawable.ic_car_top));
|
||||
private Point point;
|
||||
|
||||
// Add a source with a geojson point
|
||||
point = Point.fromLngLat(13.400972d, 52.519003d);
|
||||
source = new GeoJsonSource(
|
||||
"point",
|
||||
FeatureCollection.fromFeatures(new Feature[] {Feature.fromGeometry(point)})
|
||||
);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (point == null) {
|
||||
Timber.i("First click -> Car");
|
||||
// Add an icon to reference later
|
||||
style.addImage(CUSTOM_ICON, BitmapFactory.decodeResource(getResources(), R.drawable.ic_car_top));
|
||||
|
||||
// Add a symbol layer that references that point source
|
||||
layer = new SymbolLayer("layer", "point");
|
||||
layer.setProperties(
|
||||
// Set the id of the sprite to use
|
||||
iconImage(CUSTOM_ICON),
|
||||
iconAllowOverlap(true),
|
||||
iconIgnorePlacement(true)
|
||||
);
|
||||
// Add a source with a geojson point
|
||||
point = Point.fromLngLat(13.400972d, 52.519003d);
|
||||
source = new GeoJsonSource(
|
||||
"point",
|
||||
FeatureCollection.fromFeatures(new Feature[] {Feature.fromGeometry(point)})
|
||||
);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
|
||||
// lets add a circle below labels!
|
||||
mapboxMap.getStyle().addLayerBelow(layer, "waterway-label");
|
||||
// Add a symbol layer that references that point source
|
||||
layer = new SymbolLayer("layer", "point");
|
||||
layer.setProperties(
|
||||
// Set the id of the sprite to use
|
||||
iconImage(CUSTOM_ICON),
|
||||
iconAllowOverlap(true),
|
||||
iconIgnorePlacement(true)
|
||||
);
|
||||
|
||||
fab.setImageResource(R.drawable.ic_directions_car_black);
|
||||
} else {
|
||||
// Update point
|
||||
point = Point.fromLngLat(point.longitude() + 0.001,
|
||||
// lets add a circle below labels!
|
||||
mapboxMap.getStyle().addLayerBelow(layer, "waterway-label");
|
||||
|
||||
fab.setImageResource(R.drawable.ic_directions_car_black);
|
||||
} else {
|
||||
// Update point
|
||||
point = Point.fromLngLat(point.longitude() + 0.001,
|
||||
point.latitude() + 0.001);
|
||||
source.setGeoJson(FeatureCollection.fromFeatures(new Feature[] {Feature.fromGeometry(point)}));
|
||||
source.setGeoJson(FeatureCollection.fromFeatures(new Feature[] {Feature.fromGeometry(point)}));
|
||||
|
||||
// Move the camera as well
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(
|
||||
point.latitude(), point.longitude())));
|
||||
// Move the camera as well
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(
|
||||
point.latitude(), point.longitude())));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.FillLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.style.sources.Source;
|
||||
@@ -63,11 +64,13 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
// Store for later
|
||||
mapboxMap = map;
|
||||
|
||||
// Add a parks layer
|
||||
addParksLayer();
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
|
||||
// Add a parks layer
|
||||
addParksLayer();
|
||||
|
||||
// Add debug overlay
|
||||
setupDebugZoomView();
|
||||
// Add debug overlay
|
||||
setupDebugZoomView();
|
||||
});
|
||||
|
||||
// Center and Zoom (Amsterdam, zoomed to streets)
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(52.379189, 4.899431), 14));
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import com.mapbox.mapboxsdk.maps.MapView
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.style.layers.PropertyFactory.*
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
|
||||
@@ -67,12 +68,13 @@ class DraggableMarkerActivity : AppCompatActivity() {
|
||||
mapView.getMapAsync { mapboxMap ->
|
||||
this.mapboxMap = mapboxMap
|
||||
|
||||
val style = mapboxMap.style
|
||||
|
||||
// Setting up markers icon, source and layer
|
||||
mapboxMap.getStyle().addImage(markerImageId, IconFactory.getInstance(this).defaultMarker().bitmap)
|
||||
style.addSource(source)
|
||||
style.addLayer(layer)
|
||||
mapboxMap.setStyle(
|
||||
Style.Builder()
|
||||
.fromUrl(Style.MAPBOX_STREETS)
|
||||
.withImage(markerImageId, IconFactory.getInstance(this).defaultMarker().bitmap)
|
||||
.withSource(source)
|
||||
.withLayer(layer)
|
||||
)
|
||||
|
||||
// Add initial markers
|
||||
addMarker(LatLng(52.407210, 16.924324))
|
||||
|
||||
@@ -9,13 +9,14 @@ import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.geojson.Polygon;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionColor;
|
||||
@@ -28,51 +29,50 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionOpa
|
||||
public class FillExtrusionActivity extends AppCompatActivity {
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_fill_extrusion_layer);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
List<List<Point>> lngLats = Arrays.asList(
|
||||
Arrays.asList(
|
||||
Point.fromLngLat(5.12112557888031, 52.09071040847704),
|
||||
Point.fromLngLat(5.121227502822875, 52.09053901776669),
|
||||
Point.fromLngLat(5.121484994888306, 52.090601641371805),
|
||||
Point.fromLngLat(5.1213884353637695, 52.090766439912635),
|
||||
Point.fromLngLat(5.12112557888031, 52.09071040847704)
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
|
||||
List<List<Point>> lngLats = Collections.singletonList(
|
||||
Arrays.asList(
|
||||
Point.fromLngLat(5.12112557888031, 52.09071040847704),
|
||||
Point.fromLngLat(5.121227502822875, 52.09053901776669),
|
||||
Point.fromLngLat(5.121484994888306, 52.090601641371805),
|
||||
Point.fromLngLat(5.1213884353637695, 52.090766439912635),
|
||||
Point.fromLngLat(5.12112557888031, 52.09071040847704)
|
||||
)
|
||||
);
|
||||
);
|
||||
|
||||
Polygon domTower = Polygon.fromLngLats(lngLats);
|
||||
Polygon domTower = Polygon.fromLngLats(lngLats);
|
||||
GeoJsonSource source = new GeoJsonSource("extrusion-source", domTower);
|
||||
style.addSource(source);
|
||||
|
||||
GeoJsonSource source = new GeoJsonSource("extrusion-source", domTower);
|
||||
map.getStyle().addSource(source);
|
||||
style.addLayer(
|
||||
new FillExtrusionLayer("extrusion-layer", source.getId())
|
||||
.withProperties(
|
||||
fillExtrusionHeight(40f),
|
||||
fillExtrusionOpacity(0.5f),
|
||||
fillExtrusionColor(Color.RED)
|
||||
)
|
||||
);
|
||||
|
||||
mapboxMap.getStyle().addLayer(
|
||||
new FillExtrusionLayer("extrusion-layer", source.getId())
|
||||
.withProperties(
|
||||
fillExtrusionHeight(40f),
|
||||
fillExtrusionOpacity(0.5f),
|
||||
fillExtrusionColor(Color.RED)
|
||||
)
|
||||
);
|
||||
|
||||
mapboxMap.animateCamera(
|
||||
CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
.target(new LatLng(52.09071040847704, 5.12112557888031))
|
||||
.tilt(45.0)
|
||||
.zoom(18)
|
||||
.build()
|
||||
),
|
||||
10000
|
||||
);
|
||||
mapboxMap.animateCamera(
|
||||
CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
.target(new LatLng(52.09071040847704, 5.12112557888031))
|
||||
.tilt(45.0)
|
||||
.zoom(18)
|
||||
.build()
|
||||
),
|
||||
10000
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
|
||||
@@ -66,13 +67,19 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(37.7749, 122.4194), 0));
|
||||
mapboxMap.getStyle().addImage(
|
||||
"icon-id",
|
||||
BitmapUtils.getBitmapFromDrawable(getResources().getDrawable(R.drawable.ic_hearing_black_24dp)),
|
||||
true
|
||||
);
|
||||
// Add a clustered source with some layers
|
||||
addClusteredGeoJsonSource();
|
||||
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
|
||||
@Override
|
||||
public void onStyleLoaded(Style style) {
|
||||
style.addImage(
|
||||
"icon-id",
|
||||
BitmapUtils.getBitmapFromDrawable(getResources().getDrawable(R.drawable.ic_hearing_black_24dp)),
|
||||
true
|
||||
);
|
||||
// Add a clustered source with some layers
|
||||
addClusteredGeoJsonSource(style);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -129,10 +136,10 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private void addClusteredGeoJsonSource() {
|
||||
private void addClusteredGeoJsonSource(Style style) {
|
||||
// Add a clustered source
|
||||
try {
|
||||
mapboxMap.getStyle().addSource(
|
||||
style.addSource(
|
||||
new GeoJsonSource("earthquakes",
|
||||
new URL("https://www.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson"),
|
||||
new GeoJsonOptions()
|
||||
@@ -169,7 +176,7 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
)
|
||||
);
|
||||
unclustered.setFilter(has("mag"));
|
||||
mapboxMap.getStyle().addLayer(unclustered);
|
||||
style.addLayer(unclustered);
|
||||
|
||||
for (int i = 0; i < layers.length; i++) {
|
||||
// Add some nice circles
|
||||
@@ -189,7 +196,7 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
lt(pointCount, literal(layers[i - 1][0]))
|
||||
)
|
||||
);
|
||||
mapboxMap.getStyle().addLayer(circles);
|
||||
style.addLayer(circles);
|
||||
}
|
||||
|
||||
// Add the count labels
|
||||
@@ -201,7 +208,7 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
textIgnorePlacement(true),
|
||||
textAllowOverlap(true)
|
||||
);
|
||||
mapboxMap.getStyle().addLayer(count);
|
||||
style.addLayer(count);
|
||||
|
||||
|
||||
// Zoom out to start
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.LineLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
@@ -35,7 +36,6 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineWidth;
|
||||
public class GradientLineActivity extends AppCompatActivity implements OnMapReadyCallback {
|
||||
|
||||
public static final String LINE_SOURCE = "gradient";
|
||||
private MapboxMap mapboxMap;
|
||||
private MapView mapView;
|
||||
|
||||
@Override
|
||||
@@ -49,25 +49,25 @@ public class GradientLineActivity extends AppCompatActivity implements OnMapRead
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap map) {
|
||||
this.mapboxMap = map;
|
||||
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
try {
|
||||
String geoJson = ResourceUtils.readRawResource(GradientLineActivity.this, R.raw.test_line_gradient_feature);
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource(LINE_SOURCE, geoJson, new GeoJsonOptions().withLineMetrics(true)));
|
||||
mapboxMap.getStyle().addLayer(new LineLayer("gradient", LINE_SOURCE)
|
||||
.withProperties(
|
||||
lineGradient(interpolate(
|
||||
linear(), lineProgress(),
|
||||
stop(0f, rgb(0, 0, 255)),
|
||||
stop(0.5f, rgb(0, 255, 0)),
|
||||
stop(1f, rgb(255, 0, 0)))
|
||||
),
|
||||
lineColor(Color.RED),
|
||||
lineWidth(10.0f),
|
||||
lineCap(LINE_CAP_ROUND),
|
||||
lineJoin(LINE_JOIN_ROUND)
|
||||
)
|
||||
mapboxMap.setStyle(new Style.Builder()
|
||||
.fromJson(geoJson)
|
||||
.withSource(new GeoJsonSource(LINE_SOURCE, geoJson, new GeoJsonOptions().withLineMetrics(true)))
|
||||
.withLayer(new LineLayer("gradient", LINE_SOURCE)
|
||||
.withProperties(
|
||||
lineGradient(interpolate(
|
||||
linear(), lineProgress(),
|
||||
stop(0f, rgb(0, 0, 255)),
|
||||
stop(0.5f, rgb(0, 255, 0)),
|
||||
stop(1f, rgb(255, 0, 0)))
|
||||
),
|
||||
lineColor(Color.RED),
|
||||
lineWidth(10.0f),
|
||||
lineCap(LINE_CAP_ROUND),
|
||||
lineJoin(LINE_JOIN_ROUND)
|
||||
))
|
||||
);
|
||||
} catch (IOException exception) {
|
||||
Timber.e(exception);
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.LineLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.CustomGeometrySource;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeometryTileProvider;
|
||||
@@ -34,7 +35,6 @@ public class GridSourceActivity extends AppCompatActivity implements OnMapReadyC
|
||||
public static final String ID_GRID_LAYER = "grid_layer";
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
// public for testing purposes
|
||||
public CustomGeometrySource source;
|
||||
@@ -102,19 +102,17 @@ public class GridSourceActivity extends AppCompatActivity implements OnMapReadyC
|
||||
|
||||
@Override
|
||||
public void onMapReady(@NonNull final MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
|
||||
// add source
|
||||
source = new CustomGeometrySource(ID_GRID_SOURCE, new GridProvider());
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
|
||||
// add layer
|
||||
layer = new LineLayer(ID_GRID_LAYER, ID_GRID_SOURCE);
|
||||
layer.setProperties(
|
||||
lineColor(Color.parseColor("#000000"))
|
||||
);
|
||||
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
map.setStyle(new Style.Builder()
|
||||
.fromUrl(Style.MAPBOX_STREETS)
|
||||
.withLayer(layer)
|
||||
.withSource(source)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.HeatmapLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
@@ -53,13 +54,16 @@ public class HeatmapLayerActivity extends AppCompatActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_heatmaplayer);
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
addEarthquakeSource();
|
||||
addHeatmapLayer();
|
||||
addCircleLayer();
|
||||
|
||||
mapboxMap.setStyle(Style.DARK, style -> {
|
||||
addEarthquakeSource();
|
||||
addHeatmapLayer();
|
||||
addCircleLayer();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.HillshadeLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.RasterDemSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
@@ -33,10 +34,12 @@ public class HillshadeLayerActivity extends AppCompatActivity {
|
||||
mapboxMap = map;
|
||||
|
||||
RasterDemSource rasterDemSource = new RasterDemSource(SOURCE_ID, SOURCE_URL);
|
||||
mapboxMap.getStyle().addSource(rasterDemSource);
|
||||
|
||||
HillshadeLayer hillshadeLayer = new HillshadeLayer(LAYER_ID, SOURCE_ID);
|
||||
mapboxMap.getStyle().addLayerBelow(hillshadeLayer, LAYER_BELOW_ID);
|
||||
mapboxMap.setStyle(new Style.Builder()
|
||||
.fromUrl(Style.MAPBOX_STREETS)
|
||||
.withLayer(hillshadeLayer)
|
||||
.withSource(rasterDemSource)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
@@ -51,22 +52,27 @@ public class RealTimeGeoJsonActivity extends AppCompatActivity implements OnMapR
|
||||
public void onMapReady(@NonNull final MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
|
||||
// add source
|
||||
try {
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource(ID_GEOJSON_SOURCE, new URL(URL_GEOJSON_SOURCE)));
|
||||
} catch (MalformedURLException malformedUrlException) {
|
||||
Timber.e(malformedUrlException, "Invalid URL");
|
||||
}
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
|
||||
@Override
|
||||
public void onStyleLoaded(Style style) {
|
||||
// add source
|
||||
try {
|
||||
style.addSource(new GeoJsonSource(ID_GEOJSON_SOURCE, new URL(URL_GEOJSON_SOURCE)));
|
||||
} catch (MalformedURLException malformedUrlException) {
|
||||
Timber.e(malformedUrlException, "Invalid URL");
|
||||
}
|
||||
|
||||
// add layer
|
||||
SymbolLayer layer = new SymbolLayer(ID_GEOJSON_LAYER, ID_GEOJSON_SOURCE);
|
||||
layer.setProperties(iconImage("rocket-15"));
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
// add layer
|
||||
SymbolLayer layer = new SymbolLayer(ID_GEOJSON_LAYER, ID_GEOJSON_SOURCE);
|
||||
layer.setProperties(iconImage("rocket-15"));
|
||||
style.addLayer(layer);
|
||||
|
||||
// loop refresh geojson
|
||||
handler = new Handler();
|
||||
runnable = new RefreshGeoJsonRunnable(mapboxMap, handler);
|
||||
handler.postDelayed(runnable, 2000);
|
||||
// loop refresh geojson
|
||||
handler = new Handler();
|
||||
runnable = new RefreshGeoJsonRunnable(mapboxMap, handler);
|
||||
handler.postDelayed(runnable, 2000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,13 +7,13 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.FeatureCollection;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.FillLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
@@ -30,14 +30,13 @@ import com.mapbox.mapboxsdk.style.sources.TileSet;
|
||||
import com.mapbox.mapboxsdk.style.sources.VectorSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
|
||||
import timber.log.Timber;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.all;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.color;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.eq;
|
||||
@@ -75,6 +74,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
private boolean styleLoaded;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -82,10 +82,9 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
setContentView(R.layout.activity_runtime_style);
|
||||
|
||||
// Initialize map as normal
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
|
||||
|
||||
mapView.getMapAsync(map -> {
|
||||
// Store for later
|
||||
mapboxMap = map;
|
||||
@@ -93,8 +92,12 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
// Center and Zoom (Amsterdam, zoomed to streets)
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(52.379189, 4.899431), 14));
|
||||
|
||||
// set custom transition
|
||||
mapboxMap.getStyle().setTransition(new TransitionOptions(250, 50));
|
||||
mapboxMap.setStyle(
|
||||
new Style.Builder()
|
||||
.fromUrl(Style.MAPBOX_STREETS)
|
||||
// set custom transition
|
||||
.withTransition(new TransitionOptions(250, 50)), style -> styleLoaded = true
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -148,6 +151,10 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (!styleLoaded) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_list_layers:
|
||||
listLayers();
|
||||
@@ -490,7 +497,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void styleFillFilterLayer() {
|
||||
mapboxMap.setStyleUrl("asset://fill_filter_style.json");
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl("asset://fill_filter_style.json"));
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(31, -100), 3));
|
||||
|
||||
Handler handler = new Handler(getMainLooper());
|
||||
@@ -518,7 +525,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void styleLineFilterLayer() {
|
||||
mapboxMap.setStyleUrl("asset://line_filter_style.json");
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl("asset://line_filter_style.json"));
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40, -97), 5));
|
||||
|
||||
Handler handler = new Handler(getMainLooper());
|
||||
@@ -546,7 +553,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void styleNumericFillLayer() {
|
||||
mapboxMap.setStyleUrl("asset://numeric_filter_style.json");
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl("asset://numeric_filter_style.json"));
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40, -97), 5));
|
||||
|
||||
Handler handler = new Handler(getMainLooper());
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.VectorSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
@@ -33,8 +34,6 @@ public class RuntimeStyleTimingTestActivity extends AppCompatActivity {
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
RuntimeStyleTimingTestActivity.this.mapboxMap = mapboxMap;
|
||||
VectorSource museums = new VectorSource("museums_source", "mapbox://mapbox.2opop9hr");
|
||||
mapboxMap.getStyle().addSource(museums);
|
||||
|
||||
CircleLayer museumsLayer = new CircleLayer("museums", "museums_source");
|
||||
museumsLayer.setSourceLayer("museum-cusco");
|
||||
@@ -44,7 +43,11 @@ public class RuntimeStyleTimingTestActivity extends AppCompatActivity {
|
||||
circleColor(Color.argb(1, 55, 148, 179))
|
||||
);
|
||||
|
||||
mapboxMap.getStyle().addLayer(museumsLayer);
|
||||
VectorSource museums = new VectorSource("museums_source", "mapbox://mapbox.2opop9hr");
|
||||
mapboxMap.setStyle(new Style.Builder()
|
||||
.fromUrl(Style.MAPBOX_STREETS)
|
||||
.withSource(museums)
|
||||
.withLayer(museumsLayer));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.widget.Toast;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
|
||||
|
||||
@@ -78,7 +79,7 @@ public class StyleFileActivity extends AppCompatActivity {
|
||||
Timber.d("Read json, %s", json);
|
||||
MapboxMap mapboxMap = this.mapboxMap.get();
|
||||
if (mapboxMap != null) {
|
||||
mapboxMap.setStyleJson(json);
|
||||
mapboxMap.setStyle(new Style.Builder().fromJson(json));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,7 +117,7 @@ public class StyleFileActivity extends AppCompatActivity {
|
||||
// Actual file:// usage
|
||||
MapboxMap mapboxMap = this.mapboxMap.get();
|
||||
if (mapboxMap != null) {
|
||||
mapboxMap.setStyleUrl("file://" + cacheStyleFile.getAbsolutePath());
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl("file://" + cacheStyleFile.getAbsolutePath()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.Property;
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
@@ -72,6 +73,7 @@ public class SymbolLayerActivity extends AppCompatActivity implements MapboxMap.
|
||||
private MapboxMap mapboxMap;
|
||||
private MapView mapView;
|
||||
private boolean initialFont;
|
||||
private boolean styleLoaded;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -85,7 +87,6 @@ public class SymbolLayerActivity extends AppCompatActivity implements MapboxMap.
|
||||
.zoom(13)
|
||||
.build()
|
||||
);
|
||||
mapboxMapOptions.styleUrl("asset://streets.json");
|
||||
|
||||
// Create map programmatically, add to view hierarchy
|
||||
mapView = new MapView(this, mapboxMapOptions);
|
||||
@@ -97,50 +98,50 @@ public class SymbolLayerActivity extends AppCompatActivity implements MapboxMap.
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
this.mapboxMap = mapboxMap;
|
||||
|
||||
// Add a sdf image for the makers
|
||||
// image
|
||||
Drawable icLayersDrawable = getResources().getDrawable(R.drawable.ic_layers);
|
||||
Bitmap icLayersBitmap = BitmapUtils.getBitmapFromDrawable(icLayersDrawable);
|
||||
mapboxMap.getStyle().addImage(
|
||||
MARKER_ICON,
|
||||
icLayersBitmap,
|
||||
true
|
||||
);
|
||||
|
||||
// Add a source
|
||||
// source
|
||||
markerCollection = FeatureCollection.fromFeatures(new Feature[] {
|
||||
Feature.fromGeometry(Point.fromLngLat(4.91638, 52.35673), featureProperties("Marker 1")),
|
||||
Feature.fromGeometry(Point.fromLngLat(4.91638, 52.34673), featureProperties("Marker 2"))
|
||||
});
|
||||
mapboxMap.getStyle().addSource(geoJsonSource = new GeoJsonSource(MARKER_SOURCE, markerCollection));
|
||||
geoJsonSource = new GeoJsonSource(MARKER_SOURCE, markerCollection);
|
||||
|
||||
// Add the symbol-layer
|
||||
mapboxMap.getStyle().addLayer(
|
||||
new SymbolLayer(MARKER_LAYER, MARKER_SOURCE)
|
||||
.withProperties(
|
||||
iconImage(MARKER_ICON),
|
||||
iconIgnorePlacement(true),
|
||||
iconAllowOverlap(true),
|
||||
iconSize(switchCase(toBool(get(SELECTED_FEATURE_PROPERTY)), literal(3.0f), literal(1.0f))),
|
||||
iconAnchor(Property.ICON_ANCHOR_BOTTOM),
|
||||
iconColor(Color.RED),
|
||||
textField(
|
||||
format(
|
||||
formatEntry("this is", formatFontScale(0.75)),
|
||||
formatEntry(
|
||||
concat(literal("\n"), get(TITLE_FEATURE_PROPERTY)),
|
||||
formatFontScale(1.25),
|
||||
formatTextFont(new String[] {"DIN Offc Pro Bold", "Arial Unicode MS Regular"})
|
||||
)
|
||||
// layer
|
||||
SymbolLayer layer = new SymbolLayer(MARKER_LAYER, MARKER_SOURCE)
|
||||
.withProperties(
|
||||
iconImage(MARKER_ICON),
|
||||
iconIgnorePlacement(true),
|
||||
iconAllowOverlap(true),
|
||||
iconSize(switchCase(toBool(get(SELECTED_FEATURE_PROPERTY)), literal(3.0f), literal(1.0f))),
|
||||
iconAnchor(Property.ICON_ANCHOR_BOTTOM),
|
||||
iconColor(Color.RED),
|
||||
textField(
|
||||
format(
|
||||
formatEntry("this is", formatFontScale(0.75)),
|
||||
formatEntry(
|
||||
concat(literal("\n"), get(TITLE_FEATURE_PROPERTY)),
|
||||
formatFontScale(1.25),
|
||||
formatTextFont(new String[] {"DIN Offc Pro Bold", "Arial Unicode MS Regular"})
|
||||
)
|
||||
),
|
||||
textFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"}),
|
||||
textColor(Color.RED),
|
||||
textAllowOverlap(true),
|
||||
textIgnorePlacement(true),
|
||||
textAnchor(Property.TEXT_ANCHOR_TOP),
|
||||
textSize(10f)
|
||||
)
|
||||
)
|
||||
),
|
||||
textFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"}),
|
||||
textColor(Color.RED),
|
||||
textAllowOverlap(true),
|
||||
textIgnorePlacement(true),
|
||||
textAnchor(Property.TEXT_ANCHOR_TOP),
|
||||
textSize(10f)
|
||||
);
|
||||
|
||||
mapboxMap.setStyle(new Style.Builder()
|
||||
.fromUrl("asset://streets.json")
|
||||
.withImage(MARKER_ICON, icLayersBitmap)
|
||||
.withSource(geoJsonSource)
|
||||
.withLayer(layer),
|
||||
style -> styleLoaded = true
|
||||
);
|
||||
|
||||
// Set a click-listener so we can manipulate the map
|
||||
@@ -246,6 +247,10 @@ public class SymbolLayerActivity extends AppCompatActivity implements MapboxMap.
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (!styleLoaded) {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_toggle_text_size:
|
||||
toggleTextSize();
|
||||
|
||||
@@ -76,14 +76,16 @@ public class ZoomFunctionSymbolLayerActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_zoom_symbol_layer);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
Style style = map.getStyle();
|
||||
updateSource(style);
|
||||
addLayer(style);
|
||||
map.addOnMapClickListener(mapClickListener);
|
||||
|
||||
map.setStyle(Style.MAPBOX_STREETS, style -> {
|
||||
updateSource(style);
|
||||
addLayer(style);
|
||||
map.addOnMapClickListener(mapClickListener);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import java.util.Locale;
|
||||
@@ -58,6 +59,8 @@ public class TextureViewAnimationActivity extends AppCompatActivity {
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
TextureViewAnimationActivity.this.mapboxMap = mapboxMap;
|
||||
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
|
||||
setFpsView(mapboxMap);
|
||||
|
||||
// Animate the map view
|
||||
|
||||
@@ -1,290 +1,18 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.textureview;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.layers.Property;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.maplayout.DebugModeActivity;
|
||||
|
||||
/**
|
||||
* Test activity showcasing the different debug modes and allows to cycle between the default map styles.
|
||||
*/
|
||||
public class TextureViewDebugModeActivity extends AppCompatActivity implements OnMapReadyCallback {
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
private ActionBarDrawerToggle actionBarDrawerToggle;
|
||||
private int currentStyleIndex = 0;
|
||||
private IdleListener idleListener;
|
||||
|
||||
private static final String[] STYLES = new String[] {
|
||||
Style.MAPBOX_STREETS,
|
||||
Style.OUTDOORS,
|
||||
Style.LIGHT,
|
||||
Style.DARK,
|
||||
Style.SATELLITE,
|
||||
Style.SATELLITE_STREETS,
|
||||
Style.TRAFFIC_DAY,
|
||||
Style.TRAFFIC_NIGHT
|
||||
};
|
||||
public class TextureViewDebugModeActivity extends DebugModeActivity implements OnMapReadyCallback {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_textureview_debug_mode);
|
||||
setupToolbar();
|
||||
setupMapView(savedInstanceState);
|
||||
setupDebugChangeView();
|
||||
setupStyleChangeView();
|
||||
}
|
||||
|
||||
private void setupToolbar() {
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setHomeButtonEnabled(true);
|
||||
|
||||
DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
|
||||
actionBarDrawerToggle = new ActionBarDrawerToggle(this,
|
||||
drawerLayout,
|
||||
R.string.navigation_drawer_open,
|
||||
R.string.navigation_drawer_close
|
||||
);
|
||||
actionBarDrawerToggle.setDrawerIndicatorEnabled(true);
|
||||
actionBarDrawerToggle.syncState();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupMapView(Bundle savedInstanceState) {
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
|
||||
mapView.addOnDidFinishLoadingStyleListener(() -> {
|
||||
if (mapboxMap != null) {
|
||||
setupNavigationView(mapboxMap.getStyle().getLayers());
|
||||
}
|
||||
});
|
||||
|
||||
mapView.setTag(true);
|
||||
mapView.setStyleUrl(STYLES[currentStyleIndex]);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
|
||||
setupNavigationView(mapboxMap.getStyle().getLayers());
|
||||
setupZoomView();
|
||||
setFpsView();
|
||||
}
|
||||
|
||||
private void setFpsView() {
|
||||
final TextView fpsView = findViewById(R.id.fpsView);
|
||||
mapboxMap.setOnFpsChangedListener(fps -> fpsView.setText(String.format(Locale.US, "FPS: %4.2f", fps)));
|
||||
}
|
||||
|
||||
private void setupNavigationView(List<Layer> layerList) {
|
||||
Timber.v("New style loaded with JSON: %s", mapboxMap.getStyleJson());
|
||||
final LayerListAdapter adapter = new LayerListAdapter(this, layerList);
|
||||
ListView listView = findViewById(R.id.listView);
|
||||
listView.setAdapter(adapter);
|
||||
listView.setOnItemClickListener((parent, view, position, id) -> {
|
||||
Layer clickedLayer = adapter.getItem(position);
|
||||
toggleLayerVisibility(clickedLayer);
|
||||
closeNavigationView();
|
||||
});
|
||||
}
|
||||
|
||||
private void toggleLayerVisibility(Layer layer) {
|
||||
boolean isVisible = layer.getVisibility().getValue().equals(Property.VISIBLE);
|
||||
layer.setProperties(
|
||||
visibility(
|
||||
isVisible ? Property.NONE : Property.VISIBLE
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private void closeNavigationView() {
|
||||
DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
|
||||
drawerLayout.closeDrawers();
|
||||
}
|
||||
|
||||
private void setupZoomView() {
|
||||
final TextView textView = findViewById(R.id.textZoom);
|
||||
mapboxMap.addOnCameraIdleListener(idleListener = new IdleListener(mapboxMap, textView));
|
||||
}
|
||||
|
||||
private void setupDebugChangeView() {
|
||||
FloatingActionButton fabDebug = findViewById(R.id.fabDebug);
|
||||
fabDebug.setOnClickListener(view -> {
|
||||
if (mapboxMap != null) {
|
||||
Timber.d("Debug FAB: isDebug Active? %s", mapboxMap.isDebugActive());
|
||||
mapboxMap.cycleDebugOptions();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupStyleChangeView() {
|
||||
mapView.addOnDidFinishLoadingStyleListener(() -> Timber.d("Style loaded"));
|
||||
|
||||
FloatingActionButton fabStyles = findViewById(R.id.fabStyles);
|
||||
fabStyles.setOnClickListener(view -> {
|
||||
if (mapboxMap != null) {
|
||||
currentStyleIndex++;
|
||||
if (currentStyleIndex == STYLES.length) {
|
||||
currentStyleIndex = 0;
|
||||
}
|
||||
mapboxMap.setStyleUrl(STYLES[currentStyleIndex]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
return actionBarDrawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mapView.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
mapView.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mapboxMap != null && idleListener != null) {
|
||||
mapboxMap.removeOnCameraIdleListener(idleListener);
|
||||
}
|
||||
mapView.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
private static class LayerListAdapter extends BaseAdapter {
|
||||
|
||||
private LayoutInflater layoutInflater;
|
||||
private List<Layer> layers;
|
||||
|
||||
LayerListAdapter(Context context, List<Layer> layers) {
|
||||
this.layoutInflater = LayoutInflater.from(context);
|
||||
this.layers = layers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return layers.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Layer getItem(int position) {
|
||||
return layers.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
Layer layer = layers.get(position);
|
||||
View view = convertView;
|
||||
if (view == null) {
|
||||
view = layoutInflater.inflate(android.R.layout.simple_list_item_2, parent, false);
|
||||
ViewHolder holder = new ViewHolder(
|
||||
view.findViewById(android.R.id.text1),
|
||||
view.findViewById(android.R.id.text2)
|
||||
);
|
||||
view.setTag(holder);
|
||||
}
|
||||
ViewHolder holder = (ViewHolder) view.getTag();
|
||||
holder.text.setText(layer.getClass().getSimpleName());
|
||||
holder.subText.setText(layer.getId());
|
||||
return view;
|
||||
}
|
||||
|
||||
private static class ViewHolder {
|
||||
final TextView text;
|
||||
final TextView subText;
|
||||
|
||||
ViewHolder(TextView text, TextView subText) {
|
||||
this.text = text;
|
||||
this.subText = subText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class IdleListener implements MapboxMap.OnCameraIdleListener {
|
||||
|
||||
private MapboxMap mapboxMap;
|
||||
private TextView textView;
|
||||
|
||||
IdleListener(MapboxMap mapboxMap, TextView textView) {
|
||||
this.mapboxMap = mapboxMap;
|
||||
this.textView = textView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraIdle() {
|
||||
Context context = textView.getContext();
|
||||
CameraPosition position = mapboxMap.getCameraPosition();
|
||||
textView.setText(String.format(context.getString(R.string.debug_zoom), position.zoom));
|
||||
}
|
||||
protected MapboxMapOptions setupMapboxMapOptions() {
|
||||
MapboxMapOptions mapboxMapOptions = super.setupMapboxMapOptions();
|
||||
mapboxMapOptions.textureMode(true);
|
||||
return mapboxMapOptions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.view.View;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
/**
|
||||
@@ -17,7 +18,6 @@ import com.mapbox.mapboxsdk.testapp.R;
|
||||
public class TextureViewResizeActivity extends AppCompatActivity {
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -37,12 +37,17 @@ public class TextureViewResizeActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void setupMapView(Bundle savedInstanceState) {
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.getMapAsync(mapboxMap -> TextureViewResizeActivity.this.mapboxMap = mapboxMap);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(this::setupMap);
|
||||
}
|
||||
|
||||
private void setupMap(MapboxMap mapboxMap) {
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
}
|
||||
|
||||
private void setupFab() {
|
||||
FloatingActionButton fabDebug = (FloatingActionButton) findViewById(R.id.fabResize);
|
||||
FloatingActionButton fabDebug = findViewById(R.id.fabResize);
|
||||
fabDebug.setOnClickListener(view -> {
|
||||
if (mapView != null) {
|
||||
View parent = findViewById(R.id.coordinator_layout);
|
||||
|
||||
@@ -16,14 +16,6 @@
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@+id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:mapbox_uiAttribution="false"
|
||||
app:mapbox_uiCompass="false"
|
||||
app:mapbox_uiLogo="false"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textZoom"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
app:mapbox_cameraTargetLng="7.497989"
|
||||
app:mapbox_cameraZoom="9"
|
||||
app:mapbox_cameraBearing="140"
|
||||
app:mapbox_cameraTilt="60"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"/>
|
||||
app:mapbox_cameraTilt="60"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -7,5 +7,4 @@
|
||||
android:layout_height="match_parent"
|
||||
app:mapbox_cameraTargetLat="45.38301927899065"
|
||||
app:mapbox_cameraTargetLng="8.63525390625"
|
||||
app:mapbox_cameraZoom="7"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"/>
|
||||
app:mapbox_cameraZoom="7"/>
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_dark"/>
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
android:id="@id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"
|
||||
app:mapbox_localIdeographFontFamily="Droid Sans" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"
|
||||
app:mapbox_uiAttribution="false" />
|
||||
|
||||
<LinearLayout
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<View
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/viewParent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context=".activity.maplayout.SimpleMapActivity">
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/viewParent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context=".activity.maplayout.SimpleMapActivity">
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"
|
||||
android:visibility="invisible"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
android:layout_gravity="end|bottom"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@drawable/ic_print"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"
|
||||
app:backgroundTint="@color/accent"/>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
android:layout_height="match_parent"
|
||||
app:mapbox_cameraTargetLat="52.0907"
|
||||
app:mapbox_cameraTargetLng="5.1214"
|
||||
app:mapbox_cameraZoom="16"/>
|
||||
app:mapbox_cameraZoom="16"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
Reference in New Issue
Block a user