[android] #4318 - move min/max zoom level to MapboxMap

This commit is contained in:
Tobrun
2016-03-15 11:59:57 -04:00
parent f823021e0d
commit 93123e4d0e
8 changed files with 113 additions and 111 deletions

View File

@@ -250,7 +250,7 @@ public final class CameraUpdateFactory {
float scaleY = (uiSettings.getHeight() - padding.top - padding.bottom) / height;
float minScale = scaleX < scaleY ? scaleX : scaleY;
double zoom = projection.calculateZoom(minScale);
zoom = MathUtils.clamp(zoom, (float) uiSettings.getMinZoom(), (float) uiSettings.getMaxZoom());
zoom = MathUtils.clamp(zoom, (float) mapboxMap.getMinZoom(), (float) mapboxMap.getMaxZoom());
// Calculate the center point
PointF paddedNEPixel = new PointF(nePixel.x + padding.right / minScale, nePixel.y + padding.top / minScale);

View File

@@ -265,8 +265,8 @@ public class MapView extends FrameLayout {
uiSettings.setZoomControlsEnabled(options.getZoomControlsEnabled());
// Zoom
uiSettings.setMaxZoom(options.getMaxZoom());
uiSettings.setMinZoom(options.getMinZoom());
mMapboxMap.setMaxZoom(options.getMaxZoom());
mMapboxMap.setMinZoom(options.getMinZoom());
// Compass
uiSettings.setCompassEnabled(options.getCompassEnabled());

View File

@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.maps;
import android.location.Location;
import android.os.SystemClock;
import android.support.annotation.FloatRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
@@ -72,6 +73,9 @@ public class MapboxMap {
private MapboxMap.OnFpsChangedListener mOnFpsChangedListener;
private MapboxMap.OnCameraChangeListener mOnCameraChangeListener;
private double mMaxZoomLevel = -1;
private double mMinZoomLevel = -1;
MapboxMap(@NonNull MapView mapView) {
mMapView = mapView;
mMapView.addOnMapChangedListener(new MapChangeCameraPositionListener());
@@ -83,6 +87,78 @@ public class MapboxMap {
mInfoWindows = new ArrayList<>();
}
//
// MinZoom
//
/**
* <p>
* Sets the minimum zoom level the map can be displayed at.
* </p>
*
* @param minZoom The new minimum zoom level.
*/
@UiThread
public void setMinZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double minZoom) {
if ((minZoom < MapboxConstants.MINIMUM_ZOOM) || (minZoom > MapboxConstants.MAXIMUM_ZOOM)) {
Log.e(MapboxConstants.TAG, "Not setting minZoom, value is in unsupported range: " + minZoom);
return;
}
mMinZoomLevel = minZoom;
mMapView.setMinZoom(minZoom);
}
/**
* <p>
* Gets the maximum zoom level the map can be displayed at.
* </p>
*
* @return The minimum zoom level.
*/
@UiThread
public double getMinZoom() {
if (mMinZoomLevel == -1) {
return mMinZoomLevel = mMapView.getMinZoom();
}
return mMinZoomLevel;
}
//
// MaxZoom
//
/**
* <p>
* Sets the maximum zoom level the map can be displayed at.
* </p>
*
* @param maxZoom The new maximum zoom level.
*/
@UiThread
public void setMaxZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double maxZoom) {
if ((maxZoom < MapboxConstants.MINIMUM_ZOOM) || (maxZoom > MapboxConstants.MAXIMUM_ZOOM)) {
Log.e(MapboxConstants.TAG, "Not setting maxZoom, value is in unsupported range: " + maxZoom);
return;
}
mMaxZoomLevel = maxZoom;
mMapView.setMaxZoom(maxZoom);
}
/**
* <p>
* Gets the maximum zoom level the map can be displayed at.
* </p>
*
* @return The maximum zoom level.
*/
@UiThread
public double getMaxZoom() {
if (mMaxZoomLevel == -1) {
return mMaxZoomLevel = mMapView.getMaxZoom();
}
return mMaxZoomLevel;
}
//
// UiSettings
//

View File

@@ -26,9 +26,6 @@ public class UiSettings {
private boolean zoomControlsEnabled;
private boolean scrollGesturesEnabled;
private double maxZoomLevel = -1;
private double minZoomLevel = -1;
UiSettings(@NonNull MapView mapView) {
this.mapView = mapView;
this.compassSettings = new ViewSettings();
@@ -36,70 +33,6 @@ public class UiSettings {
this.attributionSettings = new ViewSettings();
}
/**
* <p>
* Sets the minimum zoom level the map can be displayed at.
* </p>
*
* @param minZoom The new minimum zoom level.
*/
@UiThread
public void setMinZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double minZoom) {
if ((minZoom < MapboxConstants.MINIMUM_ZOOM) || (minZoom > MapboxConstants.MAXIMUM_ZOOM)) {
Log.e(MapboxConstants.TAG, "Not setting minZoom, value is in unsupported range: " + minZoom);
return;
}
minZoomLevel = minZoom;
mapView.setMinZoom(minZoom);
}
/**
* <p>
* Gets the maximum zoom level the map can be displayed at.
* </p>
*
* @return The minimum zoom level.
*/
@UiThread
public double getMinZoom() {
if (minZoomLevel == -1) {
return minZoomLevel = mapView.getMinZoom();
}
return minZoomLevel;
}
/**
* <p>
* Sets the maximum zoom level the map can be displayed at.
* </p>
*
* @param maxZoom The new maximum zoom level.
*/
@UiThread
public void setMaxZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double maxZoom) {
if ((maxZoom < MapboxConstants.MINIMUM_ZOOM) || (maxZoom > MapboxConstants.MAXIMUM_ZOOM)) {
Log.e(MapboxConstants.TAG, "Not setting maxZoom, value is in unsupported range: " + maxZoom);
return;
}
maxZoomLevel = maxZoom;
mapView.setMaxZoom(maxZoom);
}
/**
* <p>
* Gets the maximum zoom level the map can be displayed at.
* </p>
*
* @return The maximum zoom level.
*/
@UiThread
public double getMaxZoom() {
if (maxZoomLevel == -1) {
return maxZoomLevel = mapView.getMaxZoom();
}
return maxZoomLevel;
}
/**
* <p>
* Enables or disables the compass. The compass is an icon on the map that indicates the

View File

@@ -15,7 +15,6 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
public class MaxMinZoomActivity extends AppCompatActivity {
@@ -45,10 +44,8 @@ public class MaxMinZoomActivity extends AppCompatActivity {
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
UiSettings uiSettings = mapboxMap.getUiSettings();
uiSettings.setMinZoom(3);
uiSettings.setMaxZoom(5);
mMapboxMap.setMinZoom(3);
mMapboxMap.setMaxZoom(5);
mMapboxMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(-1.063510, 32.895425)));
}

View File

@@ -257,7 +257,7 @@ public class OfflineActivity extends AppCompatActivity
String styleURL = mMapboxMap.getStyleUrl();
LatLngBounds bounds = mMapboxMap.getProjection().getVisibleRegion().latLngBounds;
double minZoom = mMapboxMap.getCameraPosition().zoom;
double maxZoom = mMapboxMap.getUiSettings().getMaxZoom();
double maxZoom = mMapboxMap.getMaxZoom();
float pixelRatio = this.getResources().getDisplayMetrics().density;
OfflineTilePyramidRegionDefinition definition = new OfflineTilePyramidRegionDefinition(
styleURL, bounds, minZoom, maxZoom, pixelRatio);
@@ -346,6 +346,7 @@ public class OfflineActivity extends AppCompatActivity
mProgressBar.setIndeterminate(true);
mProgressBar.setVisibility(View.VISIBLE);
}
private void setPercentage(final int percentage) {
mProgressBar.setIndeterminate(false);
mProgressBar.setProgress(percentage);

View File

@@ -10,9 +10,7 @@ import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
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 org.junit.Before;
@@ -26,11 +24,9 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.matches;
import static org.mockito.Mockito.mock;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -108,6 +104,30 @@ public class MapboxMapTest {
assertNotNull("UiSettings should not be null", mMapboxMap.getUiSettings());
}
//
// MinZoomLevel
//
@Test
public void testMinZoom() {
double zoom = 10;
mMapboxMap.setMinZoom(zoom);
assertEquals("MinZoom should match", zoom, mMapboxMap.getMinZoom(), 0);
}
@Test
public void testMaxZoom() {
double zoom = 10;
mMapboxMap.setMaxZoom(zoom);
assertEquals("MaxZoom should match", zoom, mMapboxMap.getMaxZoom(), 0);
}
@Test
public void testInitialZoomLevels() {
assertEquals("MaxZoom should match", 0, mMapboxMap.getMaxZoom(), 0);
assertEquals("MinZoom should match", 0, mMapboxMap.getMinZoom(), 0);
}
//
// TrackingSettings
//
@@ -221,15 +241,15 @@ public class MapboxMapTest {
}
@Test
public void testOnBearingTrackingModeChangeListener(){
public void testOnBearingTrackingModeChangeListener() {
mMapboxMap.setOnMyBearingTrackingModeChangeListener(mMyBearingTrackingModeChangeListener);
assertEquals("MyBearingTrackingChangeListerner should match",mMyBearingTrackingModeChangeListener, mMapboxMap.getOnMyBearingTrackingModeChangeListener());
assertEquals("MyBearingTrackingChangeListerner should match", mMyBearingTrackingModeChangeListener, mMapboxMap.getOnMyBearingTrackingModeChangeListener());
}
@Test
public void testOnLocationTrackingModeChangeListener(){
public void testOnLocationTrackingModeChangeListener() {
mMapboxMap.setOnMyLocationTrackingModeChangeListener(mMyLocationTrackingModeChangeListener);
assertEquals("MyLocationTrackigChangeListener should match",mMyLocationTrackingModeChangeListener, mMapboxMap.getOnMyLocationTrackingModeChangeListener());
assertEquals("MyLocationTrackigChangeListener should match", mMyLocationTrackingModeChangeListener, mMapboxMap.getOnMyLocationTrackingModeChangeListener());
}
//
@@ -709,7 +729,6 @@ public class MapboxMapTest {
assertTrue("Selected markers should be empty", mMapboxMap.getSelectedMarkers().isEmpty());
}
//
// OnMarkerClick interface
//

View File

@@ -21,30 +21,6 @@ public class UiSettingsTest {
assertNotNull("uiSettings should not be null", uiSettings);
}
@Test
public void testMinZoom() {
double zoom = 10;
UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setMinZoom(zoom);
assertEquals("MinZoom should match", zoom, uiSettings.getMinZoom(), 0);
}
@Test
public void testMaxZoom() {
double zoom = 10;
UiSettings uiSettings = new UiSettings(mMapView);
uiSettings.setMaxZoom(zoom);
assertEquals("MaxZoom should match", zoom, uiSettings.getMaxZoom(), 0);
}
@Test
public void testInitialZoomLevels() {
//we are mocking MapView we expect a value of 0 to be returned
UiSettings uiSettings = new UiSettings(mMapView);
assertEquals("MaxZoom should match", 0, uiSettings.getMaxZoom(), 0);
assertEquals("MinZoom should match", 0, uiSettings.getMinZoom(), 0);
}
@Test
public void testCompassEnabled() {
UiSettings uiSettings = new UiSettings(mMapView);