[core, android, ios, macos] Replaced getPointAnnotationsInBounds() w/ queryPointAnnotations() (#5165)
queryPointAnnotations() accepts a screen rectangle instead of a geographic bounding box, so marker hit testing works at the edges of a rotated, tilted map view. Fixes #5151.
This commit is contained in:
committed by
Jesse Bounds
parent
272ec0c30b
commit
e147887e35
@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.annotations;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.RectF;
|
||||
import android.os.SystemClock;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -321,7 +322,7 @@ public class MarkerViewManager {
|
||||
|
||||
if (!markerViewAdapters.contains(markerViewAdapter)) {
|
||||
markerViewAdapters.add(markerViewAdapter);
|
||||
invalidateViewMarkersInBounds();
|
||||
invalidateViewMarkersInVisibleRegion();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,7 +347,7 @@ public class MarkerViewManager {
|
||||
/**
|
||||
* Schedule that ViewMarkers found in the viewport are invalidated.
|
||||
* <p>
|
||||
* This method is rate limited, and {@link #invalidateViewMarkersInBounds} will only be called
|
||||
* This method is rate limited, and {@link #invalidateViewMarkersInVisibleRegion} will only be called
|
||||
* once each 250 ms.
|
||||
* </p>
|
||||
*/
|
||||
@@ -356,7 +357,7 @@ public class MarkerViewManager {
|
||||
if (currentTime < viewMarkerBoundsUpdateTime) {
|
||||
return;
|
||||
}
|
||||
invalidateViewMarkersInBounds();
|
||||
invalidateViewMarkersInVisibleRegion();
|
||||
viewMarkerBoundsUpdateTime = currentTime + 250;
|
||||
}
|
||||
}
|
||||
@@ -368,9 +369,9 @@ public class MarkerViewManager {
|
||||
* ones for each found Marker in the changed viewport.
|
||||
* </p>
|
||||
*/
|
||||
public void invalidateViewMarkersInBounds() {
|
||||
Projection projection = mapboxMap.getProjection();
|
||||
List<MarkerView> markers = mapView.getMarkerViewsInBounds(projection.getVisibleRegion().latLngBounds);
|
||||
public void invalidateViewMarkersInVisibleRegion() {
|
||||
RectF mapViewRect = new RectF(0, 0, mapView.getWidth(), mapView.getHeight());
|
||||
List<MarkerView> markers = mapView.getMarkerViewsInRect(mapViewRect);
|
||||
View convertView;
|
||||
|
||||
// remove old markers
|
||||
|
||||
@@ -1153,13 +1153,13 @@ public class MapView extends FrameLayout {
|
||||
mNativeMapView.removeAnnotations(ids);
|
||||
}
|
||||
|
||||
List<Marker> getMarkersInBounds(@NonNull LatLngBounds bbox) {
|
||||
if (mDestroyed || bbox == null) {
|
||||
List<Marker> getMarkersInRect(@NonNull RectF rect) {
|
||||
if (mDestroyed || rect == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// TODO: filter in JNI using C++ parameter to getAnnotationsInBounds
|
||||
long[] ids = mNativeMapView.getAnnotationsInBounds(bbox);
|
||||
// TODO: filter in JNI using C++ parameter to queryPointAnnotations
|
||||
long[] ids = mNativeMapView.queryPointAnnotations(rect);
|
||||
|
||||
List<Long> idsList = new ArrayList<>(ids.length);
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
@@ -1179,13 +1179,13 @@ public class MapView extends FrameLayout {
|
||||
return new ArrayList<>(annotations);
|
||||
}
|
||||
|
||||
public List<MarkerView> getMarkerViewsInBounds(@NonNull LatLngBounds bbox) {
|
||||
if (mDestroyed || bbox == null) {
|
||||
public List<MarkerView> getMarkerViewsInRect(@NonNull RectF rect) {
|
||||
if (mDestroyed || rect == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// TODO: filter in JNI using C++ parameter to getAnnotationsInBounds
|
||||
long[] ids = mNativeMapView.getAnnotationsInBounds(bbox);
|
||||
// TODO: filter in JNI using C++ parameter to queryPointAnnotations
|
||||
long[] ids = mNativeMapView.queryPointAnnotations(rect);
|
||||
|
||||
List<Long> idsList = new ArrayList<>(ids.length);
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
@@ -1730,13 +1730,7 @@ public class MapView extends FrameLayout {
|
||||
tapPoint.x + mAverageIconWidth / 2 + toleranceSides,
|
||||
tapPoint.y + mAverageIconHeight / 2 + toleranceTopBottom);
|
||||
|
||||
LatLngBounds.Builder builder = new LatLngBounds.Builder();
|
||||
builder.include(fromScreenLocation(new PointF(tapRect.left, tapRect.bottom)));
|
||||
builder.include(fromScreenLocation(new PointF(tapRect.left, tapRect.top)));
|
||||
builder.include(fromScreenLocation(new PointF(tapRect.right, tapRect.top)));
|
||||
builder.include(fromScreenLocation(new PointF(tapRect.right, tapRect.bottom)));
|
||||
|
||||
List<Marker> nearbyMarkers = getMarkersInBounds(builder.build());
|
||||
List<Marker> nearbyMarkers = getMarkersInRect(tapRect);
|
||||
long newSelectedMarkerId = -1;
|
||||
|
||||
if (nearbyMarkers != null && nearbyMarkers.size() > 0) {
|
||||
|
||||
@@ -765,7 +765,7 @@ public class MapboxMap {
|
||||
long id = mMapView.addMarker(marker);
|
||||
marker.setId(id);
|
||||
mAnnotations.put(id, marker);
|
||||
mMarkerViewManager.invalidateViewMarkersInBounds();
|
||||
mMarkerViewManager.invalidateViewMarkersInVisibleRegion();
|
||||
return marker;
|
||||
}
|
||||
|
||||
|
||||
@@ -402,8 +402,8 @@ final class NativeMapView {
|
||||
nativeRemoveAnnotations(mNativeMapViewPtr, ids);
|
||||
}
|
||||
|
||||
public long[] getAnnotationsInBounds(LatLngBounds bbox) {
|
||||
return nativeGetAnnotationsInBounds(mNativeMapViewPtr, bbox);
|
||||
public long[] queryPointAnnotations(RectF rect) {
|
||||
return nativeQueryPointAnnotations(mNativeMapViewPtr, rect);
|
||||
}
|
||||
|
||||
public void addAnnotationIcon(String symbol, int width, int height, float scale, byte[] pixels) {
|
||||
@@ -641,7 +641,7 @@ final class NativeMapView {
|
||||
|
||||
private native void nativeRemoveAnnotations(long nativeMapViewPtr, long[] id);
|
||||
|
||||
private native long[] nativeGetAnnotationsInBounds(long mNativeMapViewPtr, LatLngBounds bbox);
|
||||
private native long[] nativeQueryPointAnnotations(long mNativeMapViewPtr, RectF rect);
|
||||
|
||||
private native void nativeAddAnnotationIcon(long nativeMapViewPtr, String symbol,
|
||||
int width, int height, float scale, byte[] pixels);
|
||||
|
||||
Reference in New Issue
Block a user