[android] #3145 - MapboxMap

This commit is contained in:
Tobrun
2016-01-11 11:32:00 +01:00
parent 710398b780
commit 8ed1dc9f74
87 changed files with 4587 additions and 3037 deletions

View File

@@ -23,6 +23,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MapboxMapActivity"
android:label="@string/action_mapboxmap" />
<activity
android:name=".VisibleCoordinateBoundsActivity"
android:label="@string/activity_visible_coordinate_bounds" />
@@ -54,6 +56,9 @@
<activity
android:name=".ManualZoomActivity"
android:label="@string/action_manual_zoom" />
<activity
android:name=".MaxMinZoomActivity"
android:label="@string/action_minmax_zoom" />
<activity
android:name=".MyLocationTrackingModeActivity"
android:label="@string/activity_user_tracking_mode" />

View File

@@ -4,6 +4,7 @@ import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
@@ -14,25 +15,26 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngZoom;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.utils.GeoParseUtil;
import com.mapbox.mapboxsdk.testapp.utils.TimingLogger;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
import org.json.JSONException;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
public class BulkMarkerActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
private MapboxMap mMapboxMap;
private MapView mMapView;
@Override
@@ -43,7 +45,7 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
@@ -53,25 +55,36 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
mMapView.setLatLng(new LatLngZoom(38.87031, -77.00897, 10));
mMapView.setCompassEnabled(false);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.target(new LatLng(38.87031, -77.00897))
.zoom(10)
.build()
));
ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(actionBar.getThemedContext(), R.array.bulk_marker_list, android.R.layout.simple_spinner_item);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setAdapter(spinnerAdapter);
spinner.setOnItemSelectedListener(BulkMarkerActivity.this);
}
});
ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(actionBar.getThemedContext(), R.array.bulk_marker_list, android.R.layout.simple_spinner_item);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setAdapter(spinnerAdapter);
spinner.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
int markersAmount = Integer.valueOf(getResources().getStringArray(R.array.bulk_marker_list)[position]);
new LoadBulkMarkerTask(mMapView, markersAmount).execute();
new LoadBulkMarkerTask(this, mMapboxMap, markersAmount).execute();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// nothing selected, nothing to do!
}
@Override
@@ -130,15 +143,14 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
private static class LoadBulkMarkerTask extends AsyncTask<Void, Integer, List<MarkerOptions>> {
private static final String TAG = "LoadBulkMarkerTask";
private WeakReference<MapView> mMapView;
private MapboxMap mMapboxMap;
private Context mAppContext;
private ProgressDialog mProgressDialog;
private int mAmount;
public LoadBulkMarkerTask(MapView mapView, int amount) {
Context context = mapView.getContext();
mapView.removeAllAnnotations();
mMapView = new WeakReference<>(mapView);
public LoadBulkMarkerTask(Context context, MapboxMap mapboxMap, int amount) {
mMapboxMap = mapboxMap;
mapboxMap.removeAllAnnotations();
mProgressDialog = ProgressDialog.show(context, "Loading", "Fetching markers", false);
mAppContext = context.getApplicationContext();
mAmount = amount;
@@ -146,23 +158,12 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
@Override
protected List<MarkerOptions> doInBackground(Void... params) {
//Debug.startMethodTracing("bulk-marker");
TimingLogger timings = new TimingLogger(TAG, "doInBackground");
//Log.d(TAG, "isLoggable " + Log.isLoggable(TAG, Log.VERBOSE));
List<MarkerOptions> markerOptions = new ArrayList<>(mAmount);
timings.addSplit("create ArrayList");
try {
DecimalFormat formatter = new DecimalFormat("#.#####");
String json = GeoParseUtil.loadStringFromAssets(mAppContext, "points.geojson");
timings.addSplit("loadStringFromAssets");
List<LatLng> locations = GeoParseUtil.parseGeoJSONCoordinates(json);
timings.addSplit("parseGeoJSONCoordinates");
if (locations.size() < mAmount) {
mAmount = locations.size();
}
@@ -170,19 +171,15 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
LatLng location;
for (int i = 0; i < mAmount; i++) {
location = locations.get(i);
Log.v(TAG, "marker " + i + " of " + mAmount + " added with " + location.getLatitude() + " " + location.getLongitude());
markerOptions.add(new MarkerOptions()
.position(location)
.title("Marker")
.snippet(formatter.format(location.getLatitude()) + ", " + formatter.format(location.getLongitude())));
}
timings.addSplit("create all MarkerOptions");
} catch (IOException | JSONException e) {
Log.e(TAG, "Could not add markers,", e);
}
timings.dumpToLog();
return markerOptions;
}
@@ -194,18 +191,8 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
@Override
protected void onPostExecute(List<MarkerOptions> markerOptions) {
super.onPostExecute(markerOptions);
TimingLogger timings = new TimingLogger(TAG, "onPostExecute");
MapView mapView = mMapView.get();
if (mapView != null) {
List<Marker> markers = mapView.addMarkers(markerOptions);
Log.v(TAG, "Markers added " + markers.size());
}
timings.addSplit("addMarkers");
timings.dumpToLog();
mMapboxMap.addMarkers(markerOptions);
mProgressDialog.hide();
//Debug.stopMethodTracing();
}
}
}

View File

@@ -1,21 +1,23 @@
package com.mapbox.mapboxsdk.testapp;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
public class CameraActivity extends AppCompatActivity {
@@ -39,80 +41,84 @@ public class CameraActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.cameraMapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.setStyle(Style.MAPBOX_STREETS);
mMapView.setCompassEnabled(true);
mMapView.onCreate(savedInstanceState);
Button cameraButton = (Button) findViewById(R.id.cameraMoveButton);
cameraButton.setOnClickListener(new View.OnClickListener() {
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onClick(View view) {
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(44.50128, -88.06216)) // Sets the center of the map to Lambeau Field
.zoom(14) // Sets the zoom
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
mMapView.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
// set a style
mapboxMap.setStyle(Style.MAPBOX_STREETS);
// handle move button clicks
findViewById(R.id.cameraMoveButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(44.50128, -88.06216)) // Sets the center of the map to Lambeau Field
.zoom(14) // Sets the zoom
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build();
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
});
// handle ease button clicks
findViewById(R.id.cameraEaseButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(48.21874, 11.62465)) // Sets the center of the map to Allianz Arena
.zoom(16) // Sets the zoom
.bearing(180) // Sets the orientation of the camera to south
.build(); // Creates a CameraPosition from the builder
MapboxMap.CancelableCallback callback = new MapboxMap.CancelableCallback() {
@Override
public void onCancel() {
Log.i(TAG, "Duration onCancel Callback called.");
Toast.makeText(CameraActivity.this, "Ease onCancel Callback called.", Toast.LENGTH_LONG).show();
}
@Override
public void onFinish() {
Log.i(TAG, "Duration onFinish Callback called.");
Toast.makeText(CameraActivity.this, "Ease onFinish Callback called.", Toast.LENGTH_LONG).show();
}
};
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 25000, callback);
}
});
// handle animate button clicks
findViewById(R.id.cameraAnimateButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(-22.91214, -43.23012)) // Sets the center of the map to Maracanã
.bearing(270) // Sets the orientation of the camera to west
.tilt(20) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
MapboxMap.CancelableCallback callback = new MapboxMap.CancelableCallback() {
@Override
public void onCancel() {
Log.i(TAG, "Duration onCancel Callback called.");
Toast.makeText(CameraActivity.this, "Duration onCancel Callback called.", Toast.LENGTH_LONG).show();
}
@Override
public void onFinish() {
Log.i(TAG, "Duration onFinish Callback called.");
Toast.makeText(CameraActivity.this, "Duration onFinish Callback called.", Toast.LENGTH_LONG).show();
}
};
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 25000, callback);
}
});
}
});
Button cameraCallbackButton = (Button) findViewById(R.id.cameraEaseButton);
cameraCallbackButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(48.21874, 11.62465)) // Sets the center of the map to Allianz Arena
.zoom(16) // Sets the zoom
.bearing(180) // Sets the orientation of the camera to south
.build(); // Creates a CameraPosition from the builder
MapView.CancelableCallback callback = new MapView.CancelableCallback() {
@Override
public void onCancel() {
Log.i(TAG, "Duration onCancel Callback called.");
Toast.makeText(CameraActivity.this, "Ease onCancel Callback called.", Toast.LENGTH_LONG).show();
}
@Override
public void onFinish() {
Log.i(TAG, "Duration onFinish Callback called.");
Toast.makeText(CameraActivity.this, "Ease onFinish Callback called.", Toast.LENGTH_LONG).show();
}
};
mMapView.easeCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 25000, callback);
}
});
Button cameraDurationButton = (Button) findViewById(R.id.cameraAnimateButton);
cameraDurationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(-22.91214, -43.23012)) // Sets the center of the map to Maracanã
.bearing(270) // Sets the orientation of the camera to west
.tilt(20) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
MapView.CancelableCallback callback = new MapView.CancelableCallback() {
@Override
public void onCancel() {
Log.i(TAG, "Duration onCancel Callback called.");
Toast.makeText(CameraActivity.this, "Duration onCancel Callback called.", Toast.LENGTH_LONG).show();
}
@Override
public void onFinish() {
Log.i(TAG, "Duration onFinish Callback called.");
Toast.makeText(CameraActivity.this, "Duration onFinish Callback called.", Toast.LENGTH_LONG).show();
}
};
mMapView.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 25000, callback);
}
});
}
@Override

