Skip to content
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 @@ -42,6 +42,21 @@ public abstract class LocationLayerOptions implements Parcelable {
*/
private static final float ACCURACY_ALPHA_DEFAULT = 0.15f;

/**
* Default max map zoom
*/
private static final float MAX_ZOOM_DEFAULT = 20;

/**
* Default min map zoom
*/
private static final float MIN_ZOOM_DEFAULT = 2;

/**
* Default map padding
*/
private static final int[] PADDING_DEFAULT = {0, 0, 0, 0};

/**
* The default value which is used when the stale state is enabled
*/
Expand Down Expand Up @@ -148,7 +163,10 @@ public static Builder builder(Context context) {
private static Builder builder() {
return new AutoValue_LocationLayerOptions.Builder()
.enableStaleState(true)
.staleStateTimeout(STALE_STATE_DELAY_MS);
.staleStateTimeout(STALE_STATE_DELAY_MS)
.maxZoom(MAX_ZOOM_DEFAULT)
.minZoom(MIN_ZOOM_DEFAULT)
.padding(PADDING_DEFAULT);
}

/**
Expand Down Expand Up @@ -319,6 +337,40 @@ private static Builder builder() {
*/
public abstract long staleStateTimeout();

/**
* Sets the distance from the edges of the map view’s frame to the edges of the map
* view’s logical viewport.
* </p>
* <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.
* </p>
*
* @return integer array of padding values
* @since 0.5.0
*/
@SuppressWarnings("mutable")
public abstract int[] padding();

/**
* The maximum zoom level the map can be displayed at.
*
* @return the maximum zoom level
* @since 0.5.0
*/
public abstract double maxZoom();

/**
* The minimum zoom level the map can be displayed at.
*
* @return the minimum zoom level
* @since 0.5.0
*/
public abstract double minZoom();

/**
* Builder class for constructing a new instance of {@link LocationLayerOptions}.
*
Expand Down Expand Up @@ -493,6 +545,39 @@ public abstract static class Builder {
*/
public abstract Builder staleStateTimeout(long timeout);

/**
* Sets the distance from the edges of the map view’s frame to the edges of the map
* view’s logical viewport.
* </p>
* <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.
* </p>
*
* @param padding The margins for the map in pixels (left, top, right, bottom).
* @since 0.5.0
*/
public abstract Builder padding(int[] padding);

/**
* Sets the maximum zoom level the map can be displayed at.
* <p>
* The default maximum zoomn level is 22. The upper bound for this value is 25.5.
*
* @param maxZoom The new maximum zoom level.
* @since 0.5.0
*/
public abstract Builder maxZoom(double maxZoom);

/**
* Sets the minimum zoom level the map can be displayed at.
*
* @param minZoom The new minimum zoom level.
*/
public abstract Builder minZoom(double minZoom);

abstract LocationLayerOptions autoBuild();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public final class LocationLayerPlugin implements LifecycleObserver {
= new CopyOnWriteArrayList<>();
private final CopyOnWriteArrayList<OnLocationLayerClickListener> onLocationLayerClickListeners
= new CopyOnWriteArrayList<>();
private final CopyOnWriteArrayList<OnLocationLayerLongClickListener> onLocationLayerLongClickListeners
= new CopyOnWriteArrayList<>();

/**
* Construct a LocationLayerPlugin
Expand Down Expand Up @@ -255,6 +257,27 @@ public void setPadding(int left, int top, int right, int bottom) {
mapboxMap.setPadding(left, top, right, bottom);
}

/**
* Sets the maximum zoom level the map can be displayed at.
* <p>
* The default maximum zoom level is 22. The upper bound for this value is 25.5.
Copy link
Copy Markdown
Contributor

@LukasPaczos LukasPaczos Feb 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a higher default min zoom level to prevent jiggling when zoomed in extremely close?

*
* @param maxZoom The new maximum zoom level.
* @since 0.5.0
*/
public void setMaxZoom(double maxZoom) {
mapboxMap.setMaxZoomPreference(maxZoom);
}

/**
* Sets the minimum zoom level the map can be displayed at.
*
* @param minZoom The new minimum zoom level.
*/
public void setMinZoom(double minZoom) {
mapboxMap.setMinZoomPreference(minZoom);
}

/**
* Use to either force a location update or to manually control when the user location gets
* updated.
Expand Down Expand Up @@ -297,9 +320,9 @@ public LocationEngine getLocationEngine() {
}

/**
* Required to place inside your activities {@code onStart} method. You'll also most likely want
* to check that this Location Layer plugin instance inside your activity is null or not.
* Get the last know location of the location layer plugin.
*
* @return the last known location
* @since 0.1.0
*/
@SuppressLint("MissingPermission")
Expand Down Expand Up @@ -334,22 +357,43 @@ public void removeCompassListener(@NonNull CompassListener compassListener) {
/**
* Adds a listener that gets invoked when the user clicks the location layer.
*
* @param locationClickListener The location layer click listener that is invoked when the
* location layer is clicked
* @param listener The location layer click listener that is invoked when the
* location layer is clicked
* @since 0.3.0
*/
public void addOnLocationClickListener(@NonNull OnLocationLayerClickListener locationClickListener) {
onLocationLayerClickListeners.add(locationClickListener);
public void addOnLocationClickListener(@NonNull OnLocationLayerClickListener listener) {
onLocationLayerClickListeners.add(listener);
}

/**
* Removes the passed listener from the current list of location click listeners.
*
* @param locationClickListener to be removed
* @param listener to be removed
* @since 0.3.0
*/
public void removeOnLocationClickListener(@NonNull OnLocationLayerClickListener locationClickListener) {
onLocationLayerClickListeners.remove(locationClickListener);
public void removeOnLocationClickListener(@NonNull OnLocationLayerClickListener listener) {
onLocationLayerClickListeners.remove(listener);
}

/**
* Adds a listener that gets invoked when the user long clicks the location layer.
*
* @param listener The location layer click listener that is invoked when the
* location layer is clicked
* @since 0.5.0
*/
public void addOnLocationLongClickListener(@NonNull OnLocationLayerLongClickListener listener) {
onLocationLayerLongClickListeners.add(listener);
}

/**
* Removes the passed listener from the current list of location long click listeners.
*
* @param listener to be removed
* @since 0.5.0
*/
public void removeOnLocationLongClickListener(@NonNull OnLocationLayerLongClickListener listener) {
onLocationLayerLongClickListeners.remove(listener);
}

/**
Expand Down Expand Up @@ -403,7 +447,7 @@ public void onStart() {
/**
* Required to place inside your activities {@code onStop} method.
*
* @since 0.4.0
* @since 0.1.0
*/
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
public void onStop() {
Expand All @@ -423,6 +467,7 @@ private void initialize() {

mapView.addOnMapChangedListener(onMapChangedListener);
mapboxMap.addOnMapClickListener(onMapClickListener);
updateMapWithOptions(options);

locationLayer = new LocationLayer(mapView, mapboxMap, options);
locationLayerCamera = new LocationLayerCamera(mapboxMap);
Expand Down Expand Up @@ -450,6 +495,19 @@ private void disableLocationLayerPlugin() {
locationLayer.hide();
}

private void updateMapWithOptions(LocationLayerOptions options) {
int[] padding = options.padding();
if (padding != null && padding.length == 4) {
setPadding(options.padding()[0], padding[1], padding[2], padding[3]);
}
if (options.maxZoom() > 0) {
setMaxZoom(options.maxZoom());
}
if (options.minZoom() > 0) {
setMinZoom(options.minZoom());
}
}

/**
* Updates the user location icon.
*
Expand Down Expand Up @@ -508,6 +566,17 @@ public void onMapClick(@NonNull LatLng point) {
}
};

private MapboxMap.OnMapLongClickListener onMapLongClickListener = new MapboxMap.OnMapLongClickListener() {
@Override
public void onMapLongClick(@NonNull LatLng point) {
if (!onLocationLayerLongClickListeners.isEmpty() && locationLayer.onMapClick(point)) {
for (OnLocationLayerLongClickListener listener : onLocationLayerLongClickListeners) {
listener.onLocationLayerLongClick();
}
}
}
};

private OnLocationStaleListener onLocationStaleListener = new OnLocationStaleListener() {
@Override
public void onStaleStateChange(boolean isStale) {
Expand Down Expand Up @@ -559,4 +628,4 @@ public void onLocationChanged(Location location) {
updateLocation(location);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@
public interface OnLocationLayerClickListener {

void onLocationLayerClick();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mapbox.mapboxsdk.plugins.locationlayer;

/**
* The Location Layer Plugin exposes an API for listening to when the user long clicks on the location
* layer icon visible on the map. when this event occurs, the {@link #onLocationLayerLongClick()} method
* gets invoked.
*
* @since 0.5.0
*/
public interface OnLocationLayerLongClickListener {

void onLocationLayerLongClick();
}