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

3761 add map padding #3942

Merged
merged 1 commit into from
Feb 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,10 @@ public class MapView extends FrameLayout {
private boolean mZoomStarted = false;
private boolean mQuickZoom = false;

/*
private int mContentPaddingLeft;
private int mContentPaddingTop;
private int mContentPaddingRight;
private int mContentPaddingBottom;
*/

@UiThread
public MapView(@NonNull Context context) {
Expand Down Expand Up @@ -368,9 +366,9 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
}

//noinspection ResourceType
mMapboxMap.setMyLocationTrackingMode(savedInstanceState.getInt(MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE, MyLocationTracking.TRACKING_NONE));
setMyLocationTrackingMode(savedInstanceState.getInt(MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE, MyLocationTracking.TRACKING_NONE));
//noinspection ResourceType
mMapboxMap.setMyBearingTrackingMode(savedInstanceState.getInt(MapboxConstants.STATE_MY_BEARING_TRACKING_MODE, MyBearingTracking.NONE));
setMyBearingTrackingMode(savedInstanceState.getInt(MapboxConstants.STATE_MY_BEARING_TRACKING_MODE, MyBearingTracking.NONE));
} else {
// Force a check for Telemetry
validateTelemetryServiceConfigured();
Expand Down Expand Up @@ -414,8 +412,8 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putString(MapboxConstants.STATE_ACCESS_TOKEN, mMapboxMap.getAccessToken());
outState.putLong(MapboxConstants.STATE_DEFAULT_TRANSITION_DURATION, mNativeMapView.getDefaultTransitionDuration());
outState.putBoolean(MapboxConstants.STATE_MY_LOCATION_ENABLED, mMapboxMap.isMyLocationEnabled());
outState.putInt(MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE, mMapboxMap.getMyLocationTrackingMode());
outState.putInt(MapboxConstants.STATE_MY_BEARING_TRACKING_MODE, mMapboxMap.getMyBearingTrackingMode());
outState.putInt(MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE, getMyLocationTrackingMode());
outState.putInt(MapboxConstants.STATE_MY_BEARING_TRACKING_MODE, getMyBearingTrackingMode());

// UiSettings
UiSettings uiSettings = mMapboxMap.getUiSettings();
Expand Down Expand Up @@ -648,6 +646,46 @@ void resetNorth() {
mNativeMapView.resetNorth();
}

//
// Content padding
//

/**
* Return The current content padding left of the map view viewport.
*
* @return The current content padding left
*/
int getContentPaddingLeft() {
return mContentPaddingLeft;
}

/**
* Return The current content padding left of the map view viewport.
*
* @return The current content padding left
*/
int getContentPaddingTop() {
return mContentPaddingTop;
}

/**
* Return The current content padding left of the map view viewport.
*
* @return The current content padding right
*/
int getContentPaddingRight() {
return mContentPaddingRight;
}

/**
* Return The current content padding left of the map view viewport.
*
* @return The current content padding bottom
*/
int getContentPaddingBottom() {
return mContentPaddingBottom;
}

//
// Zoom
//
Expand All @@ -663,51 +701,6 @@ void resetNorth() {
return mNativeMapView.getZoom();
}

// /**
// * Return The current content padding left of the map view viewport.
// *
// * @return The current content padding left
// */
///*
// public int getContentPaddingLeft() {
// return mContentPaddingLeft;
// }
//*/
//
// /**
// * Return The current content padding left of the map view viewport.
// *
// * @return The current content padding left
// */
///*
// public int getContentPaddingTop() {
// return mContentPaddingTop;
// }
//*/
//
// /**
// * Return The current content padding left of the map view viewport.
// *
// * @return The current content padding left
// */
///*
// public int getContentPaddingRight() {
// return mContentPaddingRight;
// }
//*/
//
// /**
// * Return The current content padding left of the map view viewport.
// *
// * @param zoomLevel The new zoom level.
// * @param animated If true, animates the change. If false, immediately changes the map.
// * @see MapboxMap#MAXIMUM_ZOOM
// */
///*
// public int getContentPaddingBottom() {
// return mContentPaddingBottom;
//*/

/**
* <p>
* Sets the minimum zoom level the map can be displayed at.
Expand Down Expand Up @@ -1372,6 +1365,35 @@ private int getTopOffsetPixelsForIcon(Icon icon) {
* mScreenDensity);
}

/**
* Sets the distance from the edges of the map view’s frame to the edges of the map
* view’s logical viewport.
* <p/>
* When the value of this property is equal to {0,0,0,0}, viewport
* properties such as `centerCoordinate` assume a viewport that matches the map
* view’s frame. Otherwise, those properties are inset, excluding part of the
* frame from the viewport. For instance, if the only the top edge is inset, the
* map center is effectively shifted downward.
*
* @param left The left margin in pixels.
* @param top The top margin in pixels.
* @param right The right margin in pixels.
* @param bottom The bottom margin in pixels.
*/
@UiThread
void setContentPadding(int left, int top, int right, int bottom) {
if (left == mContentPaddingLeft && top == mContentPaddingTop && right == mContentPaddingRight && bottom == mContentPaddingBottom) {
return;
}

mContentPaddingLeft = left;
mContentPaddingTop = top;
mContentPaddingRight = right;
mContentPaddingBottom = bottom;

mNativeMapView.setContentPadding(top / mScreenDensity, left / mScreenDensity, bottom / mScreenDensity, right / mScreenDensity);
}

/**
* <p>
* Returns the distance spanned by one pixel at the specified latitude and current zoom level.
Expand Down Expand Up @@ -1750,8 +1772,9 @@ public boolean onDoubleTapEvent(MotionEvent e) {
// Zoom in on gesture
zoom(true, e.getX(), e.getY());
} else {
// Zoom in on center map
zoom(true, getWidth() / 2, getHeight() / 2);
// Zoom in on user location view
PointF centerPoint = mUserLocationView.getMarkerScreenPoint();
zoom(true, centerPoint.x, centerPoint.y);
}
break;
}
Expand Down Expand Up @@ -1852,7 +1875,9 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
}

// reset tracking modes if gesture occurs
resetTrackingModes();
if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) {
resetTrackingModes();
}

// Fling the map
float ease = 0.25f;
Expand Down Expand Up @@ -1884,8 +1909,10 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float d
return false;
}

// reset tracking modes if gesture occurs
resetTrackingModes();
if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) {
// reset tracking modes if gesture occurs
resetTrackingModes();
}

// Cancel any animation
mNativeMapView.cancelTransitions();
Expand Down Expand Up @@ -1915,8 +1942,10 @@ public boolean onScaleBegin(ScaleGestureDetector detector) {
return false;
}

// reset tracking modes if gesture occurs
resetTrackingModes();
if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) {
// reset tracking modes if gesture occurs
resetTrackingModes();
}

mBeginTime = detector.getEventTime();
return true;
Expand Down Expand Up @@ -1968,7 +1997,8 @@ public boolean onScale(ScaleGestureDetector detector) {
mNativeMapView.scaleBy(detector.getScaleFactor(), detector.getFocusX() / mScreenDensity, detector.getFocusY() / mScreenDensity);
} else {
// around center map
mNativeMapView.scaleBy(detector.getScaleFactor(), (getWidth() / 2) / mScreenDensity, (getHeight() / 2) / mScreenDensity);
PointF centerPoint = mUserLocationView.getMarkerScreenPoint();
mNativeMapView.scaleBy(detector.getScaleFactor(), centerPoint.x / mScreenDensity, centerPoint.y / mScreenDensity);
}
return true;
}
Expand All @@ -1988,8 +2018,10 @@ public boolean onRotateBegin(RotateGestureDetector detector) {
return false;
}

// reset tracking modes if gesture occurs
resetTrackingModes();
if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) {
// reset tracking modes if gesture occurs
resetTrackingModes();
}

mBeginTime = detector.getEventTime();
return true;
Expand Down Expand Up @@ -2044,10 +2076,9 @@ public boolean onRotate(RotateGestureDetector detector) {
detector.getFocusX() / mScreenDensity,
detector.getFocusY() / mScreenDensity);
} else {
// around center map
mNativeMapView.setBearing(bearing,
(getWidth() / 2) / mScreenDensity,
(getHeight() / 2) / mScreenDensity);
// around center userlocation
PointF centerPoint = mUserLocationView.getMarkerScreenPoint();
mNativeMapView.setBearing(bearing, centerPoint.x / mScreenDensity, centerPoint.y / mScreenDensity);
}
return true;
}
Expand All @@ -2067,8 +2098,10 @@ public boolean onShoveBegin(ShoveGestureDetector detector) {
return false;
}

// reset tracking modes if gesture occurs
resetTrackingModes();
if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) {
// reset tracking modes if gesture occurs
resetTrackingModes();
}

mBeginTime = detector.getEventTime();
return true;
Expand Down Expand Up @@ -2137,8 +2170,6 @@ public void onZoom(boolean zoomIn) {
if (!mMapboxMap.getUiSettings().isZoomGesturesEnabled()) {
return;
}

// Zoom in or out
zoom(zoomIn);
}
}
Expand Down Expand Up @@ -2889,6 +2920,10 @@ private void setWidgetGravity(@NonNull final View view, int gravity) {

private void setWidgetMargins(@NonNull final View view, int left, int top, int right, int bottom) {
LayoutParams layoutParams = (LayoutParams) view.getLayoutParams();
left += mContentPaddingLeft;
top += mContentPaddingTop;
right += mContentPaddingRight;
bottom += mContentPaddingBottom;
layoutParams.setMargins(left, top, right, bottom);
view.setLayoutParams(layoutParams);
}
Expand Down Expand Up @@ -3171,4 +3206,5 @@ public interface OnMapChangedListener {
void onMapChanged(@MapChange int change);
}


}
Loading