View File

@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.testapp;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
@@ -9,15 +10,19 @@ import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngZoom;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
public class CoordinateChangeActivity extends AppCompatActivity {
private MapView mMapView;
private MapboxMap mMapboxMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -37,16 +42,24 @@ public class CoordinateChangeActivity extends AppCompatActivity {
mMapView.setTag(true);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
mMapView.setStyle(Style.MAPBOX_STREETS);
mMapView.setLatLng(new LatLngZoom(38.87031, -77.00897, 16));
mMapView.setCompassEnabled(false);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
mapboxMap.setStyle(Style.MAPBOX_STREETS);
mapboxMap.setCompassEnabled(false);
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(getNextLatLng(), 16));
}
});
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setColorFilter(ContextCompat.getColor(this, R.color.primary));
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mMapView.setLatLng(getNextLatLng(), true);
if (mMapboxMap != null) {
mMapboxMap.animateCamera(CameraUpdateFactory.newLatLng(getNextLatLng()));
}
}
});
}

View File

@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.testapp;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
@@ -15,9 +16,13 @@ import com.mapbox.directions.service.models.DirectionsRoute;
import com.mapbox.directions.service.models.Waypoint;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
import java.util.List;
@@ -30,6 +35,7 @@ public class DirectionsActivity extends AppCompatActivity {
private final static String LOG_TAG = "DirectionsActivity";
private MapView mMapView;
private MapboxMap mMapboxMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -48,9 +54,13 @@ public class DirectionsActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
// load routes async
loadRoute();
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
loadRoute();
}
});
}
private void loadRoute() {
@@ -64,15 +74,18 @@ public class DirectionsActivity extends AppCompatActivity {
LatLng centroid = new LatLng(
(origin.getLatitude() + destination.getLatitude()) / 2,
(origin.getLongitude() + destination.getLongitude()) / 2);
mMapView.setCenterCoordinate(centroid);
mMapView.setZoomLevel(14);
mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder()
.target(centroid)
.zoom(14)
.build()));
// Add origin and destination to the map
mMapView.addMarker(new MarkerOptions()
mMapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(origin.getLatitude(), origin.getLongitude()))
.title("Origin")
.snippet("Dupont Circle"));
mMapView.addMarker(new MarkerOptions()
mMapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(destination.getLatitude(), destination.getLongitude()))
.title("Destination")
.snippet("The White House"));
@@ -121,7 +134,7 @@ public class DirectionsActivity extends AppCompatActivity {
}
// Draw Points on MapView
mMapView.addPolyline(new PolylineOptions()
mMapboxMap.addPolyline(new PolylineOptions()
.add(point)
.color(Color.parseColor("#3887be"))
.width(5));

View File

@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.testapp;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
@@ -11,9 +12,12 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
public class DoubleMapActivity extends AppCompatActivity {
@@ -60,26 +64,42 @@ public class DoubleMapActivity extends AppCompatActivity {
// MapView large
mMapView = (MapView) view.findViewById(R.id.mapview);
mMapView.onCreate(savedInstanceState);
mMapView.setStyle(Style.DARK);
mMapView.setZoom(18);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.DARK);
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(18));
try {
mapboxMap.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
} catch (SecurityException e) {
// permission is handled in MainActivity
getActivity().finish();
}
}
});
// MapView mini
mMapViewMini = (MapView) view.findViewById(R.id.mini_map);
mMapViewMini.onCreate(savedInstanceState);
mMapViewMini.setStyle(Style.LIGHT);
mMapViewMini.setAttributionVisibility(View.GONE);
mMapViewMini.setLogoVisibility(View.GONE);
mMapViewMini.setCompassEnabled(false);
mMapViewMini.setZoom(4);
mMapViewMini.setAllGesturesEnabled(false);
mMapViewMini.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.LIGHT);
mapboxMap.setAllGesturesEnabled(false);
mapboxMap.setCompassEnabled(false);
mapboxMap.setAttributionVisibility(View.GONE);
mapboxMap.setLogoVisibility(View.GONE);
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(4));
try {
mMapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
mMapViewMini.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
}catch (SecurityException e){
// permission is handled in MainActivity
getActivity().finish();
}
try {
mapboxMap.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
}catch (SecurityException e){
// permission is handled in MainActivity
getActivity().finish();
}
}
});
}
@Override

View File

