[android] #4166 - move style url to map view for improved async loading

This commit is contained in:
Tobrun
2016-03-02 11:21:03 +01:00
parent fd123de8ad
commit d994f2de0f
22 changed files with 130 additions and 88 deletions

View File

@@ -47,7 +47,6 @@ public class CameraActivity extends AppCompatActivity {
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
// set a style
mapboxMap.setStyle(Style.MAPBOX_STREETS);
mapboxMap.setOnCameraChangeListener(new MapboxMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition position) {

View File

@@ -46,7 +46,6 @@ public class CoordinateChangeActivity extends AppCompatActivity {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
mapboxMap.setStyle(Style.MAPBOX_STREETS);
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(getNextLatLng(), 16));
UiSettings uiSettings = mapboxMap.getUiSettings();

View File

@@ -65,12 +65,11 @@ public class DoubleMapActivity extends AppCompatActivity {
// MapView large
mMapView = (MapView) view.findViewById(R.id.mapView);
mMapView.setStyleUrl(Style.DARK);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.DARK);
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(18));
try {
TrackingSettings settings = mapboxMap.getTrackingSettings();
@@ -84,11 +83,11 @@ public class DoubleMapActivity extends AppCompatActivity {
// MapView mini
mMapViewMini = (MapView) view.findViewById(R.id.mini_map);
mMapViewMini.setStyle(Style.LIGHT);
mMapViewMini.onCreate(savedInstanceState);
mMapViewMini.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.LIGHT);
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(4));
UiSettings uiSettings = mapboxMap.getUiSettings();

View File

@@ -55,7 +55,6 @@ public class DynamicMarkerChangeActivity extends AppCompatActivity {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
mapboxMap.setStyle(Style.MAPBOX_STREETS);
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.506675, -0.128699), 10));
// Create marker

View File

