diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioNotesLayer.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioNotesLayer.java index fa79ab6262..57210a1463 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioNotesLayer.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioNotesLayer.java @@ -83,10 +83,7 @@ public class AudioNotesLayer extends OsmandMapLayer implements IContextMenuProvi public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { if (tileBox.getZoom() >= startZoom) { float iconSize = audio.getWidth() * 3 / 2.5f; - QuadRect bounds = new QuadRect(0, 0, tileBox.getPixWidth(), tileBox.getPixHeight()); - bounds.inset(-bounds.width()/4, -bounds.height()/4); - QuadTree boundIntersections = new QuadTree<>(bounds, 4, 0.6f); - List result = new ArrayList<>(); + QuadTree boundIntersections = initBoundIntersections(tileBox); DataTileManager recs = plugin.getRecordings(); final QuadRect latlon = tileBox.getLatLonBounds(); @@ -96,21 +93,9 @@ public class AudioNotesLayer extends OsmandMapLayer implements IContextMenuProvi float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude()); float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude()); - boolean intersects = false; - QuadRect visibleRect = calculateRect(x, y, iconSize, iconSize); - boundIntersections.queryInBox(new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom), result); - for (QuadRect r : result) { - if (QuadRect.intersects(r, visibleRect)) { - intersects = true; - break; - } - } - - if (intersects) { + if (intersects(boundIntersections, x, y, iconSize, iconSize)) { canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon); } else { - boundIntersections.insert(visibleRect, - new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom)); fullObjects.add(o); } } diff --git a/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java b/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java index c5722dc11d..0d8c8361c2 100644 --- a/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java @@ -91,10 +91,8 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer. if (tileBox.getZoom() >= startZoom) { float iconSize = FavoriteImageDrawable.getOrCreate(view.getContext(), 0, tileBox.getDensity()).getIntrinsicWidth() * 3 / 2.5f; - QuadRect bounds = new QuadRect(0, 0, tileBox.getPixWidth(), tileBox.getPixHeight()); - bounds.inset(-bounds.width()/4, -bounds.height()/4); - QuadTree boundIntersections = new QuadTree<>(bounds, 4, 0.6f); - List result = new ArrayList<>(); + QuadTree boundIntersections = initBoundIntersections(tileBox); + // request to load final QuadRect latLonBounds = tileBox.getLatLonBounds(); List fullObjects = new ArrayList<>(); @@ -102,21 +100,9 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer. float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude()); float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude()); - boolean intersects = false; - QuadRect visibleRect = calculateRect(x, y, iconSize, iconSize); - boundIntersections.queryInBox(new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom), result); - for (QuadRect r : result) { - if (QuadRect.intersects(r, visibleRect)) { - intersects = true; - break; - } - } - - if (intersects) { + if (intersects(boundIntersections, x, y, iconSize, iconSize)) { canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon); } else { - boundIntersections.insert(visibleRect, - new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom)); fullObjects.add(o); } } diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 2cfa127753..a65ee60e2b 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -12,6 +12,7 @@ import android.graphics.Path; import android.graphics.PointF; import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuffColorFilter; +import android.support.annotation.NonNull; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -277,10 +278,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex if (tileBox.getZoom() >= startZoom) { float iconSize = FavoriteImageDrawable.getOrCreate(view.getContext(), 0, tileBox.getDensity()).getIntrinsicWidth() * 3 / 2.5f; - QuadRect bounds = new QuadRect(0, 0, tileBox.getPixWidth(), tileBox.getPixHeight()); - bounds.inset(-bounds.width()/4, -bounds.height()/4); - QuadTree boundIntersections = new QuadTree<>(bounds, 4, 0.6f); - List result = new ArrayList<>(); + QuadTree boundIntersections = initBoundIntersections(tileBox); + // request to load final QuadRect latLonBounds = tileBox.getLatLonBounds(); for (SelectedGpxFile g : selectedGPXFiles) { @@ -294,21 +293,9 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex float x = tileBox.getPixXFromLatLon(o.lat, o.lon); float y = tileBox.getPixYFromLatLon(o.lat, o.lon); - boolean intersects = false; - QuadRect visibleRect = calculateRect(x, y, iconSize, iconSize); - boundIntersections.queryInBox(new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom), result); - for (QuadRect r : result) { - if (QuadRect.intersects(r, visibleRect)) { - intersects = true; - break; - } - } - - if (intersects) { + if (intersects(boundIntersections, x, y, iconSize, iconSize)) { canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon); } else { - boundIntersections.insert(visibleRect, - new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom)); fullObjects.add(o); } } diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index 19c755acb1..04de4a573f 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -2,10 +2,12 @@ package net.osmand.plus.views; import gnu.trove.list.array.TIntArrayList; +import java.util.ArrayList; import java.util.List; import java.util.Map; import net.osmand.data.QuadRect; +import net.osmand.data.QuadTree; import net.osmand.data.RotatedTileBox; import net.osmand.plus.ContextMenuAdapter; import net.osmand.util.MapAlgorithms; @@ -13,6 +15,7 @@ import android.graphics.Canvas; import android.graphics.Path; import android.graphics.PointF; import android.os.AsyncTask; +import android.support.annotation.NonNull; import android.view.MotionEvent; public abstract class OsmandMapLayer { @@ -158,6 +161,27 @@ public abstract class OsmandMapLayer { return cnt; } + @NonNull + public QuadTree initBoundIntersections(RotatedTileBox tileBox) { + QuadRect bounds = new QuadRect(0, 0, tileBox.getPixWidth(), tileBox.getPixHeight()); + bounds.inset(-bounds.width()/4, -bounds.height()/4); + return new QuadTree<>(bounds, 4, 0.6f); + } + + public boolean intersects(QuadTree boundIntersections, float x, float y, float width, float height) { + List result = new ArrayList<>(); + QuadRect visibleRect = calculateRect(x, y, width, height); + boundIntersections.queryInBox(new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom), result); + for (QuadRect r : result) { + if (QuadRect.intersects(r, visibleRect)) { + return true; + } + } + boundIntersections.insert(visibleRect, + new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom)); + return false; + } + public QuadRect calculateRect(float x, float y, float width, float height) { QuadRect rf; double left = x - width / 2.0d; diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index ef320fa40b..0e4d34473a 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -238,10 +238,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon objects = data.getResults(); if (objects != null) { float iconSize = poiBackground.getWidth() * 3 / 2; - QuadRect bounds = new QuadRect(0, 0, tileBox.getPixWidth(), tileBox.getPixHeight()); - bounds.inset(-bounds.width()/4, -bounds.height()/4); - QuadTree boundIntersections = new QuadTree<>(bounds, 4, 0.6f); - List result = new ArrayList<>(); + QuadTree boundIntersections = initBoundIntersections(tileBox); for (Amenity o : objects) { float x = tileBox.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation() @@ -249,21 +246,9 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon float y = tileBox.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation() .getLongitude()); - boolean intersects = false; - QuadRect visibleRect = calculateRect(x, y, iconSize, iconSize); - boundIntersections.queryInBox(new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom), result); - for (QuadRect r : result) { - if (QuadRect.intersects(r, visibleRect)) { - intersects = true; - break; - } - } - - if (intersects) { + if (intersects(boundIntersections, x, y, iconSize, iconSize)) { canvas.drawBitmap(poiBackgroundSmall, x - poiBackgroundSmall.getWidth() / 2, y - poiBackgroundSmall.getHeight() / 2, paintIconBackground); } else { - boundIntersections.insert(visibleRect, - new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom)); fullObjects.add(o); } }