@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.testapp;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
@@ -12,11 +13,14 @@ import com.mapbox.geocoder.GeocoderCriteria;
import com.mapbox.geocoder.MapboxGeocoder;
import com.mapbox.geocoder.service.models.GeocoderFeature;
import com.mapbox.geocoder.service.models.GeocoderResponse;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
import java.util.List;
@@ -27,6 +31,7 @@ import retrofit.Retrofit;
public class GeocoderActivity extends AppCompatActivity {
private static final String LOG_TAG = "GeocoderActivity";
private static final LatLng DC_DUPONT_CIRCLE = new LatLng(38.90962, -77.04341);
private MapView mapView;
private TextView textView;
@@ -48,24 +53,38 @@ public class GeocoderActivity extends AppCompatActivity {
textView = (TextView) findViewById(R.id.message);
setMessage("Tap the map to trigger the geocoder.");
LatLng dupontCircle = new LatLng(38.90962, -77.04341);
mapView = (MapView) findViewById(R.id.mapView);
mapView.setAccessToken(ApiAccess.getToken(this));
mapView.setStyleUrl(Style.MAPBOX_STREETS);
mapView.setCenterCoordinate(dupontCircle);
mapView.setZoomLevel(15);
mapView.onCreate(savedInstanceState);
mapView.setOnMapClickListener(new MapView.OnMapClickListener() {
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapClick(LatLng point) {
setMessage("Geocoding...");
mapView.removeAllAnnotations();
mapView.addMarker(new MarkerOptions()
.position(point)
.title("Your finger is here"));
geocode(point);
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
// Style
mapboxMap.setStyle(Style.EMERALD);
// Camera position
mapboxMap.setCameraPosition(
new CameraPosition.Builder()
.target(DC_DUPONT_CIRCLE)
.zoom(15)
.bearing(0)
.tilt(0)
.build()
);
// Click listener
mapboxMap.setOnMapClickListener(new MapboxMap.OnMapClickListener() {
@Override
public void onMapClick(@NonNull LatLng point) {
setMessage("Geocoding...");
mapboxMap.removeAllAnnotations();
mapboxMap.addMarker(new MarkerOptions()
.position(point)
.title("Your finger is here"));
geocode(point);
}
});
}
});
}
@@ -83,7 +102,7 @@ public class GeocoderActivity extends AppCompatActivity {
}
@Override
public void onPause() {
public void onPause() {
super.onPause();
mapView.onPause();
}

View File

@@ -7,12 +7,14 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
import java.text.DecimalFormat;
@@ -38,43 +40,44 @@ public class InfoWindowActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
// Enable to let concurrent multiple infowindows to be shown.
//mMapView.setAllowConcurrentMultipleOpenInfoWindows(true);
mMapView.addMarker(new MarkerOptions()
.title("Intersection")
.snippet("H St NW with 15th St NW")
.icon(IconFactory.getInstance(this).fromAsset("london-underground-24.png"))
.position(new LatLng(38.9002073, -77.03364419)));
mMapView.addMarker(new MarkerOptions()
.title("White House")
.snippet("The official residence and principal workplace of the President of the United States, located at 1600 Pennsylvania Avenue NW in Washington, D.C. It has been the residence of every U.S. president since John Adams in 1800.")
.icon(mMapView.getIconFactory().fromAsset("town-hall-24.png"))
.position(new LatLng(38.897705003219784, -77.03655168667463)));
mMapView.addMarker(new MarkerOptions().title("Intersection")
.snippet("E St NW with 17th St NW")
.icon(mMapView.getIconFactory().fromAsset("commercial-24.png"))
.position(new LatLng(38.8954236, -77.0394623)));
final DecimalFormat formatter = new DecimalFormat("#.#####");
mMapView.setOnMapLongClickListener(new MapView.OnMapLongClickListener() {
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapLongClick(@NonNull LatLng point) {
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
mapboxMap.addMarker(new MarkerOptions()
.title("Intersection")
.snippet("H St NW with 15th St NW")
.icon(IconFactory.getInstance(InfoWindowActivity.this)
.fromAsset("london-underground-24.png"))
.position(new LatLng(38.9002073, -77.03364419)));
// Remove previous added marker
if (mCustomMarker != null) {
mMapView.removeAnnotation(mCustomMarker);
mCustomMarker = null;
}
mapboxMap.addMarker(new MarkerOptions()
.title("White House")
.snippet("The official residence and principal workplace of the President of the United States, located at 1600 Pennsylvania Avenue NW in Washington, D.C. It has been the residence of every U.S. president since John Adams in 1800.")
.icon(IconFactory.getInstance(InfoWindowActivity.this).fromAsset("town-hall-24.png"))
.position(new LatLng(38.897705003219784, -77.03655168667463)));
// Add marker on long click location with default marker image
mCustomMarker = mMapView.addMarker(new MarkerOptions()
.title("Custom Marker")
.snippet(formatter.format(point.getLatitude()) + ", " + formatter.format(point.getLongitude()))
.position(point));
mapboxMap.addMarker(new MarkerOptions().title("Intersection")
.snippet("E St NW with 17th St NW")
.icon(IconFactory.getInstance(InfoWindowActivity.this).fromAsset("commercial-24.png"))
.position(new LatLng(38.8954236, -77.0394623)));
final DecimalFormat formatter = new DecimalFormat("#.#####");
mapboxMap.setOnMapLongClickListener(new MapboxMap.OnMapLongClickListener() {
@Override
public void onMapLongClick(@NonNull LatLng point) {
// Remove previous added marker
if (mCustomMarker != null) {
mapboxMap.removeAnnotation(mCustomMarker);
mCustomMarker = null;
}
// Add marker on long click location with default marker image
mCustomMarker = mapboxMap.addMarker(new MarkerOptions()
.title("Custom Marker")
.snippet(formatter.format(point.getLatitude()) + ", " + formatter.format(point.getLongitude()))
.position(point));
}
});
}
});
}

View File

@@ -13,13 +13,15 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
public class InfoWindowAdapterActivity extends AppCompatActivity {
@@ -48,30 +50,34 @@ public class InfoWindowAdapterActivity extends AppCompatActivity {
mIconFactory = IconFactory.getInstance(this);
mIconDrawable = ContextCompat.getDrawable(this, R.drawable.ic_location_city_24dp);
mMapView.setInfoWindowAdapter(new MapView.InfoWindowAdapter() {
private int tenDp = (int) getResources().getDimension(R.dimen.attr_margin);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public View getInfoWindow(@NonNull Marker marker) {
TextView textView = new TextView(InfoWindowAdapterActivity.this);
textView.setText(marker.getTitle());
textView.setTextColor(Color.WHITE);
textView.setBackgroundColor(Color.parseColor(marker.getSnippet()));
textView.setPadding(tenDp, tenDp, tenDp, tenDp);
return textView;
public void onMapReady(@NonNull MapboxMap mapboxMap) {
// add markers
mapboxMap.addMarker(generateMarker("Andorra", 42.505777, 1.52529, "#F44336"));
mapboxMap.addMarker(generateMarker("Luxembourg", 49.815273, 6.129583, "#3F51B5"));
mapboxMap.addMarker(generateMarker("Monaco", 43.738418, 7.424616, "#673AB7"));
mapboxMap.addMarker(generateMarker("Vatican City", 41.902916, 12.453389, "#009688"));
mapboxMap.addMarker(generateMarker("San Marino", 43.942360, 12.457777, "#795548"));
mapboxMap.addMarker(generateMarker("Liechtenstein", 47.166000, 9.555373, "#FF5722"));
// add custom window adapter
mapboxMap.setInfoWindowAdapter(new MapboxMap.InfoWindowAdapter() {
private int tenDp = (int) getResources().getDimension(R.dimen.attr_margin);
@Override
public View getInfoWindow(@NonNull Marker marker) {
TextView textView = new TextView(InfoWindowAdapterActivity.this);
textView.setText(marker.getTitle());
textView.setTextColor(Color.WHITE);
textView.setBackgroundColor(Color.parseColor(marker.getSnippet()));
textView.setPadding(tenDp, tenDp, tenDp, tenDp);
return textView;
}
});
}
});
// Enable to let concurrent multiple infowindows to be shown.
//mMapView.setAllowConcurrentMultipleOpenInfoWindows(true);
mMapView.addMarker(generateMarker("Andorra", 42.505777, 1.52529, "#F44336"));
mMapView.addMarker(generateMarker("Luxembourg", 49.815273, 6.129583, "#3F51B5"));
mMapView.addMarker(generateMarker("Monaco", 43.738418, 7.424616, "#673AB7"));
mMapView.addMarker(generateMarker("Vatican City", 41.902916, 12.453389, "#009688"));
mMapView.addMarker(generateMarker("San Marino", 43.942360, 12.457777, "#795548"));
mMapView.addMarker(generateMarker("Liechtenstein", 47.166000, 9.555373, "#FF5722"));
}
private MarkerOptions generateMarker(String title, double lat, double lng, String color) {

View File

@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.testapp;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
@@ -8,8 +9,10 @@ import android.view.MenuItem;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
public class InfoWindowConcurrentActivity extends AppCompatActivity {
@@ -33,22 +36,26 @@ public class InfoWindowConcurrentActivity extends AppCompatActivity {
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
// Enable to let concurrent multiple infowindows to be shown.
mMapView.setAllowConcurrentMultipleOpenInfoWindows(true);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setAllowConcurrentMultipleOpenInfoWindows(true);
mMapView.addMarker(new MarkerOptions()
.title("Intersection")
.snippet("H St NW with 15th St NW")
.position(new LatLng(38.9002073, -77.03364419)));
mapboxMap.addMarker(new MarkerOptions()
.title("Intersection")
.snippet("H St NW with 15th St NW")
.position(new LatLng(38.9002073, -77.03364419)));
mMapView.addMarker(new MarkerOptions()
.title("White House")
.snippet("The official residence and principal workplace of the President of the United States, located at 1600 Pennsylvania Avenue NW in Washington, D.C. It has been the residence of every U.S. president since John Adams in 1800.")
.position(new LatLng(38.897705003219784, -77.03655168667463)));
mapboxMap.addMarker(new MarkerOptions()
.title("White House")
.snippet("The official residence and principal workplace of the President of the United States, located at 1600 Pennsylvania Avenue NW in Washington, D.C. It has been the residence of every U.S. president since John Adams in 1800.")
.position(new LatLng(38.897705003219784, -77.03655168667463)));
mMapView.addMarker(new MarkerOptions().title("Intersection")
.snippet("E St NW with 17th St NW")
.position(new LatLng(38.8954236, -77.0394623)));
mapboxMap.addMarker(new MarkerOptions().title("Intersection")
.snippet("E St NW with 17th St NW")
.position(new LatLng(38.8954236, -77.0394623)));
}
});
}
@Override

View File

@@ -8,7 +8,6 @@ import android.location.Location;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresPermission;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
@@ -24,6 +23,10 @@ import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
@@ -34,10 +37,12 @@ import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.layers.CustomLayer;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.layers.ExampleCustomLayer;
import com.mapbox.mapboxsdk.testapp.utils.GeoParseUtil;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
@@ -69,6 +74,7 @@ public class MainActivity extends AppCompatActivity {
// Used for the UI
private DrawerLayout mDrawerLayout;
private MapView mMapView;
private MapboxMap mMapboxMap;
private TextView mFpsTextView;
private int mSelectedStyle = R.id.actionStyleMapboxStreets;
private NavigationView mNavigationView;
@@ -88,7 +94,7 @@ public class MainActivity extends AppCompatActivity {
// Called when activity is created
@Override
protected void onCreate(Bundle savedInstanceState) {
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the layout
@@ -112,73 +118,6 @@ public class MainActivity extends AppCompatActivity {
mCoordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinator_layout);
mMapView = (MapView) findViewById(R.id.mainMapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
mMapView.setOnFpsChangedListener(new MyOnFpsChangedListener());
mMapView.setOnMapLongClickListener(new MapView.OnMapLongClickListener() {
@Override
public void onMapLongClick(@NonNull LatLng point) {
MarkerOptions marker = new MarkerOptions()
.position(point)
.title("Dropped Pin")
.snippet(LAT_LON_FORMATTER.format(point.getLatitude()) + ", " +
LAT_LON_FORMATTER.format(point.getLongitude()))
.icon(null);
mMarkerList.add(marker);
mMapView.addMarker(marker);
}
});
mMapView.setOnMapClickListener(new MapView.OnMapClickListener() {
@Override
public void onMapClick(@NonNull LatLng point) {
String location = LAT_LON_FORMATTER.format(point.getLatitude()) + ", " +
LAT_LON_FORMATTER.format(point.getLongitude());
Snackbar.make(mCoordinatorLayout, "Map Click Listener " + location, Snackbar.LENGTH_SHORT).show();
}
});
mMapView.setOnMarkerClickListener(new MapView.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(@NonNull Marker marker) {
Snackbar.make(mCoordinatorLayout, "Marker Click Listener for " + marker.getTitle(), Snackbar.LENGTH_SHORT).show();
return false;
}
});
mMapView.setOnInfoWindowClickListener(new MapView.OnInfoWindowClickListener() {
@Override
public boolean onMarkerClick(@NonNull Marker marker) {
Snackbar.make(mCoordinatorLayout, "InfoWindow Click Listener for " + marker.getTitle(), Snackbar.LENGTH_SHORT).show();
marker.hideInfoWindow();
return true;
}
});
mMapView.setOnMyLocationChangeListener(new MapView.OnMyLocationChangeListener() {
@Override
public void onMyLocationChange(@Nullable Location location) {
String desc = "Loc Chg: ";
boolean noInfo = true;
if (location.hasSpeed()) {
desc += String.format("Spd = %.1f km/h ", location.getSpeed() * 3.6f);
noInfo = false;
}
if (location.hasAltitude()) {
desc += String.format("Alt = %.0f m ", location.getAltitude());
noInfo = false;
}
if (noInfo) {
desc += "No extra info";
}
Snackbar.make(mCoordinatorLayout, desc, Snackbar.LENGTH_SHORT).show();
}
});
mFpsTextView = (TextView) findViewById(R.id.view_fps);
mFpsTextView.setText("");
@@ -187,24 +126,102 @@ public class MainActivity extends AppCompatActivity {
@Override
public void onClick(View v) {
// Toggle GPS position updates
toggleGps(!mMapView.isMyLocationEnabled());
if (mMapboxMap != null) {
toggleGps(!mMapboxMap.isMyLocationEnabled());
}
}
});
// Restore saved state
if (savedInstanceState != null) {
mIsAnnotationsOn = savedInstanceState.getBoolean(STATE_IS_ANNOTATIONS_ON);
mSelectedStyle = savedInstanceState.getInt(STATE_SELECTED_STYLE);
mMarkerList = savedInstanceState.getParcelableArrayList(STATE_MARKER_LIST);
mMapView.addMarkers(mMarkerList);
}
mMapView = (MapView) findViewById(R.id.mainMapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
// Set default UI state
mNavigationView.getMenu().findItem(R.id.action_compass).setChecked(mMapView.isCompassEnabled());
mNavigationView.getMenu().findItem(R.id.action_debug).setChecked(mMapView.isDebugActive());
mNavigationView.getMenu().findItem(R.id.action_markers).setChecked(mIsAnnotationsOn);
changeMapStyle(mSelectedStyle);
toggleGps(mMapView.isMyLocationEnabled());
mMapboxMap.setOnFpsChangedListener(new MyOnFpsChangedListener());
// add location listener to MapboxMap
mapboxMap.setOnMyLocationChangeListener(new MapboxMap.OnMyLocationChangeListener() {
@Override
public void onMyLocationChange(@Nullable Location location) {
String desc = "Loc Chg: ";
boolean noInfo = true;
if (location.hasSpeed()) {
desc += String.format("Spd = %.1f km/h ", location.getSpeed() * 3.6f);
noInfo = false;
}
if (location.hasAltitude()) {
desc += String.format("Alt = %.0f m ", location.getAltitude());
noInfo = false;
}
if (noInfo) {
desc += "No extra info";
}
Snackbar.make(mCoordinatorLayout, desc, Snackbar.LENGTH_SHORT).show();
}
});
// Set default UI state
mNavigationView.getMenu().findItem(R.id.action_compass).setChecked(mapboxMap.isCompassEnabled());
mNavigationView.getMenu().findItem(R.id.action_debug).setChecked(mapboxMap.isDebugActive());
mNavigationView.getMenu().findItem(R.id.action_markers).setChecked(mIsAnnotationsOn);
toggleGps(mapboxMap.isMyLocationEnabled());
// Listeners
mapboxMap.setOnMapLongClickListener(new MapboxMap.OnMapLongClickListener() {
@Override
public void onMapLongClick(@NonNull LatLng point) {
MarkerOptions marker = new MarkerOptions()
.position(point)
.title("Dropped Pin")
.snippet(LAT_LON_FORMATTER.format(point.getLatitude()) + ", " +
LAT_LON_FORMATTER.format(point.getLongitude()))
.icon(null);
mMarkerList.add(marker);
mapboxMap.addMarker(marker);
}
});
// Restore saved state
if (savedInstanceState != null) {
mIsAnnotationsOn = savedInstanceState.getBoolean(STATE_IS_ANNOTATIONS_ON);
mSelectedStyle = savedInstanceState.getInt(STATE_SELECTED_STYLE);
mMarkerList = savedInstanceState.getParcelableArrayList(STATE_MARKER_LIST);
mapboxMap.addMarkers(mMarkerList);
}
mMapboxMap.setOnMarkerClickListener(new MapboxMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(@NonNull Marker marker) {
Snackbar.make(mCoordinatorLayout, "Marker Click Listener for " + marker.getTitle(), Snackbar.LENGTH_SHORT).show();
return false;
}
});
mMapboxMap.setOnMapClickListener(new MapboxMap.OnMapClickListener() {
@Override
public void onMapClick(@NonNull LatLng point) {
String location = LAT_LON_FORMATTER.format(point.getLatitude()) + ", " +
LAT_LON_FORMATTER.format(point.getLongitude());
Snackbar.make(mCoordinatorLayout, "Map Click Listener " + location, Snackbar.LENGTH_SHORT).show();
}
});
mMapboxMap.setOnInfoWindowClickListener(new MapboxMap.OnInfoWindowClickListener() {
@Override
public boolean onMarkerClick(@NonNull Marker marker) {
Snackbar.make(mCoordinatorLayout, "InfoWindow Click Listener for " + marker.getTitle(), Snackbar.LENGTH_SHORT).show();
marker.hideInfoWindow();
return true;
}
});
changeMapStyle(mSelectedStyle);
}
});
}
/**
@@ -320,8 +337,8 @@ public class MainActivity extends AppCompatActivity {
case R.id.action_debug:
// Cycle map debug options
mMapView.cycleDebugOptions();
toggleFpsCounter(mMapView.isDebugActive());
mMapboxMap.cycleDebugOptions();
toggleFpsCounter(mMapboxMap.isDebugActive());
return true;
case R.id.action_markers:
@@ -331,7 +348,11 @@ public class MainActivity extends AppCompatActivity {
case R.id.action_compass:
// Toggle compass
mMapView.setCompassEnabled(!mMapView.isCompassEnabled());
mMapboxMap.setCompassEnabled(!mMapboxMap.isCompassEnabled());
return true;
case R.id.action_mapboxmap:
startActivity(new Intent(getApplicationContext(), MapboxMapActivity.class));
return true;
case R.id.action_info_window_adapter:
@@ -358,6 +379,10 @@ public class MainActivity extends AppCompatActivity {
startActivity(new Intent(getApplicationContext(), ManualZoomActivity.class));
return true;
case R.id.action_minmax_zoom:
startActivity(new Intent(getApplicationContext(), MaxMinZoomActivity.class));
return true;
case R.id.action_coordinate_change:
startActivity(new Intent(getApplicationContext(), CoordinateChangeActivity.class));
return true;
@@ -444,32 +469,32 @@ public class MainActivity extends AppCompatActivity {
private boolean changeMapStyle(int id) {
switch (id) {
case R.id.actionStyleMapboxStreets:
mMapView.setStyle(Style.MAPBOX_STREETS);
mMapboxMap.setStyle(Style.MAPBOX_STREETS);
mSelectedStyle = id;
return true;
case R.id.actionStyleEmerald:
mMapView.setStyle(Style.EMERALD);
mMapboxMap.setStyle(Style.EMERALD);
mSelectedStyle = id;
return true;
case R.id.actionStyleLight:
mMapView.setStyle(Style.LIGHT);
mMapboxMap.setStyle(Style.LIGHT);
mSelectedStyle = id;
return true;
case R.id.actionStyleDark:
mMapView.setStyle(Style.DARK);
mMapboxMap.setStyle(Style.DARK);
mSelectedStyle = id;
return true;
case R.id.actionStyleSatellite:
mMapView.setStyle(Style.SATELLITE);
mMapboxMap.setStyle(Style.SATELLITE);
mSelectedStyle = id;
return true;
case R.id.actionStyleSatelliteStreets:
mMapView.setStyle(Style.SATELLITE_STREETS);
mMapboxMap.setStyle(Style.SATELLITE_STREETS);
mSelectedStyle = id;
return true;
@@ -493,23 +518,27 @@ public class MainActivity extends AppCompatActivity {
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION},
PERMISSIONS_LOCATION);
} else {
mMapView.setOnMyLocationChangeListener(new MapView.OnMyLocationChangeListener() {
mMapboxMap.setOnMyLocationChangeListener(new MapboxMap.OnMyLocationChangeListener() {
@Override
public void onMyLocationChange(@Nullable Location location) {
if (location != null) {
mMapView.setZoom(16);
mMapView.setLatLng(new LatLng(location));
mMapView.setOnMyLocationChangeListener(null);
mMapboxMap.setCameraPosition(new CameraPosition.Builder()
.target(new LatLng(location))
.zoom(16)
.bearing(0)
.tilt(0)
.build());
mMapboxMap.setOnMyLocationChangeListener(null);
}
}
});
mMapView.setMyLocationEnabled(true);
mMapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
mMapView.setMyBearingTrackingMode(MyBearingTracking.GPS);
mMapboxMap.setMyLocationEnabled(true);
mMapboxMap.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
mMapboxMap.setMyBearingTrackingMode(MyBearingTracking.GPS);
mLocationFAB.setColorFilter(ContextCompat.getColor(this, R.color.primary));
}
} else {
mMapView.setMyLocationEnabled(false);
mMapboxMap.setMyLocationEnabled(false);
mLocationFAB.setColorFilter(Color.TRANSPARENT);
}
}
@@ -526,8 +555,13 @@ public class MainActivity extends AppCompatActivity {
addMarkers();
addPolyline();
addPolygon();
mMapView.setZoom(7);
mMapView.setLatLng(new LatLng(38.11727, -122.22839));
mMapboxMap.setCameraPosition(
new CameraPosition.Builder()
.target(new LatLng(38.11727, -122.22839))
.zoom(7)
.bearing(0)
.tilt(0)
.build());
}
} else {
if (mIsAnnotationsOn) {
@@ -543,11 +577,11 @@ public class MainActivity extends AppCompatActivity {
final MarkerOptions backLot = generateMarker("Back Lot", "The back lot behind my house", null, 38.649441, -121.369064);
markerOptionsList.add(backLot);
final Icon dogIcon = mMapView.getIconFactory().fromAsset("dog-park-24.png");
final Icon dogIcon = IconFactory.getInstance(this).fromAsset("dog-park-24.png");
final MarkerOptions cheeseRoom = generateMarker("Cheese Room", "The only air conditioned room on the property", dogIcon, 38.531577, -122.010646);
markerOptionsList.add(cheeseRoom);
List<Marker> markers = mMapView.addMarkers(markerOptionsList);
mMapboxMap.addMarkers(markerOptionsList);
}
private MarkerOptions generateMarker(String title, String snippet, Icon icon, double lat, double lng) {
@@ -562,8 +596,7 @@ public class MainActivity extends AppCompatActivity {
try {
String geojsonStr = GeoParseUtil.loadStringFromAssets(this, "small_line.geojson");
List<LatLng> latLngs = GeoParseUtil.parseGeoJSONCoordinates(geojsonStr);
MapView map = mMapView;
map.addPolyline(new PolylineOptions()
mMapboxMap.addPolyline(new PolylineOptions()
.add(latLngs.toArray(new LatLng[latLngs.size()]))
.width(2)
.color(Color.RED));
@@ -577,13 +610,12 @@ public class MainActivity extends AppCompatActivity {
try {
String geojsonStr = GeoParseUtil.loadStringFromAssets(this, "small_poly.geojson");
List<LatLng> latLngs = GeoParseUtil.parseGeoJSONCoordinates(geojsonStr);
MapView map = mMapView;
ArrayList<PolygonOptions> opts = new ArrayList<>();
opts.add(new PolygonOptions()
List<PolygonOptions> polygonOptions = new ArrayList<>();
polygonOptions.add(new PolygonOptions()
.add(latLngs.toArray(new LatLng[latLngs.size()]))
.strokeColor(Color.MAGENTA)
.fillColor(Color.BLUE).alpha(0.5f));
map.addPolygons(opts).get(0);
mMapboxMap.addPolygons(polygonOptions).get(0);
} catch (Exception e) {
Log.e(TAG, "Error adding Polygon: " + e);
e.printStackTrace();
@@ -592,27 +624,27 @@ public class MainActivity extends AppCompatActivity {
private void removeAnnotations() {
mMarkerList.clear();
mMapView.removeAllAnnotations();
mMapboxMap.removeAllAnnotations();
}
private void addCustomLayer() {
mIsShowingCustomLayer = true;
mMapView.addCustomLayer(
new CustomLayer("custom",
ExampleCustomLayer.createContext(),
ExampleCustomLayer.InitializeFunction,
ExampleCustomLayer.RenderFunction,
ExampleCustomLayer.DeinitializeFunction),
null);
mMapboxMap.addCustomLayer(
new CustomLayer("custom",
ExampleCustomLayer.createContext(),
ExampleCustomLayer.InitializeFunction,
ExampleCustomLayer.RenderFunction,
ExampleCustomLayer.DeinitializeFunction),
null);
}
private void removeCustomLayer() {
mIsShowingCustomLayer = false;
mMapView.removeCustomLayer("custom");
mMapboxMap.removeCustomLayer("custom");
}
// Called when FPS changes
private class MyOnFpsChangedListener implements MapView.OnFpsChangedListener {
private class MyOnFpsChangedListener implements MapboxMap.OnFpsChangedListener {
@Override
public void onFpsChanged(double fps) {

View File

@@ -1,16 +1,25 @@
package com.mapbox.mapboxsdk.testapp;
import android.graphics.Point;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
public class ManualZoomActivity extends AppCompatActivity {
private MapboxMap mMapboxMap;
private MapView mMapView;
@Override
@@ -29,8 +38,53 @@ public class ManualZoomActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.manualZoomMapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.setStyle(Style.MAPBOX_STREETS);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
mMapboxMap.setStyle(Style.SATELLITE_STREETS);
mMapboxMap.setAllGesturesEnabled(false);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_zoom, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
case R.id.action_zoom_in:
mMapboxMap.animateCamera(CameraUpdateFactory.zoomIn());
return true;
case R.id.action_zoom_out:
mMapboxMap.animateCamera(CameraUpdateFactory.zoomOut());
return true;
case R.id.action_zoom_by:
mMapboxMap.animateCamera(CameraUpdateFactory.zoomBy(2));
return true;
case R.id.action_zoom_to:
mMapboxMap.animateCamera(CameraUpdateFactory.zoomTo(2));
return true;
case R.id.action_zoom_to_point:
mMapboxMap.animateCamera(CameraUpdateFactory.zoomBy(12, new Point(100, 100)));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
@@ -74,15 +128,4 @@ public class ManualZoomActivity extends AppCompatActivity {
super.onLowMemory();
mMapView.onLowMemory();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}

View File

@@ -1,24 +1,23 @@
package com.mapbox.mapboxsdk.testapp;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import com.mapbox.mapboxsdk.MapFragment;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.maps.MapFragment;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
public class MapFragmentActivity extends AppCompatActivity {
private static final String TAG_FRAGMENT = "map";
private MyMapFragment mMapFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -33,31 +32,28 @@ public class MapFragmentActivity extends AppCompatActivity {
actionBar.setDisplayShowHomeEnabled(true);
}
MapFragment mapFragment;
if (savedInstanceState == null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.fragment_container, mMapFragment = new MyMapFragment(), TAG_FRAGMENT);
transaction.add(R.id.fragment_container, mapFragment = new MapFragment(), "com.mapbox.map");
transaction.commit();
} else {
mMapFragment = (MyMapFragment) getSupportFragmentManager().findFragmentByTag(TAG_FRAGMENT);
mapFragment = (MapFragment) getSupportFragmentManager().findFragmentByTag("com.mapbox.map");
}
}
public static class MyMapFragment extends MapFragment {
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
MapView mapView = getMap();
mapView.setStyleUrl(Style.EMERALD);
mapView.setZoom(12);
mapView.setLatLng(new LatLng(50.853658, 4.352419));
// move attribution control to right of screen
mapView.setAttributionGravity(Gravity.BOTTOM | Gravity.END);
int tenDp = (int) getResources().getDimension(R.dimen.attr_margin);
mapView.setAttributionMargins(0, 0, tenDp, tenDp);
}
mapFragment.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyleUrl(Style.SATELLITE_STREETS);
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.target(new LatLng(48.861431, 2.334166))
.zoom(10)
.bearing(0)
.tilt(0)
.build()));
}
});
}
@Override

View File

@@ -0,0 +1,114 @@
package com.mapbox.mapboxsdk.testapp;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
public class MapboxMapActivity extends AppCompatActivity {
private MapView mMapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mapboxmap);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.SATELLITE_STREETS);
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.target(new LatLng(43.876550, -103.454791))
.zoom(14)
.bearing(0)
.tilt(0)
.build()));
}
});
Snackbar.make(findViewById(android.R.id.content),
"Demo MapboxMap API.",
Snackbar.LENGTH_INDEFINITE).show();
}
@Override
protected void onStart() {
super.onStart();
mMapView.onStart();
}
@Override
public void onResume() {
super.onResume();
mMapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mMapView.onPause();
}
@Override
protected void onStop() {
super.onStop();
mMapView.onStop();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mMapView.onSaveInstanceState(outState);
}
@Override
protected void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mMapView.onLowMemory();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}

View File

@@ -0,0 +1,134 @@
package com.mapbox.mapboxsdk.testapp;
import android.graphics.Point;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
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.utils.ApiAccess;
public class MaxMinZoomActivity extends AppCompatActivity {
private MapboxMap mMapboxMap;
private MapView mMapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maxmin_zoom);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
mMapView = (MapView) findViewById(R.id.manualZoomMapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
mMapboxMap.setStyle(Style.SATELLITE_STREETS);
mMapboxMap.setMinZoom(3);
mMapboxMap.setMaxZoom(5);
mMapboxMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(-1.063510, 32.895425)));
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_zoom, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
case R.id.action_zoom_in:
mMapboxMap.animateCamera(CameraUpdateFactory.zoomIn());
return true;
case R.id.action_zoom_out:
mMapboxMap.animateCamera(CameraUpdateFactory.zoomOut());
return true;
case R.id.action_zoom_by:
mMapboxMap.animateCamera(CameraUpdateFactory.zoomBy(2));
return true;
case R.id.action_zoom_to:
mMapboxMap.animateCamera(CameraUpdateFactory.zoomTo(2));
return true;
case R.id.action_zoom_to_point:
mMapboxMap.animateCamera(CameraUpdateFactory.zoomBy(12, new Point(100, 100)));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
protected void onStart() {
super.onStart();
mMapView.onStart();
}
@Override
public void onResume() {
super.onResume();
mMapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mMapView.onPause();
}
@Override
protected void onStop() {
super.onStop();
mMapView.onStop();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mMapView.onSaveInstanceState(outState);
}
@Override
protected void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mMapView.onLowMemory();
}
}

View File

@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.testapp;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v7.app.ActionBar;
@@ -14,15 +15,19 @@ import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
public class MyLocationTrackingModeActivity extends AppCompatActivity implements MapView.OnMyLocationChangeListener, AdapterView.OnItemSelectedListener {
public class MyLocationTrackingModeActivity extends AppCompatActivity implements MapboxMap.OnMyLocationChangeListener, AdapterView.OnItemSelectedListener {
private MapView mMapView;
private MapboxMap mMapboxMap;
private Spinner mLocationSpinner, mBearingSpinner;
private Location mLocation;
@@ -56,35 +61,43 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
mMapView.setOnMyLocationChangeListener(this);
try {
mMapView.setMyLocationEnabled(true);
} catch (SecurityException e) {
//should not occur, permission was checked in MainActivity
Toast.makeText(this, "Location permission is not availlable", Toast.LENGTH_SHORT).show();
finish();
}
mMapView.setOnMyLocationTrackingModeChangeListener(new MapView.OnMyLocationTrackingModeChangeListener() {
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMyLocationTrackingModeChange(@MyLocationTracking.Mode int myLocationTrackingMode) {
if (MyLocationTracking.TRACKING_NONE == myLocationTrackingMode) {
mLocationSpinner.setOnItemSelectedListener(null);
mLocationSpinner.setSelection(0);
mLocationSpinner.setOnItemSelectedListener(MyLocationTrackingModeActivity.this);
}
}
});
mMapView.setOnMyBearingTrackingModeChangeListener(new MapView.OnMyBearingTrackingModeChangeListener() {
@Override
public void onMyBearingTrackingModeChange(@MyBearingTracking.Mode int myBearingTrackingMode) {
if (MyBearingTracking.NONE == myBearingTrackingMode) {
mBearingSpinner.setOnItemSelectedListener(null);
mBearingSpinner.setSelection(0);
mBearingSpinner.setOnItemSelectedListener(MyLocationTrackingModeActivity.this);
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
mapboxMap.setOnMyLocationChangeListener(MyLocationTrackingModeActivity.this);
try {
mapboxMap.setMyLocationEnabled(true);
} catch (SecurityException e) {
//should not occur, permission was checked in MainActivity
Toast.makeText(MyLocationTrackingModeActivity.this,
"Location permission is not available", Toast.LENGTH_SHORT).show();
finish();
}
mapboxMap.setOnMyLocationTrackingModeChangeListener(new MapboxMap.OnMyLocationTrackingModeChangeListener() {
@Override
public void onMyLocationTrackingModeChange(@MyLocationTracking.Mode int myLocationTrackingMode) {
if (MyLocationTracking.TRACKING_NONE == myLocationTrackingMode) {
mLocationSpinner.setOnItemSelectedListener(null);
mLocationSpinner.setSelection(0);
mLocationSpinner.setOnItemSelectedListener(MyLocationTrackingModeActivity.this);
}
}
});
mapboxMap.setOnMyBearingTrackingModeChangeListener(new MapboxMap.OnMyBearingTrackingModeChangeListener() {
@Override
public void onMyBearingTrackingModeChange(@MyBearingTracking.Mode int myBearingTrackingMode) {
if (MyBearingTracking.NONE == myBearingTrackingMode) {
mBearingSpinner.setOnItemSelectedListener(null);
mBearingSpinner.setSelection(0);
mBearingSpinner.setOnItemSelectedListener(MyLocationTrackingModeActivity.this);
}
}
});
}
});
}
@@ -94,7 +107,7 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements
if (location != null) {
if (mLocation == null) {
// initial location to reposition map
mMapView.setLatLng(new LatLng(location.getLatitude(), location.getLongitude()));
mMapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 14));
mLocationSpinner.setEnabled(true);
mBearingSpinner.setEnabled(true);
}
@@ -125,25 +138,25 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements
if (parent.getId() == R.id.spinner_location) {
switch (position) {
case 0:
mMapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
mMapboxMap.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
break;
case 1:
mMapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
mMapboxMap.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
break;
}
} else if (parent.getId() == R.id.spinner_bearing) {
switch (position) {
case 0:
mMapView.setMyBearingTrackingMode(MyBearingTracking.NONE);
mMapboxMap.setMyBearingTrackingMode(MyBearingTracking.NONE);
break;
case 1:
mMapView.setMyBearingTrackingMode(MyBearingTracking.GPS);
mMapboxMap.setMyBearingTrackingMode(MyBearingTracking.GPS);
break;
case 2:
mMapView.setMyBearingTrackingMode(MyBearingTracking.COMPASS);
mMapboxMap.setMyBearingTrackingMode(MyBearingTracking.COMPASS);
break;
}
}

View File

@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.testapp;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
@@ -12,8 +13,10 @@ import android.view.View;
import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
import java.util.ArrayList;
import java.util.Collections;
@@ -32,6 +35,7 @@ public class PolylineActivity extends AppCompatActivity {
private List<Polyline> mPolylines;
private ArrayList<PolylineOptions> mPolylineOptions = new ArrayList<>();
private MapView mMapView;
private MapboxMap mMapboxMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -47,33 +51,38 @@ public class PolylineActivity extends AppCompatActivity {
actionBar.setDisplayShowHomeEnabled(true);
}
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
if (savedInstanceState != null) {
mPolylineOptions = savedInstanceState.getParcelableArrayList(STATE_POLYLINE_OPTIONS);
} else {
mPolylineOptions.addAll(getAllPolylines());
}
mPolylines = mMapView.addPolylines(mPolylineOptions);
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
mPolylines = mapboxMap.addPolylines(mPolylineOptions);
}
});
findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mPolylines != null && mPolylines.size() > 0) {
if (mMapboxMap != null && mPolylines != null && mPolylines.size() > 0) {
if (mPolylines.size() == 1) {
// test for removing annotation
mMapView.removeAnnotation(mPolylines.get(0));
mMapboxMap.removeAnnotation(mPolylines.get(0));
} else {
// test for removing annotations
mMapView.removeAnnotations(mPolylines);
mMapboxMap.removeAnnotations(mPolylines);
}
}
mPolylineOptions.clear();
mPolylineOptions.addAll(getRandomLine());
mPolylines = mMapView.addPolylines(mPolylineOptions);
mPolylines = mMapboxMap.addPolylines(mPolylineOptions);
}
});
}
@@ -100,7 +109,7 @@ public class PolylineActivity extends AppCompatActivity {
public List<PolylineOptions> getRandomLine() {
final List<PolylineOptions> randomLines = getAllPolylines();
Collections.shuffle(randomLines);
return new ArrayList<PolylineOptions>(){{
return new ArrayList<PolylineOptions>() {{
add(randomLines.get(0));
}};
}
@@ -160,7 +169,7 @@ public class PolylineActivity extends AppCompatActivity {
case R.id.action_id_remove:
// test to remove all annotations
mPolylineOptions.clear();
mMapView.removeAllAnnotations();
mMapboxMap.removeAllAnnotations();
return true;
case android.R.id.home:
@@ -171,5 +180,4 @@ public class PolylineActivity extends AppCompatActivity {
return super.onOptionsItemSelected(item);
}
}
}

View File

@@ -9,23 +9,26 @@ import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.ViewGroup;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
import java.text.DecimalFormat;
import java.util.ArrayList;
public class PressForMarkerActivity extends AppCompatActivity implements MapView.OnMapLongClickListener {
private MapView mMapView;
private ArrayList<MarkerOptions> mMarkerList = new ArrayList<>();
public class PressForMarkerActivity extends AppCompatActivity implements MapboxMap.OnMapLongClickListener {
private static final DecimalFormat LAT_LON_FORMATTER = new DecimalFormat("#.#####");
private static final String STATE_MARKER_LIST = "markerList";
private static String STATE_MARKER_LIST = "markerList";
private MapView mMapView;
private MapboxMap mMapboxMap;
private ArrayList<MarkerOptions> mMarkerList;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -41,32 +44,46 @@ public class PressForMarkerActivity extends AppCompatActivity implements MapView
actionBar.setDisplayShowHomeEnabled(true);
}
mMapView = new MapView(this, ApiAccess.getToken(this));
mMapView.setStyleUrl(Style.EMERALD);
// Adding MapView programmatically
mMapView = new MapView(this);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
mMapView.setLatLng(new LatLng(45.1855569, 5.7215506));
mMapView.setZoom(11);
mMapView.setOnMapLongClickListener(this);
((ViewGroup) findViewById(R.id.activity_container)).addView(mMapView);
if (savedInstanceState != null) {
mMarkerList = savedInstanceState.getParcelableArrayList(STATE_MARKER_LIST);
mMapView.addMarkers(mMarkerList);
}else{
mMarkerList = new ArrayList<>();
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
mMapView.onSaveInstanceState(outState);
outState.putParcelableArrayList(STATE_MARKER_LIST, mMarkerList);
// select style
mapboxMap.setStyle(Style.EMERALD);
// set camera
mapboxMap.setCameraPosition(new CameraPosition.Builder()
.target(new LatLng(45.1855569, 5.7215506))
.zoom(11)
.bearing(0)
.tilt(0)
.build());
// add markers
mapboxMap.addMarkers(mMarkerList);
// set map long click listeners
mapboxMap.setOnMapLongClickListener(PressForMarkerActivity.this);
}
});
}
@Override
public void onMapLongClick(@NonNull LatLng point) {
final PointF pixel = mMapView.toScreenLocation(point);
PointF pixel = mMapboxMap.toScreenLocation(point);
String title = LAT_LON_FORMATTER.format(point.getLatitude()) + ", " + LAT_LON_FORMATTER.format(point.getLongitude());
String snippet = "X = " + (int) pixel.x + ", Y = " + (int) pixel.y;
@@ -76,52 +93,49 @@ public class PressForMarkerActivity extends AppCompatActivity implements MapView
.snippet(snippet);
mMarkerList.add(marker);
mMapView.addMarker(marker);
mMapboxMap.addMarker(marker);
}
/**
* Dispatch onStart() to all fragments. Ensure any created loaders are
* now started.
*/
@Override
protected void onStart() {
super.onStart();
mMapView.onStart();
}
@Override
public void onResume() {
super.onResume();
mMapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mMapView.onPause();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mMapView.onSaveInstanceState(outState);
outState.putParcelableArrayList(STATE_MARKER_LIST, mMarkerList);
}
@Override
protected void onStop() {
super.onStop();
mMapView.onStop();
}
// Called when our app goes into the background
@Override
public void onPause() {
super.onPause();
mMapView.onPause();
}
// Called when our app comes into the foreground
@Override
public void onResume() {
super.onResume();
mMapView.onResume();
}
@Override
protected void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}
// Called when the system is running low on memory
@Override
public void onLowMemory() {
super.onLowMemory();
mMapView.onLowMemory();
}

