Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] #4018 - migrated max/min zoom to UiSettings + added tests +…
Browse files Browse the repository at this point in the history
… update sample app
  • Loading branch information
tobrun committed Feb 18, 2016
1 parent e4fa181 commit 374f464
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ void setMinZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxCons
* @return The minimum zoom level.
*/
@UiThread
public double getMinZoom() {
double getMinZoom() {
return mNativeMapView.getMinZoom();
}

Expand All @@ -737,7 +737,7 @@ public double getMinZoom() {
* @param maxZoom The new maximum zoom level.
*/
@UiThread
public void setMaxZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double maxZoom) {
void setMaxZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double maxZoom) {
mNativeMapView.setMaxZoom(maxZoom);
}

Expand All @@ -749,7 +749,7 @@ public void setMaxZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = Map
* @return The maximum zoom level.
*/
@UiThread
public double getMaxZoom() {
double getMaxZoom() {
return mNativeMapView.getMaxZoom();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,66 +305,6 @@ private void invalidateCameraPosition() {
}
}

//
// ZOOM
//

/**
* <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;
}
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() {
return mMapView.getMinZoom();
}

/**
* <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;
}
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() {
return mMapView.getMaxZoom();
}

//
// Manual zoom controls
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.mapbox.mapboxsdk.maps;

import android.support.annotation.FloatRange;
import android.support.annotation.NonNull;
import android.support.annotation.UiThread;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.VideoView;

import com.mapbox.mapboxsdk.constants.MapboxConstants;

/**
* Settings for the user interface of a MapboxMap. To obtain this interface, call getUiSettings().
*/
Expand All @@ -23,13 +27,80 @@ 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();
this.logoSettings = new ViewSettings();
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
Expand Down Expand Up @@ -110,7 +181,7 @@ public int getCompassMarginLeft() {
* @return The top margin in pixels
*/
public int getCompassMarginTop() {
return compassSettings.getMargins()[1];
return compassSettings.getMargins()[1];
}

/**
Expand All @@ -119,7 +190,7 @@ public int getCompassMarginTop() {
* @return The right margin in pixels
*/
public int getCompassMarginRight() {
return compassSettings.getMargins()[2];
return compassSettings.getMargins()[2];
}

/**
Expand All @@ -128,7 +199,7 @@ public int getCompassMarginRight() {
* @return The bottom margin in pixels
*/
public int getCompassMarginBottom() {
return compassSettings.getMargins()[3];
return compassSettings.getMargins()[3];
}

/**
Expand All @@ -141,7 +212,7 @@ public int getCompassMarginBottom() {
*/
public void setLogoEnabled(boolean enabled) {
logoSettings.setEnabled(enabled);
mapView.setLogoVisibility(enabled );
mapView.setLogoVisibility(enabled);
}

/**
Expand Down Expand Up @@ -196,7 +267,7 @@ public void setLogoMargins(int left, int top, int right, int bottom) {
*
* @return The left margin in pixels
*/
public int getLogoMarginLeft(){
public int getLogoMarginLeft() {
return logoSettings.getMargins()[0];
}

Expand All @@ -205,7 +276,7 @@ public int getLogoMarginLeft(){
*
* @return The top margin in pixels
*/
public int getLogoMarginTop(){
public int getLogoMarginTop() {
return logoSettings.getMargins()[1];
}

Expand All @@ -214,7 +285,7 @@ public int getLogoMarginTop(){
*
* @return The right margin in pixels
*/
public int getLogoMarginRight(){
public int getLogoMarginRight() {
return logoSettings.getMargins()[2];
}

Expand All @@ -223,7 +294,7 @@ public int getLogoMarginRight(){
*
* @return The bottom margin in pixels
*/
public int getLogoMarginBottom(){
public int getLogoMarginBottom() {
return logoSettings.getMargins()[3];
}

Expand Down Expand Up @@ -292,7 +363,7 @@ public void setAttributionMargins(int left, int top, int right, int bottom) {
*
* @return The left margin in pixels
*/
public int getAttributionMarginLeft(){
public int getAttributionMarginLeft() {
return attributionSettings.getMargins()[0];
}

Expand All @@ -301,7 +372,7 @@ public int getAttributionMarginLeft(){
*
* @return The top margin in pixels
*/
public int getAttributionMarginTop(){
public int getAttributionMarginTop() {
return attributionSettings.getMargins()[1];
}

Expand All @@ -310,7 +381,7 @@ public int getAttributionMarginTop(){
*
* @return The right margin in pixels
*/
public int getAttributionMarginRight(){
public int getAttributionMarginRight() {
return attributionSettings.getMargins()[2];
}

Expand All @@ -319,7 +390,7 @@ public int getAttributionMarginRight(){
*
* @return The bottom margin in pixels
*/
public int getAttributionMarginBottom(){
public int getAttributionMarginBottom() {
return attributionSettings.getMargins()[3];
}

Expand Down Expand Up @@ -471,9 +542,9 @@ public void setAllGesturesEnabled(boolean enabled) {
setZoomGesturesEnabled(enabled);
}

public void invalidate(){
public void invalidate() {
mapView.setLogoMargins(getLogoMarginLeft(), getLogoMarginTop(), getLogoMarginRight(), getLogoMarginBottom());
mapView.setCompassMargins(getCompassMarginLeft(),getCompassMarginTop(),getCompassMarginRight(),getCompassMarginBottom());
mapView.setCompassMargins(getCompassMarginLeft(), getCompassMarginTop(), getCompassMarginRight(), getCompassMarginBottom());
mapView.setAttributionMargins(getAttributionMarginLeft(), getAttributionMarginTop(), getAttributionMarginRight(), getAttributionMarginBottom());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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.utils.ApiAccess;

public class MaxMinZoomActivity extends AppCompatActivity {
Expand Down Expand Up @@ -44,8 +45,11 @@ protected void onCreate(Bundle savedInstanceState) {
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
mMapboxMap.setStyle(Style.SATELLITE_STREETS);
mMapboxMap.setMinZoom(3);
mMapboxMap.setMaxZoom(5);

UiSettings uiSettings = mapboxMap.getUiSettings();
uiSettings.setMinZoom(3);
uiSettings.setMaxZoom(5);

mMapboxMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(-1.063510, 32.895425)));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,30 @@ public void testSanity() {
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);
Expand Down Expand Up @@ -204,7 +228,6 @@ public void testAllGesturesDisabled() {
assertEquals("Scroll gesture should be disabled", false, uiSettings.isScrollGesturesEnabled());
}


@Test
public void testInvalidate() {
UiSettings uiSettings = new UiSettings(mMapView);
Expand Down

0 comments on commit 374f464

Please sign in to comment.