Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - getMarkerViews in rect should return in bound views (#7016)
Browse files Browse the repository at this point in the history
* [android] - getMarkerViews in rectangle should only return in bound views.

* [android] - make calculating a density dependable rectangle part of getMarkersInRect/getMarkerViewInRect
  • Loading branch information
tobrun authored Nov 14, 2016
1 parent d310219 commit 1d497d9
Showing 1 changed file with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1221,11 +1221,16 @@ void removeAnnotations(@NonNull long[] ids) {
nativeMapView.removeAnnotations(ids);
}

List<Marker> getMarkersInRect(@NonNull RectF rect) {
if (destroyed || rect == null) {
List<Marker> getMarkersInRect(@NonNull RectF rectangle) {
if (destroyed || rectangle == null) {
return new ArrayList<>();
}

RectF rect = new RectF(rectangle.left / screenDensity,
rectangle.top / screenDensity,
rectangle.right / screenDensity,
rectangle.bottom / screenDensity);

long[] ids = nativeMapView.queryPointAnnotations(rect);

List<Long> idsList = new ArrayList<>(ids.length);
Expand All @@ -1246,11 +1251,16 @@ List<Marker> getMarkersInRect(@NonNull RectF rect) {
return new ArrayList<>(annotations);
}

public List<MarkerView> getMarkerViewsInRect(@NonNull RectF rect) {
if (destroyed || rect == null) {
public List<MarkerView> getMarkerViewsInRect(@NonNull RectF rectangle) {
if (destroyed || rectangle == null) {
return new ArrayList<>();
}

RectF rect = new RectF(rectangle.left / screenDensity,
rectangle.top / screenDensity,
rectangle.right / screenDensity,
rectangle.bottom / screenDensity);

long[] ids = nativeMapView.queryPointAnnotations(rect);

List<Long> idsList = new ArrayList<>(ids.length);
Expand All @@ -1263,7 +1273,7 @@ public List<MarkerView> getMarkerViewsInRect(@NonNull RectF rect) {
int count = annotationList.size();
for (int i = 0; i < count; i++) {
Annotation annotation = annotationList.get(i);
if (annotation instanceof MarkerView) {
if (annotation instanceof MarkerView && idsList.contains(annotation.getId())) {
annotations.add((MarkerView) annotation);
}
}
Expand Down Expand Up @@ -1871,10 +1881,10 @@ public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
float toleranceSides = 4 * screenDensity;
float toleranceTopBottom = 10 * screenDensity;

RectF tapRect = new RectF((tapPoint.x - averageIconWidth / 2 - toleranceSides) / screenDensity,
(tapPoint.y - averageIconHeight / 2 - toleranceTopBottom) / screenDensity,
(tapPoint.x + averageIconWidth / 2 + toleranceSides) / screenDensity,
(tapPoint.y + averageIconHeight / 2 + toleranceTopBottom) / screenDensity);
RectF tapRect = new RectF(tapPoint.x - averageIconWidth / 2 - toleranceSides,
tapPoint.y - averageIconHeight / 2 - toleranceTopBottom,
tapPoint.x + averageIconWidth / 2 + toleranceSides,
tapPoint.y + averageIconHeight / 2 + toleranceTopBottom);

List<Marker> nearbyMarkers = getMarkersInRect(tapRect);
long newSelectedMarkerId = -1;
Expand Down

0 comments on commit 1d497d9

Please sign in to comment.