View File

@@ -1,18 +1,26 @@
package com.mapbox.mapboxsdk.testapp;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
public class TiltActivity extends AppCompatActivity {
private MapView mMapView = null;
private final static LatLng WASHINGTON_DC = new LatLng(38.90252, -77.02291);
private MapView mMapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -28,15 +36,34 @@ public class TiltActivity extends AppCompatActivity {
actionBar.setDisplayShowHomeEnabled(true);
}
LatLng dc = new LatLng(38.90252, -77.02291);
// Set up the map
mMapView = (MapView) findViewById(R.id.tiltMapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.setStyleUrl(Style.MAPBOX_STREETS);
mMapView.setLatLng(dc);
mMapView.setZoom(11);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.MAPBOX_STREETS);
// Move camera to Washington DC
CameraPosition normalCameraPosition = new CameraPosition.Builder()
.target(WASHINGTON_DC)
.zoom(11)
.bearing(0)
.tilt(0)
.build();
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(normalCameraPosition));
// Animate camera tilting
CameraPosition tiltedCameraPosition = new CameraPosition.Builder()
.target(WASHINGTON_DC)
.zoom(11)
.bearing(0)
.tilt(45.0f)
.build();
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(tiltedCameraPosition), 10000);
}
});
}
@Override
@@ -52,7 +79,7 @@ public class TiltActivity extends AppCompatActivity {
}
@Override
public void onPause() {
public void onPause() {
super.onPause();
mMapView.onPause();
}
@@ -61,9 +88,6 @@ public class TiltActivity extends AppCompatActivity {
public void onResume() {
super.onResume();
mMapView.onResume();
// Tilt Map 45 degrees over 10 seconds
mMapView.setTilt(45.0, 10000l);
}
@Override

View File

@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.testapp;
import android.graphics.RectF;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
@@ -10,15 +11,21 @@ import android.view.MenuItem;
import android.view.View;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.CoordinateBounds;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
public class VisibleCoordinateBoundsActivity extends AppCompatActivity {
private MapView mMapView;
private static final LatLng LOS_ANGELES = new LatLng(34.053940, -118.242622);
private static final LatLng NEW_YORK = new LatLng(40.712730, -74.005953);
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -36,35 +43,37 @@ public class VisibleCoordinateBoundsActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.setStyle(Style.DARK);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.DARK);
mapboxMap.setAllGesturesEnabled(false);
final LatLng losAngeles = new LatLng(34.053940, -118.242622);
final LatLng newYork = new LatLng(40.712730, -74.005953);
mapboxMap.addMarker(new MarkerOptions()
.title("Los Angeles")
.snippet("City Hall")
.position(LOS_ANGELES));
mMapView.addMarker(new MarkerOptions()
.title("Los Angeles")
.snippet("City Hall")
.position(losAngeles));
mapboxMap.addMarker(new MarkerOptions()
.title("New York")
.snippet("City Hall")
.position(NEW_YORK));
mMapView.addMarker(new MarkerOptions()
.title("New York")
.snippet("City Hall")
.position(newYork));
Snackbar.make(findViewById(android.R.id.content), R.string.action_visible_bounds_explanation, Snackbar.LENGTH_INDEFINITE)
.setAction(android.R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View v) {
// Reposition coordinate bounds
LatLngBounds bounds = new LatLngBounds(NEW_YORK, LOS_ANGELES);
int padding = (int) getResources().getDimension(R.dimen.coordinatebounds_margin);
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding));
}
}).show();
}
});
Snackbar.make(findViewById(android.R.id.content), R.string.action_visible_bounds_explanation, Snackbar.LENGTH_INDEFINITE)
.setAction(android.R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View v) {
// Disable UserInput
mMapView.setScrollEnabled(false);
mMapView.setZoomEnabled(false);
// Reposition coordinate bounds
float margin = getResources().getDimension(R.dimen.coordinatebounds_margin);
mMapView.setVisibleCoordinateBounds(new CoordinateBounds(losAngeles, newYork), new RectF(margin, 0, margin, 0), true);
}
}).show();
}
@Override

