diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 694 |
1 files changed, 528 insertions, 166 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index 757a9bc3d9..40b75d3ce1 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -1,20 +1,21 @@ package com.mapbox.mapboxsdk.maps; -import android.Manifest; import android.content.Context; import android.location.Location; import android.os.Bundle; -import android.support.annotation.FloatRange; +import android.os.SystemClock; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.annotation.RequiresPermission; import android.support.annotation.UiThread; +import android.support.v4.util.LongSparseArray; import android.text.TextUtils; import android.util.Log; import android.view.View; import com.mapbox.mapboxsdk.annotations.Annotation; +import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; +import com.mapbox.mapboxsdk.annotations.Icon; import com.mapbox.mapboxsdk.annotations.InfoWindow; import com.mapbox.mapboxsdk.annotations.Marker; import com.mapbox.mapboxsdk.annotations.MarkerOptions; @@ -23,6 +24,8 @@ 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.CameraUpdate; +import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.constants.MyBearingTracking; import com.mapbox.mapboxsdk.constants.MyLocationTracking; @@ -39,10 +42,12 @@ public class MapboxMap { private MapView mMapView; private UiSettings mUiSettings; + private TrackingSettings mTrackingSettings; private Projection mProjection; private CameraPosition mCameraPosition; private boolean mInvalidCameraPosition; private String mStyleUrl; + private LongSparseArray<Annotation> mAnnotations; private List<Marker> mSelectedMarkers; private List<InfoWindow> mInfoWindows; private MapboxMap.InfoWindowAdapter mInfoWindowAdapter; @@ -54,17 +59,22 @@ public class MapboxMap { private MapboxMap.OnMapLongClickListener mOnMapLongClickListener; private MapboxMap.OnMarkerClickListener mOnMarkerClickListener; private MapboxMap.OnInfoWindowClickListener mOnInfoWindowClickListener; + private MapboxMap.OnInfoWindowLongClickListener mOnInfoWindowLongClickListener; + private MapboxMap.OnInfoWindowCloseListener mOnInfoWindowCloseListener; private MapboxMap.OnFlingListener mOnFlingListener; private MapboxMap.OnScrollListener mOnScrollListener; private MapboxMap.OnMyLocationTrackingModeChangeListener mOnMyLocationTrackingModeChangeListener; private MapboxMap.OnMyBearingTrackingModeChangeListener mOnMyBearingTrackingModeChangeListener; private MapboxMap.OnFpsChangedListener mOnFpsChangedListener; + private MapboxMap.OnCameraChangeListener mOnCameraChangeListener; MapboxMap(@NonNull MapView mapView) { mMapView = mapView; mMapView.addOnMapChangedListener(new MapChangeCameraPositionListener()); mUiSettings = new UiSettings(mapView); + mTrackingSettings = new TrackingSettings(mMapView, mUiSettings); mProjection = new Projection(mapView); + mAnnotations = new LongSparseArray<>(); mSelectedMarkers = new ArrayList<>(); mInfoWindows = new ArrayList<>(); } @@ -83,6 +93,19 @@ public class MapboxMap { } // + // TrackingSettings + // + + /** + * Gets the tracking interface settings for the map. + * + * @return + */ + public TrackingSettings getTrackingSettings() { + return mTrackingSettings; + } + + // // Projection // @@ -105,14 +128,7 @@ public class MapboxMap { */ public final CameraPosition getCameraPosition() { if (mInvalidCameraPosition) { - // Camera position has changed, need to regenerate position - mCameraPosition = new CameraPosition.Builder(true) - .bearing((float) mMapView.getBearing()) - .target(mMapView.getLatLng()) - .tilt((float) mMapView.getTilt()) - .zoom((float) mMapView.getZoom()) - .build(); - mInvalidCameraPosition = false; + invalidateCameraPosition(); } return mCameraPosition; } @@ -137,8 +153,26 @@ public class MapboxMap { */ @UiThread public final void moveCamera(CameraUpdate update) { + moveCamera(update, null); + } + + /** + * Repositions the camera according to the instructions defined in the update. + * The move is instantaneous, and a subsequent getCameraPosition() will reflect the new position. + * See CameraUpdateFactory for a set of updates. + * + * @param update The change that should be applied to the camera. + */ + @UiThread + public final void moveCamera(CameraUpdate update, MapboxMap.CancelableCallback callback) { mCameraPosition = update.getCameraPosition(this); mMapView.jumpTo(mCameraPosition.bearing, mCameraPosition.target, mCameraPosition.tilt, mCameraPosition.zoom); + if (mOnCameraChangeListener != null) { + mOnCameraChangeListener.onCameraChange(mCameraPosition); + } + if (callback != null) { + callback.onFinish(); + } } /** @@ -175,7 +209,25 @@ public class MapboxMap { @UiThread public final void easeCamera(CameraUpdate update, int durationMs, final MapboxMap.CancelableCallback callback) { mCameraPosition = update.getCameraPosition(this); - mMapView.easeTo(mCameraPosition.bearing, mCameraPosition.target, getDurationNano(durationMs), mCameraPosition.tilt, mCameraPosition.zoom, callback); + mMapView.easeTo(mCameraPosition.bearing, mCameraPosition.target, getDurationNano(durationMs), mCameraPosition.tilt, mCameraPosition.zoom, new CancelableCallback() { + @Override + public void onCancel() { + if (callback != null) { + callback.onCancel(); + } + } + + @Override + public void onFinish() { + if (mOnCameraChangeListener != null) { + mOnCameraChangeListener.onCameraChange(mCameraPosition); + } + + if (callback != null) { + callback.onFinish(); + } + } + }); } /** @@ -227,7 +279,25 @@ public class MapboxMap { @UiThread public final void animateCamera(CameraUpdate update, int durationMs, final MapboxMap.CancelableCallback callback) { mCameraPosition = update.getCameraPosition(this); - mMapView.flyTo(mCameraPosition.bearing, mCameraPosition.target, getDurationNano(durationMs), mCameraPosition.tilt, mCameraPosition.zoom, callback); + mMapView.flyTo(mCameraPosition.bearing, mCameraPosition.target, getDurationNano(durationMs), mCameraPosition.tilt, mCameraPosition.zoom, new CancelableCallback() { + @Override + public void onCancel() { + if (callback != null) { + callback.onCancel(); + } + } + + @Override + public void onFinish() { + if (mOnCameraChangeListener != null) { + mOnCameraChangeListener.onCameraChange(mCameraPosition); + } + + if (callback != null) { + callback.onFinish(); + } + } + }); } // internal time layer conversion @@ -235,75 +305,34 @@ public class MapboxMap { return durationMs > 0 ? TimeUnit.NANOSECONDS.convert(durationMs, TimeUnit.MILLISECONDS) : 0; } - // - // 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; + private void invalidateCameraPosition() { + mInvalidCameraPosition = false; + mCameraPosition = new CameraPosition.Builder(true) + .bearing((float) mMapView.getBearing()) + .target(mMapView.getLatLng()) + .tilt((float) mMapView.getTilt()) + .zoom((float) mMapView.getZoom()) + .build(); + if (mOnCameraChangeListener != null) { + mOnCameraChangeListener.onCameraChange(mCameraPosition); } - 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); - } + // + // Reset North + // /** - * <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(); + public void resetNorth() { + mMapView.resetNorth(); } // // Manual zoom controls // - // used by UiSettings - void setZoomControlsEnabled(boolean enabled) { - mMapView.setZoomControlsEnabled(enabled); - } - // // Debug // @@ -468,7 +497,17 @@ public class MapboxMap { @UiThread @NonNull public Marker addMarker(@NonNull MarkerOptions markerOptions) { - return mMapView.addMarker(markerOptions); + return addMarker((BaseMarkerOptions) markerOptions); + } + + @UiThread + @NonNull + public Marker addMarker(@NonNull BaseMarkerOptions markerOptions) { + Marker marker = prepareMarker(markerOptions); + long id = mMapView.addMarker(marker); + marker.setId(id); + mAnnotations.put(id, marker); + return marker; } /** @@ -484,7 +523,50 @@ public class MapboxMap { @UiThread @NonNull public List<Marker> addMarkers(@NonNull List<MarkerOptions> markerOptionsList) { - return mMapView.addMarkers(markerOptionsList); + int count = markerOptionsList.size(); + List<Marker> markers = new ArrayList<>(count); + MarkerOptions markerOptions; + Marker marker; + for (int i = 0; i < count; i++) { + markerOptions = markerOptionsList.get(i); + marker = prepareMarker(markerOptions); + markers.add(marker); + } + + long[] ids = mMapView.addMarkers(markers); + long id = 0; + Marker m; + + for (int i = 0; i < markers.size(); i++) { + m = markers.get(i); + m.setMapboxMap(this); + if (ids != null) { + id = ids[i]; + } else { + //unit test + id++; + } + m.setId(id); + mAnnotations.put(id, m); + } + return markers; + } + + /** + * <p> + * Updates a marker on this map. Does nothing if the marker is already added. + * </p> + * + * @param updatedMarker An updated marker object. + */ + @UiThread + public void updateMarker(@NonNull Marker updatedMarker) { + mMapView.updateMarker(updatedMarker); + + int index = mAnnotations.indexOfKey(updatedMarker.getId()); + if (index > -1) { + mAnnotations.setValueAt(index, updatedMarker); + } } /** @@ -496,7 +578,14 @@ public class MapboxMap { @UiThread @NonNull public Polyline addPolyline(@NonNull PolylineOptions polylineOptions) { - return mMapView.addPolyline(polylineOptions); + Polyline polyline = polylineOptions.getPolyline(); + if (!polyline.getPoints().isEmpty()) { + long id = mMapView.addPolyline(polyline); + polyline.setMapboxMap(this); + polyline.setId(id); + mAnnotations.put(id, polyline); + } + return polyline; } /** @@ -508,7 +597,33 @@ public class MapboxMap { @UiThread @NonNull public List<Polyline> addPolylines(@NonNull List<PolylineOptions> polylineOptionsList) { - return mMapView.addPolylines(polylineOptionsList); + int count = polylineOptionsList.size(); + Polyline polyline; + List<Polyline> polylines = new ArrayList<>(count); + for (PolylineOptions options : polylineOptionsList) { + polyline = options.getPolyline(); + if (!polyline.getPoints().isEmpty()) { + polylines.add(polyline); + } + } + + long[] ids = mMapView.addPolylines(polylines); + long id = 0; + Polyline p; + + for (int i = 0; i < polylines.size(); i++) { + p = polylines.get(i); + p.setMapboxMap(this); + if (ids != null) { + id = ids[i]; + } else { + // unit test + id++; + } + p.setId(id); + mAnnotations.put(id, p); + } + return polylines; } /** @@ -520,7 +635,14 @@ public class MapboxMap { @UiThread @NonNull public Polygon addPolygon(@NonNull PolygonOptions polygonOptions) { - return mMapView.addPolygon(polygonOptions); + Polygon polygon = polygonOptions.getPolygon(); + if (!polygon.getPoints().isEmpty()) { + long id = mMapView.addPolygon(polygon); + polygon.setId(id); + polygon.setMapboxMap(this); + mAnnotations.put(id, polygon); + } + return polygon; } /** @@ -532,7 +654,32 @@ public class MapboxMap { @UiThread @NonNull public List<Polygon> addPolygons(@NonNull List<PolygonOptions> polygonOptionsList) { - return mMapView.addPolygons(polygonOptionsList); + int count = polygonOptionsList.size(); + + Polygon polygon; + List<Polygon> polygons = new ArrayList<>(count); + for (PolygonOptions polygonOptions : polygonOptionsList) { + polygon = polygonOptions.getPolygon(); + if (!polygon.getPoints().isEmpty()) { + polygons.add(polygon); + } + } + + long[] ids = mMapView.addPolygons(polygons); + long id = 0; + for (int i = 0; i < polygons.size(); i++) { + polygon = polygons.get(i); + polygon.setMapboxMap(this); + if (ids != null) { + id = ids[i]; + } else { + // unit test + id++; + } + polygon.setId(id); + mAnnotations.put(id, polygon); + } + return polygons; } /** @@ -549,13 +696,55 @@ public class MapboxMap { } /** + * <p> + * Convenience method for removing a Polyline from the map. + * </p> + * Calls removeAnnotation() internally + * + * @param polyline Polyline to remove + */ + @UiThread + public void removePolyline(@NonNull Polyline polyline) { + removeAnnotation(polyline); + } + + /** + * <p> + * Convenience method for removing a Polygon from the map. + * </p> + * Calls removeAnnotation() internally + * + * @param polygon Polygon to remove + */ + @UiThread + public void removePolygon(@NonNull Polygon polygon) { + removeAnnotation(polygon); + } + + /** * Removes an annotation from the map. * * @param annotation The annotation object to remove. */ @UiThread public void removeAnnotation(@NonNull Annotation annotation) { - mMapView.removeAnnotation(annotation); + if (annotation instanceof Marker) { + ((Marker) annotation).hideInfoWindow(); + } + long id = annotation.getId(); + mMapView.removeAnnotation(id); + mAnnotations.remove(id); + } + + /** + * Removes an annotation from the map + * + * @param id The identifier associated to the annotation to be removed + */ + @UiThread + public void removeAnnotation(long id) { + mMapView.removeAnnotation(id); + mAnnotations.remove(id); } /** @@ -565,15 +754,49 @@ public class MapboxMap { */ @UiThread public void removeAnnotations(@NonNull List<? extends Annotation> annotationList) { - mMapView.removeAnnotations(annotationList); + int count = annotationList.size(); + long[] ids = new long[count]; + for (int i = 0; i < count; i++) { + Annotation annotation = annotationList.get(i); + if (annotation instanceof Marker) { + ((Marker) annotation).hideInfoWindow(); + } + ids[i] = annotationList.get(i).getId(); + } + mMapView.removeAnnotations(ids); + for (long id : ids) { + mAnnotations.remove(id); + } } /** * Removes all annotations from the map. */ @UiThread - public void removeAllAnnotations() { - mMapView.removeAllAnnotations(); + public void removeAnnotations() { + Annotation annotation; + int count = mAnnotations.size(); + long[] ids = new long[count]; + for (int i = 0; i < count; i++) { + ids[i] = mAnnotations.keyAt(i); + annotation = mAnnotations.get(ids[i]); + if (annotation instanceof Marker) { + ((Marker) annotation).hideInfoWindow(); + } + } + mMapView.removeAnnotations(ids); + mAnnotations.clear(); + } + + /** + * Return a annotation based on its id. + * + * @return An annotation with a matched id, null is returned if no match was found. + */ + @UiThread + @Nullable + public Annotation getAnnotation(long id) { + return mAnnotations.get(id); } /** @@ -583,8 +806,69 @@ public class MapboxMap { * list will not update the map. */ @NonNull - public List<Annotation> getAllAnnotations() { - return mMapView.getAllAnnotations(); + public List<Annotation> getAnnotations() { + List<Annotation> annotations = new ArrayList<>(); + for (int i = 0; i < mAnnotations.size(); i++) { + annotations.add(mAnnotations.get(mAnnotations.keyAt(i))); + } + return annotations; + } + + /** + * Returns a list of all the markers on the map. + * + * @return A list of all the markers objects. The returned object is a copy so modifying this + * list will not update the map. + */ + @NonNull + public List<Marker> getMarkers() { + List<Marker> markers = new ArrayList<>(); + Annotation annotation; + for (int i = 0; i < mAnnotations.size(); i++) { + annotation = mAnnotations.get(mAnnotations.keyAt(i)); + if (annotation instanceof Marker) { + markers.add((Marker) annotation); + } + } + return markers; + } + + /** + * Returns a list of all the polygons on the map. + * + * @return A list of all the polygon objects. The returned object is a copy so modifying this + * list will not update the map. + */ + @NonNull + public List<Polygon> getPolygons() { + List<Polygon> polygons = new ArrayList<>(); + Annotation annotation; + for (int i = 0; i < mAnnotations.size(); i++) { + annotation = mAnnotations.get(mAnnotations.keyAt(i)); + if (annotation instanceof Polygon) { + polygons.add((Polygon) annotation); + } + } + return polygons; + } + + /** + * Returns a list of all the polylines on the map. + * + * @return A list of all the polylines objects. The returned object is a copy so modifying this + * list will not update the map. + */ + @NonNull + public List<Polyline> getPolylines() { + List<Polyline> polylines = new ArrayList<>(); + Annotation annotation; + for (int i = 0; i < mAnnotations.size(); i++) { + annotation = mAnnotations.get(mAnnotations.keyAt(i)); + if (annotation instanceof Polyline) { + polylines.add((Polyline) annotation); + } + } + return polylines; } /** @@ -670,11 +954,17 @@ public class MapboxMap { * @return The currently selected marker. */ @UiThread - @Nullable public List<Marker> getSelectedMarkers() { return mSelectedMarkers; } + private Marker prepareMarker(BaseMarkerOptions markerOptions) { + Marker marker = markerOptions.getMarker(); + Icon icon = mMapView.loadIconForMarker(marker); + marker.setTopOffsetPixels(mMapView.getTopOffsetPixelsForIcon(icon)); + return marker; + } + // // InfoWindow // @@ -735,10 +1025,58 @@ public class MapboxMap { } // + // Padding + // + + /** + * 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. + */ + public void setPadding(int left, int top, int right, int bottom) { + mMapView.setContentPadding(left, top, right, bottom); + mUiSettings.invalidate(); + + moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder(mCameraPosition).build())); + } + + /** + * + * @return + */ + public int[] getPadding() { + return new int[]{mMapView.getContentPaddingLeft(), + mMapView.getContentPaddingTop(), + mMapView.getContentPaddingRight(), + mMapView.getContentPaddingBottom()}; + } + + // // Map events // /** + * Sets a callback that's invoked on every change in camera position. + * + * @param listener The callback that's invoked on every camera change position. + * To unset the callback, use null. + */ + @UiThread + public void setOnCameraChangeListener(@Nullable OnCameraChangeListener listener) { + mOnCameraChangeListener = listener; + } + + /** * Sets a callback that's invoked on every frame rendered to the map view. * * @param listener The callback that's invoked on every frame rendered to the map view. @@ -845,10 +1183,44 @@ public class MapboxMap { * * @return Current active InfoWindow Click Listener */ + @UiThread public OnInfoWindowClickListener getOnInfoWindowClickListener() { return mOnInfoWindowClickListener; } + /** + * Sets a callback that's invoked when a marker's info window is long pressed. + * + * @param listener The callback that's invoked when a marker's info window is long pressed. To unset the callback, use null. + */ + @UiThread + public void setOnInfoWindowLongClickListener(@Nullable OnInfoWindowLongClickListener listener) { + mOnInfoWindowLongClickListener = listener; + } + + /** + * Return the InfoWindow long click listener + * + * @return Current active InfoWindow long Click Listener + */ + public OnInfoWindowLongClickListener getOnInfoWindowLongClickListener() { + return mOnInfoWindowLongClickListener; + } + + public void setOnInfoWindowCloseListener(@Nullable OnInfoWindowCloseListener listener) { + mOnInfoWindowCloseListener = listener; + } + + /** + * Return the InfoWindow close listener + * + * @return Current active InfoWindow Close Listener + */ + @UiThread + public OnInfoWindowCloseListener getOnInfoWindowCloseListener() { + return mOnInfoWindowCloseListener; + } + // // User location // @@ -874,13 +1246,14 @@ public class MapboxMap { * or @link android.Manifest.permission#ACCESS_FINE_LOCATION. * * @param enabled True to enable; false to disable. - * @throws SecurityException if no suitable permission is present */ @UiThread - @RequiresPermission(anyOf = { - Manifest.permission.ACCESS_COARSE_LOCATION, - Manifest.permission.ACCESS_FINE_LOCATION}) public void setMyLocationEnabled(boolean enabled) { + if (!mMapView.isPermissionsAccepted()) { + Log.e(MapboxConstants.TAG, "Could not activate user location tracking: " + + "user did not accept the permission or permissions were not requested."); + return; + } mMyLocationEnabled = enabled; mMapView.setMyLocationEnabled(enabled); } @@ -909,40 +1282,6 @@ public class MapboxMap { } /** - * <p> - * Set the current my location tracking mode. - * </p> - * <p> - * Will enable my location if not active. - * </p> - * See {@link MyLocationTracking} for different values. - * - * @param myLocationTrackingMode The location tracking mode to be used. - * @throws SecurityException if no suitable permission is present - * @see MyLocationTracking - */ - @UiThread - @RequiresPermission(anyOf = { - Manifest.permission.ACCESS_COARSE_LOCATION, - Manifest.permission.ACCESS_FINE_LOCATION}) - public void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) { - mMapView.setMyLocationTrackingMode(myLocationTrackingMode); - } - - /** - * Returns the current user location tracking mode. - * - * @return The current user location tracking mode. - * One of the values from {@link MyLocationTracking.Mode}. - * @see MyLocationTracking.Mode - */ - @UiThread - @MyLocationTracking.Mode - public int getMyLocationTrackingMode() { - return mMapView.getMyLocationTrackingMode(); - } - - /** * Sets a callback that's invoked when the location tracking mode changes. * * @param listener The callback that's invoked when the location tracking mode changes. @@ -959,42 +1298,6 @@ public class MapboxMap { } /** - * <p> - * Set the current my bearing tracking mode. - * </p> - * Shows the direction the user is heading. - * <p> - * When location tracking is disabled the direction of {@link UserLocationView} is rotated - * When location tracking is enabled the {@link MapView} is rotated based on bearing value. - * </p> - * See {@link MyBearingTracking} for different values. - * - * @param myBearingTrackingMode The bearing tracking mode to be used. - * @throws SecurityException if no suitable permission is present - * @see MyBearingTracking - */ - @UiThread - @RequiresPermission(anyOf = { - Manifest.permission.ACCESS_COARSE_LOCATION, - Manifest.permission.ACCESS_FINE_LOCATION}) - public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTrackingMode) { - mMapView.setMyBearingTrackingMode(myBearingTrackingMode); - } - - /** - * Returns the current user bearing tracking mode. - * See {@link MyBearingTracking} for possible return values. - * - * @return the current user bearing tracking mode. - * @see MyBearingTracking - */ - @UiThread - @MyLocationTracking.Mode - public int getMyBearingTrackingMode() { - return mMapView.getMyBearingTrackingMode(); - } - - /** * Sets a callback that's invoked when the bearing tracking mode changes. * * @param listener The callback that's invoked when the bearing tracking mode changes. @@ -1033,9 +1336,17 @@ public class MapboxMap { return mMapView; } -// -// Interfaces -// + // + // Invalidate + // + + public void invalidate(){ + mMapView.update(); + } + + // + // Interfaces + // /** * Interface definition for a callback to be invoked when the map is flinged. @@ -1062,6 +1373,20 @@ public class MapboxMap { } /** + * Interface definition for a callback to be invoked for when the camera changes position. + */ + public interface OnCameraChangeListener { + /** + * Called after the camera position has changed. During an animation, + * this listener may not be notified of intermediate camera positions. + * It is always called for the final position in the animation. + * + * @param position The CameraPosition at the end of the last camera change. + */ + void onCameraChange(CameraPosition position); + } + + /** * Interface definition for a callback to be invoked on every frame rendered to the map view. * * @see MapboxMap#setOnFpsChangedListener(OnFpsChangedListener) @@ -1130,7 +1455,37 @@ public class MapboxMap { * @param marker The marker of the info window the user clicked on. * @return If true the listener has consumed the event and the info window will not be closed. */ - boolean onMarkerClick(@NonNull Marker marker); + boolean onInfoWindowClick(@NonNull Marker marker); + } + + /** + * Callback interface for when the user long presses on a marker's info window. + * + * @see MapboxMap#setOnInfoWindowClickListener(OnInfoWindowClickListener) + */ + public interface OnInfoWindowLongClickListener { + + /** + * Called when the user makes a long-press gesture on the marker's info window. + * + * @param marker The marker were the info window is attached to + */ + void onInfoWindowLongClick(Marker marker); + } + + /** + * Callback interface for close events on a marker's info window. + * + * @see MapboxMap#setOnInfoWindowCloseListener(OnInfoWindowCloseListener) + */ + public interface OnInfoWindowCloseListener { + + /** + * Called when the marker's info window is closed. + * + * @param marker The marker of the info window that was closed. + */ + void onInfoWindowClose(Marker marker); } /** @@ -1169,7 +1524,7 @@ public class MapboxMap { /** * Interface definition for a callback to be invoked when the the My Location tracking mode changes. * - * @see MapboxMap#setMyLocationTrackingMode(int) + * @see MapView#setMyLocationTrackingMode(int) */ public interface OnMyLocationTrackingModeChangeListener { @@ -1184,7 +1539,7 @@ public class MapboxMap { /** * Interface definition for a callback to be invoked when the the My Location tracking mode changes. * - * @see MapboxMap#setMyLocationTrackingMode(int) + * @see MapView#setMyLocationTrackingMode(int) */ public interface OnMyBearingTrackingModeChangeListener { @@ -1212,13 +1567,20 @@ public class MapboxMap { } private class MapChangeCameraPositionListener implements MapView.OnMapChangedListener { + + private static final long UPDATE_RATE_MS = 400; + private long mPreviousUpdateTimestamp = 0; + @Override public void onMapChanged(@MapView.MapChange int change) { - if (!mInvalidCameraPosition && (change == MapView.REGION_DID_CHANGE - || change == MapView.REGION_DID_CHANGE_ANIMATED - || change == MapView.REGION_WILL_CHANGE - || change == MapView.REGION_WILL_CHANGE_ANIMATED)) { + if (change >= MapView.REGION_WILL_CHANGE && change <= MapView.REGION_DID_CHANGE_ANIMATED) { mInvalidCameraPosition = true; + long currentTime = SystemClock.elapsedRealtime(); + if (currentTime < mPreviousUpdateTimestamp) { + return; + } + invalidateCameraPosition(); + mPreviousUpdateTimestamp = currentTime + UPDATE_RATE_MS; } } } |