@@ -55,14 +55,12 @@ public class GeocoderActivity extends AppCompatActivity {
mapView = (MapView) findViewById(R.id.mapView);
mapView.setAccessToken(ApiAccess.getToken(this));
mapView.setStyle(Style.EMERALD);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
// Style
mapboxMap.setStyle(Style.EMERALD);
// Camera position
mapboxMap.setCameraPosition(
new CameraPosition.Builder()

View File

@@ -49,11 +49,14 @@ public class InfoWindowActivity extends AppCompatActivity {
.snippet("H St NW with 15th St NW")
.position(new LatLng(38.9002073, -77.03364419)));
mapboxMap.addMarker(new MarkerOptions()
Marker marker = mapboxMap.addMarker(new MarkerOptions()
.title("White House")
.snippet("The official residence and principal workplace of the President of the United States, located at 1600 Pennsylvania Avenue NW in Washington, D.C. It has been the residence of every U.S. president since John Adams in 1800.")
.position(new LatLng(38.897705003219784, -77.03655168667463)));
// open InfoWindow at startup!
mapboxMap.selectMarker(marker);
mapboxMap.addMarker(new MarkerOptions().title("Intersection")
.snippet("E St NW with 17th St NW")
.position(new LatLng(38.8954236, -77.0394623)));
@@ -61,7 +64,7 @@ public class InfoWindowActivity extends AppCompatActivity {
mapboxMap.setOnInfoWindowCloseListener(new MapboxMap.OnInfoWindowCloseListener() {
@Override
public void onInfoWindowClose(Marker marker) {
Toast.makeText(getApplicationContext(),"OnClose: "+marker.getTitle(),Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "OnClose: " + marker.getTitle(), Toast.LENGTH_LONG).show();
}
});
@@ -97,7 +100,7 @@ public class InfoWindowActivity extends AppCompatActivity {
mapboxMap.setOnInfoWindowLongClickListener(new MapboxMap.OnInfoWindowLongClickListener() {
@Override
public void onInfoWindowLongClick(Marker marker) {
Toast.makeText(getApplicationContext(),"OnLongClick: "+marker.getTitle(),Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "OnLongClick: " + marker.getTitle(), Toast.LENGTH_LONG).show();
}
});

View File

@@ -43,6 +43,7 @@ public class LatLngBoundsActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.setStyle(Style.DARK);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override

View File

@@ -136,6 +136,7 @@ public class MainActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.mainMapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
changeMapStyle(mSelectedStyle);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
@@ -229,7 +230,6 @@ public class MainActivity extends AppCompatActivity {
}
});
changeMapStyle(mSelectedStyle);
}
});
}
@@ -496,32 +496,32 @@ public class MainActivity extends AppCompatActivity {
private boolean changeMapStyle(int id) {
switch (id) {
case R.id.actionStyleMapboxStreets:
mMapboxMap.setStyle(Style.MAPBOX_STREETS);
mMapView.setStyleUrl(Style.MAPBOX_STREETS);
mSelectedStyle = id;
return true;
case R.id.actionStyleEmerald:
mMapboxMap.setStyle(Style.EMERALD);
mMapView.setStyleUrl(Style.EMERALD);
mSelectedStyle = id;
return true;
case R.id.actionStyleLight:
mMapboxMap.setStyle(Style.LIGHT);
mMapView.setStyleUrl(Style.LIGHT);
mSelectedStyle = id;
return true;
case R.id.actionStyleDark:
mMapboxMap.setStyle(Style.DARK);
mMapView.setStyleUrl(Style.DARK);
mSelectedStyle = id;
return true;
case R.id.actionStyleSatellite:
mMapboxMap.setStyle(Style.SATELLITE);
mMapView.setStyleUrl(Style.SATELLITE);
mSelectedStyle = id;
return true;
case R.id.actionStyleSatelliteStreets:
mMapboxMap.setStyle(Style.SATELLITE_STREETS);
mMapView.setStyleUrl(Style.SATELLITE_STREETS);
mSelectedStyle = id;
return true;

View File

@@ -39,12 +39,12 @@ public class ManualZoomActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.manualZoomMapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.setStyleUrl(Style.SATELLITE_STREETS);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
mMapboxMap.setStyle(Style.SATELLITE_STREETS);
UiSettings uiSettings = mMapboxMap.getUiSettings();
uiSettings.setAllGesturesEnabled(false);

View File

@@ -49,8 +49,6 @@ public class MapFragmentActivity extends AppCompatActivity {
new CameraPosition.Builder()
.target(new LatLng(48.861431, 2.334166))
.zoom(10)
.bearing(0)
.tilt(0)
.build()));
}
});

View File

@@ -43,18 +43,18 @@ public class MapPaddingActivity extends AppCompatActivity {
mMapView.setTag(true);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
mapboxMap.setStyle(Style.MAPBOX_STREETS);
moveToBangalore();
int paddingLeft = (int) getResources().getDimension(R.dimen.map_padding_left);
int paddingBottom = (int) getResources().getDimension(R.dimen.map_padding_bottom);
int paddingRight = (int) getResources().getDimension(R.dimen.map_padding_right);
mapboxMap.setPadding(paddingLeft, toolbar.getHeight(), paddingRight, paddingBottom);
moveToBangalore();
}
});
}
@@ -123,14 +123,16 @@ public class MapPaddingActivity extends AppCompatActivity {
private void moveToBangalore() {
toggleGps(false);
LatLng bangalore = new LatLng(12.9810816, 77.6368034);
mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.zoom(16)
.target(bangalore)
.bearing(40)
.tilt(45)
.build()));
CameraPosition cameraPosition = new CameraPosition.Builder()
.zoom(16)
.target(bangalore)
.bearing(40)
.tilt(45)
.build();
mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
mMapboxMap.addMarker(new MarkerOptions().title("Center map").position(bangalore));
}

View File