View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M11,6c1.38,0 2.63,0.56 3.54,1.46L12,10h6V4l-2.05,2.05C14.68,4.78 12.93,4 11,4c-3.53,0 -6.43,2.61 -6.92,6H6.1c0.46,-2.28 2.48,-4 4.9,-4zm5.64,9.14c0.66,-0.9 1.12,-1.97 1.28,-3.14H15.9c-0.46,2.28 -2.48,4 -4.9,4 -1.38,0 -2.63,-0.56 -3.54,-1.46L10,12H4v6l2.05,-2.05C7.32,17.22 9.07,18 11,18c1.55,0 2.98,-0.51 4.14,-1.36L20,21.49 21.49,20l-4.85,-4.86z"/>
</vector>

View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFF"
android:pathData="M12,11.55C9.64,9.35 6.48,8 3,8v11c3.48,0 6.64,1.35 9,3.55 2.36,-2.19 5.52,-3.55 9,-3.55V8c-3.48,0 -6.64,1.35 -9,3.55zM12,8c1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3 1.34,3 3,3z"/>
</vector>

View File

@@ -22,7 +22,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mapbox.mapboxsdk.views.MapView
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@@ -12,7 +12,7 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<com.mapbox.mapboxsdk.views.MapView
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/cameraMapView"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@@ -12,7 +12,7 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<com.mapbox.mapboxsdk.views.MapView
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@@ -11,7 +11,7 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<com.mapbox.mapboxsdk.views.MapView
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="0dp"

