From aa018736b286f39536419716a86369def8a5009f Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Tue, 24 Nov 2015 17:35:22 -0500 Subject: [PATCH 1/6] still some work needed on onSingleTapConfirmed() --- .../mapboxsdk/annotations/InfoWindow.java | 2 +- .../com/mapbox/mapboxsdk/views/MapView.java | 82 ++++++++++++------- 2 files changed, 54 insertions(+), 30 deletions(-) diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java index 0f9668be8f7..e3254e8f72a 100644 --- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java +++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java @@ -196,7 +196,7 @@ void adaptDefaultMarker(Marker overlayItem) { } private void onClose() { - mMapView.get().deselectMarker(); + mMapView.get().deselectMarker(getBoundMarker()); } InfoWindow setBoundMarker(Marker boundMarker) { diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java index 8844184142b..a37d09a3a8e 100644 --- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java +++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java @@ -81,6 +81,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Iterator; import java.util.List; /** @@ -201,7 +202,7 @@ public final class MapView extends FrameLayout { // Every annotation that has been added to the map private final List mAnnotations = new ArrayList<>(); private List mMarkersNearLastTap = new ArrayList<>(); - private Marker mSelectedMarker; + private List mSelectedMarkers = new ArrayList<>(); private InfoWindowAdapter mInfoWindowAdapter; private SpriteFactory mSpriteFactory; private ArrayList mSprites = new ArrayList<>(); @@ -808,7 +809,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { @Override public void onMapChanged(@MapChange int change) { if ((change == REGION_WILL_CHANGE) || (change == REGION_WILL_CHANGE_ANIMATED)) { - deselectMarker(); + deselectMarkers(); } if (change == DID_FINISH_LOADING_MAP) { @@ -2018,12 +2019,12 @@ public void selectMarker(@NonNull Marker marker) { return; } - if (marker == mSelectedMarker) { + if (mSelectedMarkers.contains(marker)) { return; } // Need to deselect any currently selected annotation first - deselectMarker(); + deselectMarker(marker); boolean handledDefaultClick = false; if (mOnMarkerClickListener != null) { @@ -2038,20 +2039,41 @@ public void selectMarker(@NonNull Marker marker) { marker.showInfoWindow(); } - mSelectedMarker = marker; + mSelectedMarkers.add(marker); } /** - * Deselects any currently selected marker. The selected marker will have it's info window closed. + * Deselects any currently selected marker. All markers will have it's info window closed. */ @UiThread - public void deselectMarker() { - if (mSelectedMarker != null) { - if (mSelectedMarker.isInfoWindowShown()) { - mSelectedMarker.hideInfoWindow(); - mSelectedMarker = null; + public void deselectMarkers() { + if (mSelectedMarkers.isEmpty()) { + return; + } + + for (Marker marker: mSelectedMarkers) { + if (marker.isInfoWindowShown()) { + marker.hideInfoWindow(); } } + + mSelectedMarkers = new ArrayList<>(); + } + + /** + * Deselects a currently selected marker. The selected marker will have it's info window closed. + */ + @UiThread + public void deselectMarker(@NonNull Marker marker) { + if (!mSelectedMarkers.contains(marker)) { + return; + } + + if (marker.isInfoWindowShown()) { + marker.hideInfoWindow(); + } + + mSelectedMarkers.remove(marker); } // @@ -2129,8 +2151,8 @@ private void setVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, dou */ @UiThread @Nullable - public Marker getSelectedMarker() { - return mSelectedMarker; + public List getSelectedMarkers() { + return mSelectedMarkers; } private void adjustTopOffsetPixels() { @@ -2144,12 +2166,12 @@ private void adjustTopOffsetPixels() { } } - if (mSelectedMarker != null) { - if (mSelectedMarker.isInfoWindowShown()) { - Marker temp = mSelectedMarker; + for (Marker marker: mSelectedMarkers) { + if (marker.isInfoWindowShown()) { + Marker temp = marker; temp.hideInfoWindow(); temp.showInfoWindow(); - mSelectedMarker = temp; + marker = temp; } } } @@ -2426,19 +2448,21 @@ public boolean onSingleTapConfirmed(MotionEvent e) { Collections.sort(nearbyMarkers); if (nearbyMarkers == mMarkersNearLastTap) { + // TODO // the selection candidates haven't changed; cycle through them - if (mSelectedMarker != null && (mSelectedMarker.getId() == mMarkersNearLastTap.get(mMarkersNearLastTap.size() - 1).getId())) { - // the selected marker is the last in the set; cycle back to the first - // note: this could be the selected marker if only one in set - newSelectedMarkerId = mMarkersNearLastTap.get(0).getId(); - } else if (mSelectedMarker != null) { - // otherwise increment the selection through the candidates - long result = mMarkersNearLastTap.indexOf(mSelectedMarker); - newSelectedMarkerId = mMarkersNearLastTap.get((int) result + 1).getId(); - } else { +// if (mSelectedMarker != null +// && (mSelectedMarker.getId() == mMarkersNearLastTap.get(mMarkersNearLastTap.size() - 1).getId())) { +// // the selected marker is the last in the set; cycle back to the first +// // note: this could be the selected marker if only one in set +// newSelectedMarkerId = mMarkersNearLastTap.get(0).getId(); +// } else if (mSelectedMarker != null) { +// // otherwise increment the selection through the candidates +// long result = mMarkersNearLastTap.indexOf(mSelectedMarker); +// newSelectedMarkerId = mMarkersNearLastTap.get((int) result + 1).getId(); +// } else { // no current selection; select the first one newSelectedMarkerId = mMarkersNearLastTap.get(0).getId(); - } +// } } else { // start tracking a new set of nearby markers mMarkersNearLastTap = nearbyMarkers; @@ -2459,7 +2483,7 @@ public boolean onSingleTapConfirmed(MotionEvent e) { Annotation annotation = mAnnotations.get(i); if (annotation instanceof Marker) { if (annotation.getId() == newSelectedMarkerId) { - if (mSelectedMarker == null || annotation.getId() != mSelectedMarker.getId()) { + if (mSelectedMarkers.isEmpty() || !mSelectedMarkers.contains(annotation)) { selectMarker((Marker) annotation); } break; @@ -2469,7 +2493,7 @@ public boolean onSingleTapConfirmed(MotionEvent e) { } else { // deselect any selected marker - deselectMarker(); + deselectMarkers(); // notify app of map click if (mOnMapClickListener != null) { From 936d1c01b28b1edd3961a2fb15a99562fe7af029 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Wed, 25 Nov 2015 10:33:15 +0000 Subject: [PATCH 2/6] [android] #3121 Allow InfoWindow to be open while panning, allow standard InfoWindow (without repositioning InfoWindowTipView) to be panned above the map --- .../mapboxsdk/annotations/InfoWindow.java | 34 +++++++++++++------ .../mapbox/mapboxsdk/annotations/Marker.java | 11 +++--- .../com/mapbox/mapboxsdk/views/MapView.java | 20 +++++------ 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java index e3254e8f72a..c9ca2acb525 100644 --- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java +++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java @@ -18,10 +18,11 @@ /** * A tooltip view */ -final class InfoWindow { +public class InfoWindow { private WeakReference mBoundMarker; private WeakReference mMapView; + private float mMarkerHeightOffset; private boolean mIsVisible; protected View mView; @@ -82,6 +83,7 @@ public boolean onTouch(View v, MotionEvent e) { */ InfoWindow open(Marker boundMarker, LatLng position, int offsetX, int offsetY) { setBoundMarker(boundMarker); + mMarkerHeightOffset = offsetY; MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, MapView.LayoutParams.WRAP_CONTENT); mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); @@ -89,19 +91,20 @@ InfoWindow open(Marker boundMarker, LatLng position, int offsetX, int offsetY) { // Calculate default Android x,y coordinate PointF coords = mMapView.get().toScreenLocation(position); float x = coords.x - (mView.getMeasuredWidth() / 2) + offsetX; - float y = coords.y - mView.getMeasuredHeight() + offsetY; - - // get right/left popup window - float rightSideInfowWindow = x + mView.getMeasuredWidth(); - float leftSideInfoWindow = x; - - // get right/left map view - final float mapRight = mMapView.get().getRight(); - final float mapLeft = mMapView.get().getLeft(); + float y = coords.y - mView.getMeasuredHeight() + mMarkerHeightOffset; if (mView instanceof InfoWindowView) { // only apply repositioning/margin for InfoWindowView Resources resources = mMapView.get().getContext().getResources(); + + // get right/left popup window + float rightSideInfowWindow = x + mView.getMeasuredWidth(); + float leftSideInfoWindow = x; + + // get right/left map view + final float mapRight = mMapView.get().getRight(); + final float mapLeft = mMapView.get().getLeft(); + float marginHorizontal = resources.getDimension(R.dimen.infowindow_margin); float tipViewOffset = resources.getDimension(R.dimen.infowindow_tipview_width) / 2; float tipViewMarginLeft = mView.getMeasuredWidth() / 2 - tipViewOffset; @@ -226,4 +229,15 @@ private static void setResIds(Context context) { .getIdentifier("id/infowindow_subdescription", null, packageName); mImageId = context.getResources().getIdentifier("id/infowindow_image", null, packageName); } + + public void update() { + MapView mapView = mMapView.get(); + Marker marker = mBoundMarker.get(); + if (mapView != null && marker != null) { + PointF pointF = mapView.toScreenLocation(marker.getPosition()); + mView.setX(pointF.x - mView.getWidth() / 2); + mView.setY(pointF.y - mView.getHeight() + mMarkerHeightOffset); + } + } + } diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java index 4f43f9bfa2d..ed8e0d98e4c 100644 --- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java +++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java @@ -79,9 +79,9 @@ void setTitle(String title) { /** * Do not use this method. Used internally by the SDK. */ - public void showInfoWindow() { + public InfoWindow showInfoWindow() { if (getMapView() == null) { - return; + return null; } MapView.InfoWindowAdapter infoWindowAdapter = getMapView().getInfoWindowAdapter(); @@ -91,17 +91,18 @@ public void showInfoWindow() { if (content != null) { infoWindow = new InfoWindow(content, getMapView()); showInfoWindow(infoWindow); - return; + return infoWindow; } } getInfoWindow().adaptDefaultMarker(this); - showInfoWindow(getInfoWindow()); + return showInfoWindow(getInfoWindow()); } - private void showInfoWindow(InfoWindow iw) { + private InfoWindow showInfoWindow(InfoWindow iw) { iw.open(this, getPosition(), 0, topOffsetPixels); infoWindowShown = true; + return iw; } private InfoWindow getInfoWindow() { diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java index a37d09a3a8e..6c225c02b6d 100644 --- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java +++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java @@ -56,6 +56,7 @@ import com.almeros.android.multitouch.gesturedetectors.TwoFingerGestureDetector; import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.annotations.Annotation; +import com.mapbox.mapboxsdk.annotations.InfoWindow; import com.mapbox.mapboxsdk.annotations.Marker; import com.mapbox.mapboxsdk.annotations.MarkerOptions; import com.mapbox.mapboxsdk.annotations.Polygon; @@ -81,7 +82,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.Iterator; import java.util.List; /** @@ -203,6 +203,7 @@ public final class MapView extends FrameLayout { private final List mAnnotations = new ArrayList<>(); private List mMarkersNearLastTap = new ArrayList<>(); private List mSelectedMarkers = new ArrayList<>(); + private List mInfoWindows = new ArrayList<>(); private InfoWindowAdapter mInfoWindowAdapter; private SpriteFactory mSpriteFactory; private ArrayList mSprites = new ArrayList<>(); @@ -808,10 +809,6 @@ public void onCreate(@Nullable Bundle savedInstanceState) { addOnMapChangedListener(new OnMapChangedListener() { @Override public void onMapChanged(@MapChange int change) { - if ((change == REGION_WILL_CHANGE) || (change == REGION_WILL_CHANGE_ANIMATED)) { - deselectMarkers(); - } - if (change == DID_FINISH_LOADING_MAP) { reloadSprites(); reloadMarkers(); @@ -2033,10 +2030,8 @@ public void selectMarker(@NonNull Marker marker) { } if (!handledDefaultClick) { - // default behaviour - // Can't do this as InfoWindow will get hidden - //setCenterCoordinate(marker.getPosition(), true); - marker.showInfoWindow(); + // default behaviour show InfoWindow + mInfoWindows.add(marker.showInfoWindow()); } mSelectedMarkers.add(marker); @@ -2051,7 +2046,7 @@ public void deselectMarkers() { return; } - for (Marker marker: mSelectedMarkers) { + for (Marker marker : mSelectedMarkers) { if (marker.isInfoWindowShown()) { marker.hideInfoWindow(); } @@ -2166,7 +2161,7 @@ private void adjustTopOffsetPixels() { } } - for (Marker marker: mSelectedMarkers) { + for (Marker marker : mSelectedMarkers) { if (marker.isInfoWindowShown()) { Marker temp = marker; temp.hideInfoWindow(); @@ -2252,6 +2247,9 @@ public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int h public void onSurfaceTextureUpdated(SurfaceTexture surface) { mCompassView.update(getDirection()); mUserLocationView.update(); + for (InfoWindow infoWindow : mInfoWindows) { + infoWindow.update(); + } } } From 0cf326d668dc2318ca50f753c956b4532e25a288 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Wed, 25 Nov 2015 11:24:30 +0000 Subject: [PATCH 3/6] [android] #3115 reposition info windows that have been repositioned while panning the map --- .../java/com/mapbox/mapboxsdk/annotations/InfoWindow.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java index c9ca2acb525..220b37ed1f0 100644 --- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java +++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java @@ -23,6 +23,7 @@ public class InfoWindow { private WeakReference mBoundMarker; private WeakReference mMapView; private float mMarkerHeightOffset; + private float mViewWidthOffset; private boolean mIsVisible; protected View mView; @@ -152,6 +153,8 @@ InfoWindow open(Marker boundMarker, LatLng position, int offsetX, int offsetY) { mView.setX(x); mView.setY(y); + mViewWidthOffset = x - (coords.x - (mView.getMeasuredWidth() / 2) + offsetX); + close(); //if it was already opened mMapView.get().addView(mView, lp); mIsVisible = true; @@ -235,7 +238,7 @@ public void update() { Marker marker = mBoundMarker.get(); if (mapView != null && marker != null) { PointF pointF = mapView.toScreenLocation(marker.getPosition()); - mView.setX(pointF.x - mView.getWidth() / 2); + mView.setX((pointF.x - (mView.getWidth() / 2)) + mViewWidthOffset); mView.setY(pointF.y - mView.getHeight() + mMarkerHeightOffset); } } From 4c9751c6e6866882a17a81603b6550bc74072440 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Wed, 25 Nov 2015 09:39:03 -0500 Subject: [PATCH 4/6] we just need to clear the list' --- .../src/main/java/com/mapbox/mapboxsdk/views/MapView.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java index 6c225c02b6d..a5758bbeef4 100644 --- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java +++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java @@ -2052,7 +2052,8 @@ public void deselectMarkers() { } } - mSelectedMarkers = new ArrayList<>(); + // Removes all selected markers from the list + mSelectedMarkers.clear(); } /** @@ -2446,7 +2447,10 @@ public boolean onSingleTapConfirmed(MotionEvent e) { Collections.sort(nearbyMarkers); if (nearbyMarkers == mMarkersNearLastTap) { - // TODO + + // TODO: We still need to adapt this logic to the new mSelectedMarkers list, + // though the basic functionality is there. + // the selection candidates haven't changed; cycle through them // if (mSelectedMarker != null // && (mSelectedMarker.getId() == mMarkersNearLastTap.get(mMarkersNearLastTap.size() - 1).getId())) { From e7c4ee49b1647c054cf72e7c4fb3be3bc5f4e424 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Wed, 25 Nov 2015 18:55:49 +0100 Subject: [PATCH 5/6] [android] #3115 - optimised + cleanup before PR --- .../mapboxsdk/annotations/InfoWindow.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java index 220b37ed1f0..5d4fa91e0b1 100644 --- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java +++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java @@ -24,6 +24,7 @@ public class InfoWindow { private WeakReference mMapView; private float mMarkerHeightOffset; private float mViewWidthOffset; + private PointF mCoordinates; private boolean mIsVisible; protected View mView; @@ -84,15 +85,17 @@ public boolean onTouch(View v, MotionEvent e) { */ InfoWindow open(Marker boundMarker, LatLng position, int offsetX, int offsetY) { setBoundMarker(boundMarker); - mMarkerHeightOffset = offsetY; MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, MapView.LayoutParams.WRAP_CONTENT); mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); + // Calculate y-offset for update method + mMarkerHeightOffset = -mView.getMeasuredHeight() + offsetY; + // Calculate default Android x,y coordinate - PointF coords = mMapView.get().toScreenLocation(position); - float x = coords.x - (mView.getMeasuredWidth() / 2) + offsetX; - float y = coords.y - mView.getMeasuredHeight() + mMarkerHeightOffset; + mCoordinates = mMapView.get().toScreenLocation(position); + float x = mCoordinates.x - (mView.getMeasuredWidth() / 2) + offsetX; + float y = mCoordinates.y - mView.getMeasuredHeight() + offsetY; if (mView instanceof InfoWindowView) { // only apply repositioning/margin for InfoWindowView @@ -133,7 +136,6 @@ InfoWindow open(Marker boundMarker, LatLng position, int offsetX, int offsetY) { if (outOfBoundsRight && mapRight - rightSideInfowWindow < marginHorizontal) { x -= marginHorizontal - (mapRight - rightSideInfowWindow); tipViewMarginLeft += marginHorizontal - (mapRight - rightSideInfowWindow) - tipViewOffset; - leftSideInfoWindow = x; } @@ -141,7 +143,6 @@ InfoWindow open(Marker boundMarker, LatLng position, int offsetX, int offsetY) { if (outOfBoundsLeft && leftSideInfoWindow - mapLeft < marginHorizontal) { x += marginHorizontal - (leftSideInfoWindow - mapLeft); tipViewMarginLeft -= (marginHorizontal - (leftSideInfoWindow - mapLeft)) - tipViewOffset; - } // Adjust tipView @@ -153,7 +154,8 @@ InfoWindow open(Marker boundMarker, LatLng position, int offsetX, int offsetY) { mView.setX(x); mView.setY(y); - mViewWidthOffset = x - (coords.x - (mView.getMeasuredWidth() / 2) + offsetX); + // Calculate x-offset for update method + mViewWidthOffset = x - mCoordinates.x - offsetX; close(); //if it was already opened mMapView.get().addView(mView, lp); @@ -237,9 +239,9 @@ public void update() { MapView mapView = mMapView.get(); Marker marker = mBoundMarker.get(); if (mapView != null && marker != null) { - PointF pointF = mapView.toScreenLocation(marker.getPosition()); - mView.setX((pointF.x - (mView.getWidth() / 2)) + mViewWidthOffset); - mView.setY(pointF.y - mView.getHeight() + mMarkerHeightOffset); + mCoordinates = mapView.toScreenLocation(marker.getPosition()); + mView.setX(mCoordinates.x + mViewWidthOffset); + mView.setY(mCoordinates.y + mMarkerHeightOffset); } } From e9d749b775e2284b6866d362d4588a847a178e98 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Mon, 30 Nov 2015 11:32:25 -0500 Subject: [PATCH 6/6] add flag to let concurrent multiple infowindows to be shown --- .../com/mapbox/mapboxsdk/views/MapView.java | 32 +++++++++++++++++-- .../mapboxsdk/testapp/InfoWindowActivity.java | 3 ++ .../testapp/InfoWindowAdapterActivity.java | 3 ++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java index a5758bbeef4..5a6b8c80ed1 100644 --- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java +++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java @@ -240,6 +240,7 @@ public final class MapView extends FrameLayout { private boolean mZoomEnabled = true; private boolean mScrollEnabled = true; private boolean mRotateEnabled = true; + private boolean mAllowConcurrentMultipleOpenInfoWindows = false; private String mStyleUrl; // @@ -1292,6 +1293,30 @@ private void zoom(boolean zoomIn, float x, float y) { } } + // + // InfoWindows + // + + /** + * Changes whether the map allows concurrent multiple infowindows to be shown. + * + * @param allow If true, map allows concurrent multiple infowindows to be shown. + */ + @UiThread + public void setAllowConcurrentMultipleOpenInfoWindows(boolean allow) { + this.mAllowConcurrentMultipleOpenInfoWindows = allow; + } + + /** + * Returns whether the map allows concurrent multiple infowindows to be shown. + * + * @return If true, map allows concurrent multiple infowindows to be shown. + */ + @UiThread + public boolean isAllowConcurrentMultipleOpenInfoWindows() { + return this.mAllowConcurrentMultipleOpenInfoWindows; + } + // // Debug // @@ -2003,7 +2028,8 @@ public double getMetersPerPixelAtLatitude(@FloatRange(from = -180, to = 180) dou /** * Selects a marker. The selected marker will have it's info window opened. - * Any other open info windows will be closed. + * Any other open info windows will be closed unless isAllowConcurrentMultipleOpenInfoWindows() + * is true. *

* Selecting an already selected marker will have no effect. * @@ -2021,7 +2047,9 @@ public void selectMarker(@NonNull Marker marker) { } // Need to deselect any currently selected annotation first - deselectMarker(marker); + if (!isAllowConcurrentMultipleOpenInfoWindows()) { + deselectMarkers(); + } boolean handledDefaultClick = false; if (mOnMarkerClickListener != null) { diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowActivity.java b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowActivity.java index f53f923b0e4..5764b670174 100644 --- a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowActivity.java +++ b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowActivity.java @@ -35,6 +35,9 @@ protected void onCreate(Bundle savedInstanceState) { mMapView.setAccessToken(ApiAccess.getToken(this)); mMapView.onCreate(savedInstanceState); + // Enable to let concurrent multiple infowindows to be shown. + //mMapView.setAllowConcurrentMultipleOpenInfoWindows(true); + mMapView.addMarker(new MarkerOptions() .title("Intersection") .snippet("H St NW with 15th St NW") diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowAdapterActivity.java b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowAdapterActivity.java index 0a489edaa18..97f5f3faa16 100644 --- a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowAdapterActivity.java +++ b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowAdapterActivity.java @@ -64,6 +64,9 @@ public View getInfoWindow(@NonNull Marker marker) { } }); + // Enable to let concurrent multiple infowindows to be shown. + //mMapView.setAllowConcurrentMultipleOpenInfoWindows(true); + mMapView.addMarker(generateMarker("Andorra", 42.505777, 1.52529, "#F44336")); mMapView.addMarker(generateMarker("Luxembourg", 49.815273, 6.129583, "#3F51B5")); mMapView.addMarker(generateMarker("Monaco", 43.738418, 7.424616, "#673AB7"));