@@ -37,24 +37,22 @@ public class MapboxMapActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.setStyle(Style.SATELLITE_STREETS);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.SATELLITE_STREETS);
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.target(new LatLng(43.876550, -103.454791))
.zoom(14)
.bearing(0)
.tilt(0)
.build()));
}
});
Snackbar.make(findViewById(android.R.id.content),
"Demo MapboxMap API.",
"Demo MapboxMap API",
Snackbar.LENGTH_INDEFINITE).show();
}

View File

@@ -39,12 +39,12 @@ public class MaxMinZoomActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.manualZoomMapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.setStyle(Style.SATELLITE_STREETS);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
mMapboxMap.setStyle(Style.SATELLITE_STREETS);
UiSettings uiSettings = mapboxMap.getUiSettings();
uiSettings.setMinZoom(3);

View File

@@ -73,6 +73,7 @@ public class OfflineActivity extends AppCompatActivity
// Set up map
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.setStyle(Style.MAPBOX_STREETS);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
@@ -80,9 +81,6 @@ public class OfflineActivity extends AppCompatActivity
Log.d(LOG_TAG, "Map is ready");
mMapboxMap = mapboxMap;
// Set style
mapboxMap.setStyle(Style.MAPBOX_STREETS);
// Set initial position to UNHQ in NYC
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()

View File

@@ -47,6 +47,7 @@ public class PressForMarkerActivity extends AppCompatActivity implements MapboxM
// Adding MapView programmatically
mMapView = new MapView(this);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.setStyle(Style.EMERALD);
mMapView.onCreate(savedInstanceState);
((ViewGroup) findViewById(R.id.activity_container)).addView(mMapView);
@@ -61,15 +62,10 @@ public class PressForMarkerActivity extends AppCompatActivity implements MapboxM
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
// select style
mapboxMap.setStyle(Style.EMERALD);
// set camera
mapboxMap.setCameraPosition(new CameraPosition.Builder()
.target(new LatLng(45.1855569, 5.7215506))
.zoom(11)
.bearing(0)
.tilt(0)
.build());
// add markers

View File

@@ -53,12 +53,11 @@ public class ScrollByActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setTag(true);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.setStyleUrl(Style.MAPBOX_STREETS);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.MAPBOX_STREETS);
UiSettings uiSettings = mapboxMap.getUiSettings();
uiSettings.setLogoEnabled(false);
uiSettings.setAttributionEnabled(false);

View File

@@ -43,14 +43,11 @@ public class TiltActivity extends AppCompatActivity {
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.MAPBOX_STREETS);
// Move camera to Washington DC
CameraPosition normalCameraPosition = new CameraPosition.Builder()
.target(WASHINGTON_DC)
.zoom(11)
.bearing(0)
.tilt(0)
.build();
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(normalCameraPosition));
@@ -58,7 +55,6 @@ public class TiltActivity extends AppCompatActivity {
CameraPosition tiltedCameraPosition = new CameraPosition.Builder()
.target(WASHINGTON_DC)
.zoom(11)
.bearing(0)
.tilt(45.0f)
.build();
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(tiltedCameraPosition), 10000);

View File

@@ -231,22 +231,6 @@ public class MapboxMapTest {
mMapboxMap.setOnMyLocationTrackingModeChangeListener(mMyLocationTrackingModeChangeListener);
assertEquals("MyLocationTrackigChangeListener should match",mMyLocationTrackingModeChangeListener, mMapboxMap.getOnMyLocationTrackingModeChangeListener());
}
//
// Style
//
@Test
public void testStyleUrl() {
mMapboxMap.setStyleUrl("somestyle");
assertEquals("StyleUrl should be same", "somestyle", mMapboxMap.getStyleUrl());
}
@Test
public void testStyle() {
mMapboxMap.setStyle(Style.MAPBOX_STREETS);
assertEquals("Style should be same", Style.MAPBOX_STREETS, mMapboxMap.getStyleUrl());
}
//
// CameraPosition