View File

@@ -12,7 +12,7 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<com.mapbox.mapboxsdk.views.MapView
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@@ -12,7 +12,7 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<com.mapbox.mapboxsdk.views.MapView
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@@ -12,7 +12,7 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<com.mapbox.mapboxsdk.views.MapView
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/infoWindowConcurrentMapView"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@@ -29,7 +29,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mapbox.mapboxsdk.views.MapView
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mainMapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
@@ -11,16 +11,10 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<com.mapbox.mapboxsdk.views.MapView
<com.mapbox.mapboxsdk.maps.MapView
android:layout_below="@id/toolbar"
android:id="@+id/manualZoomMapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="wrap_content" />
<Button
android:id="@+id/zoomInButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/zoom_botton"
android:layout_gravity="right"/>
</LinearLayout>
</RelativeLayout>

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:style_url="@string/style_mapbox_streets"
app:center_latitude="38.897705003219784"
app:center_longitude="-77.03655168667463"
app:zoom="15" />
</LinearLayout>

View File

@@ -19,7 +19,7 @@
</android.support.v7.widget.Toolbar>
<com.mapbox.mapboxsdk.views.MapView
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<com.mapbox.mapboxsdk.maps.MapView
android:layout_below="@id/toolbar"
android:id="@+id/manualZoomMapView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>

