summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2017-01-26 18:35:26 +0100
committerGitHub <noreply@github.com>2017-01-26 18:35:26 +0100
commit00598432b0cc7b8aefd63b5162ad317917eb1154 (patch)
treee190e36316e43290b0982fd16c6eec545f64f373
parent7e1b3b8ce0d55579e7883016769cc8376f2a6a8a (diff)
downloadqtlocation-mapboxgl-00598432b0cc7b8aefd63b5162ad317917eb1154.tar.gz
[android] - trigger marker click event for clicking selected marker (#7830)
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java23
1 files changed, 21 insertions, 2 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java
index 05b37bc80d..8b47fb1d51 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java
@@ -359,6 +359,7 @@ class AnnotationManager {
return selectedMarkers;
}
+ @NonNull
List<Marker> getMarkersInRect(@NonNull RectF rectangle) {
// convert Rectangle to be density depedent
float pixelRatio = nativeMapView.getPixelRatio();
@@ -622,6 +623,7 @@ class AnnotationManager {
boolean onTap(PointF tapPoint, float screenDensity) {
float toleranceSides = 4 * screenDensity;
float toleranceTopBottom = 10 * screenDensity;
+ boolean handledDefaultClick = false;
RectF tapRect = new RectF(tapPoint.x - iconManager.getAverageIconWidth() / 2 - toleranceSides,
tapPoint.y - iconManager.getAverageIconHeight() / 2 - toleranceTopBottom,
@@ -631,7 +633,8 @@ class AnnotationManager {
List<Marker> nearbyMarkers = getMarkersInRect(tapRect);
long newSelectedMarkerId = -1;
- if (nearbyMarkers != null && nearbyMarkers.size() > 0) {
+ // find a Marker that isn't selected yet
+ if (nearbyMarkers.size() > 0) {
Collections.sort(nearbyMarkers);
for (Marker nearbyMarker : nearbyMarkers) {
boolean found = false;
@@ -647,6 +650,7 @@ class AnnotationManager {
}
}
+ // if unselected marker found
if (newSelectedMarkerId >= 0) {
List<Annotation> annotations = getAnnotations();
int count = annotations.size();
@@ -655,7 +659,6 @@ class AnnotationManager {
if (annotation instanceof Marker) {
if (annotation.getId() == newSelectedMarkerId) {
Marker marker = (Marker) annotation;
- boolean handledDefaultClick = false;
if (marker instanceof MarkerView) {
handledDefaultClick = markerViewManager.onClickMarkerView((MarkerView) marker);
@@ -679,6 +682,22 @@ class AnnotationManager {
}
}
}
+ } else if (nearbyMarkers.size() > 0) {
+ // we didn't find an unselected marker, check if we can close an already open markers
+ for (Marker nearbyMarker : nearbyMarkers) {
+ for (Marker selectedMarker : selectedMarkers) {
+ if (nearbyMarker.equals(selectedMarker)) {
+ if (onMarkerClickListener != null) {
+ // end developer has provided a custom click listener
+ handledDefaultClick = onMarkerClickListener.onMarkerClick(nearbyMarker);
+ if (!handledDefaultClick) {
+ deselectMarker(nearbyMarker);
+ }
+ }
+ return true;
+ }
+ }
+ }
}
return false;
}