View File

@@ -38,7 +38,7 @@
</android.support.v7.widget.Toolbar>
<com.mapbox.mapboxsdk.views.MapView
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@@ -12,7 +12,7 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<com.mapbox.mapboxsdk.views.MapView
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@@ -11,7 +11,7 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<com.mapbox.mapboxsdk.views.MapView
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/tiltMapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@@ -11,7 +11,7 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<com.mapbox.mapboxsdk.views.MapView
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@@ -4,7 +4,7 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.mapbox.mapboxsdk.views.MapView
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -18,7 +18,7 @@
android:layout_marginRight="5dp"
android:layout_marginTop="5dp">
<com.mapbox.mapboxsdk.views.MapView
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mini_map"
android:layout_width="100dp"
android:layout_height="100dp"

View File

@@ -72,6 +72,12 @@
android:title="@string/navdrawer_menu_title_individual_tests">
<menu>
<item
android:id="@+id/action_mapboxmap"
android:checkable="false"
android:icon="@drawable/ic_mapboxmap"
android:title="@string/action_mapboxmap"/>
<item
android:id="@+id/action_tilt"
android:checkable="false"
@@ -119,6 +125,12 @@
android:icon="@drawable/ic_filter_center_focus_24dp"
android:title="@string/action_manual_zoom" />
<item
android:id="@+id/action_minmax_zoom"
android:checkable="false"
android:icon="@drawable/ic_find_replace_24dp"
android:title="@string/action_minmax_zoom" />
<item
android:id="@+id/action_coordinate_change"
android:checkable="false"

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_zoom_in"
android:title="Zoom in"
mapbox:showAsAction="never" />
<item
android:id="@+id/action_zoom_out"
android:title="Zoom out"
mapbox:showAsAction="never" />
<item
android:id="@+id/action_zoom_by"
android:title="Zoom by 2"
mapbox:showAsAction="never" />
<item
android:id="@+id/action_zoom_to_point"
android:title="Zoom to point"
mapbox:showAsAction="never" />
<item
android:id="@+id/action_zoom_to"
android:title="Zoom to 4"
mapbox:showAsAction="never" />
</menu>

View File

@@ -4,6 +4,7 @@
<string name="app_name">Mapbox GL</string>
<!-- Test Activities -->
<string name="activity_mapboxmap">MapboxMap</string>
<string name="activity_tilt">Map Tilt</string>
<string name="activity_infowindow_adapter">InfoWindow Adapter</string>
<string name="activity_map_fragment">Map Fragment Activity</string>
@@ -32,11 +33,13 @@
<string name="action_custom_layer">Custom Layer</string>
<string name="action_debug">Cycle map debug options</string>
<string name="action_point_annotations">Toggle point annotations</string>
<string name="action_mapboxmap">MapboxMap</string>
<string name="action_info_window_adapter">InfoWindow Adapter</string>
<string name="action_tilt">Tilt</string>
<string name="action_map_fragment">MapFragment</string>
<string name="action_press_for_marker">Press For Marker</string>
<string name="action_manual_zoom">Manual Zoom</string>
<string name="action_minmax_zoom">Min/Max Zoom</string>
<string name="action_info_window">InfoWindow</string>
<string name="action_animate_coordinate_change">Animate Coordinate Change</string>
<string name="action_info_window_concurrent">InfoWindow (Concurrent)</string>

View File

@@ -1,15 +0,0 @@
import com.mapbox.mapboxsdk.geometry.LatLngZoom;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
public class LatLngZoomTest {
@Test
public void testSanity() {
LatLngZoom latLngZoom = new LatLngZoom(0.0, 0.0, 0.0);
assertNotNull("latLngZoom should not be null", latLngZoom);
}
}

View File

@@ -1,3 +1,5 @@
package com.mapbox.mapboxsdk.maps;
import com.mapbox.mapboxsdk.geometry.BoundingBox;
import com.mapbox.mapboxsdk.geometry.CoordinateSpan;
import com.mapbox.mapboxsdk.geometry.LatLng;

View File

@@ -1,3 +1,5 @@
package com.mapbox.mapboxsdk.maps;
import com.mapbox.mapboxsdk.geometry.CoordinateBounds;
import com.mapbox.mapboxsdk.geometry.LatLng;

View File

@@ -1,3 +1,5 @@
package com.mapbox.mapboxsdk.maps;
import com.mapbox.mapboxsdk.geometry.CoordinateRegion;
import com.mapbox.mapboxsdk.geometry.CoordinateSpan;
import com.mapbox.mapboxsdk.geometry.LatLng;

View File

@@ -1,3 +1,5 @@
package com.mapbox.mapboxsdk.maps;
import com.mapbox.mapboxsdk.geometry.CoordinateSpan;
import org.junit.Test;

View File

@@ -1,3 +1,5 @@
package com.mapbox.mapboxsdk.maps;
import android.location.Location;
import com.mapbox.mapboxsdk.geometry.LatLng;

View File

@@ -0,0 +1,235 @@
package com.mapbox.mapboxsdk.maps;
import android.util.Log;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.lang.reflect.Constructor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class MapboxMapTest {
private MapboxMap mMapboxMap;
@InjectMocks
MapView mMapView = mock(MapView.class);
@Mock
MapboxMap.OnMarkerClickListener mOnMarkerClickListener;
@Before
public void beforeTest() {
MockitoAnnotations.initMocks(this);
mMapboxMap = new MapboxMap(mMapView);
}
@Test
public void testSanity() {
assertNotNull("mMapboxMap should not be null", mMapboxMap);
}
@Test
public void testCompassEnabled() {
mMapboxMap.setCompassEnabled(true);
assertTrue("CompassEnabled should be true", mMapboxMap.isCompassEnabled());
}
@Test
public void testCompassDisabled() {
mMapboxMap.setCompassEnabled(false);
assertFalse("CompassbEnabled should be false", mMapboxMap.isCompassEnabled());
}
@Test
public void testScrollEnabled() {
mMapboxMap.setScrollEnabled(true);
assertTrue("ScrollEnabled should be true", mMapboxMap.isScrollEnabled());
}
@Test
public void testScrollDisabled() {
mMapboxMap.setScrollEnabled(false);
assertFalse("ScrollEnabled should be false", mMapboxMap.isScrollEnabled());
}
@Test
public void testRotateEnabled() {
mMapboxMap.setRotateEnabled(true);
assertTrue("RotateEnabled should be true", mMapboxMap.isRotateEnabled());
}
@Test
public void testRotateDisabled() {
mMapboxMap.setRotateEnabled(false);
assertFalse("RotateDisabled should be false", mMapboxMap.isRotateEnabled());
}
@Test
public void testZoomEnabled() {
mMapboxMap.setZoomEnabled(true);
assertTrue("ZoomEnabled should be true", mMapboxMap.isZoomEnabled());
}
@Test
public void testZoomDisabled() {
mMapboxMap.setZoomEnabled(false);
assertFalse("ZoomEnabled should be false", mMapboxMap.isZoomEnabled());
}
@Test
public void testZoomControlsEnabled() {
mMapboxMap.setZoomControlsEnabled(true);
assertTrue("ZoomControlsEnabled should be true", mMapboxMap.isZoomControlsEnabled());
}
@Test
public void testZoomControlsDisabled() {
mMapboxMap.setZoomControlsEnabled(false);
assertFalse("ZoomControlsEnabled should be false", mMapboxMap.isZoomControlsEnabled());
}
@Test
public void testTiltEnabled() {
mMapboxMap.setTiltEnabled(true);
assertTrue("TiltEnabled should be true", mMapboxMap.isTiltEnabled());
}
@Test
public void testTiltDisabled() {
mMapboxMap.setTiltEnabled(false);
assertFalse("TiltEnabled should be false", mMapboxMap.isTiltEnabled());
}
@Test
public void testConcurrentInfoWindowEnabled() {
mMapboxMap.setAllowConcurrentMultipleOpenInfoWindows(true);
assertTrue("ConcurrentWindows should be true", mMapboxMap.isAllowConcurrentMultipleOpenInfoWindows());
}
@Test
public void testConcurrentInfoWindowDisabled() {
mMapboxMap.setAllowConcurrentMultipleOpenInfoWindows(false);
assertFalse("ConcurrentWindows should be false", mMapboxMap.isAllowConcurrentMultipleOpenInfoWindows());
}
@Test
public void testMyLocationEnabled() {
try {
mMapboxMap.setMyLocationEnabled(true);
assertTrue("MyLocationEnabled should be true", mMapboxMap.isMyLocationEnabled());
} catch (SecurityException e) {
assertTrue(false);
}
}
@Test
public void testMyLocationDisabled() {
try {
mMapboxMap.setMyLocationEnabled(false);
assertFalse("MyLocationEnabled should be false", mMapboxMap.isMyLocationEnabled());
} catch (SecurityException e) {
assertTrue(false);
}
}
@Test
public void testStyleUrl() {
mMapboxMap.setStyleUrl("somestyle");
assertEquals("StyleUrl should be same", "somestyle", mMapboxMap.getStyleUrl());
}
@Test
public void testStyle() {
mMapboxMap.setStyle(Style.MAPBOX_STREETS);
assertEquals("Style should be same", Style.MAPBOX_STREETS, mMapboxMap.getStyleUrl());
}
@Test
public void testCameraPosition() {
CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
mMapboxMap.setCameraPosition(position);
assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition());
}
@Test
public void testMoveCamera() {
CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(position));
assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition());
}
@Test
public void testAnimateCamera() {
CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position));
assertEquals("CameraPosition should be same", position , mMapboxMap.getCameraPosition());
}
@Test
public void testAnimateCameraWithCallbackParameter() {
CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), null);
assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition());
}
@Test
public void testAnimateCameraWithDurationParameter() {
CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 0);
assertEquals("CameraPosition should be same",position, mMapboxMap.getCameraPosition());
}
@Test
public void testAnimateCameraWithDurationAndCallbackParameter() {
CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 0, null);
assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition());
}
@Test
public void testEaseCamera() {
CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
mMapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(position), 1000);
assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition());
}
@Test
public void testEaseCameraWithCallbackParameter() {
CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
mMapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(position), 1000, null);
assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition());
}
@Test
public void testOnMarkerClick() {
mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener);
Marker marker = new MarkerOptions().getMarker();
when(mOnMarkerClickListener.onMarkerClick(marker)).thenReturn(true);
mMapboxMap.selectMarker(marker);
verify(mOnMarkerClickListener, times(1)).onMarkerClick(marker);
}
}

View File

@@ -1,3 +1,5 @@
package com.mapbox.mapboxsdk.maps;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;

View File

@@ -1,3 +1,5 @@
package com.mapbox.mapboxsdk.maps;
import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.annotations.Polyline;

View File

@@ -1,3 +1,5 @@
package com.mapbox.mapboxsdk.maps;
import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;

View File

@@ -1,3 +1,5 @@
package com.mapbox.mapboxsdk.maps;
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
import org.junit.Test;