Small refactoring
This commit is contained in:
parent
d277c9ed5e
commit
b2116a6bc8
5 changed files with 35 additions and 68 deletions
|
@ -83,10 +83,7 @@ public class AudioNotesLayer extends OsmandMapLayer implements IContextMenuProvi
|
||||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||||
if (tileBox.getZoom() >= startZoom) {
|
if (tileBox.getZoom() >= startZoom) {
|
||||||
float iconSize = audio.getWidth() * 3 / 2.5f;
|
float iconSize = audio.getWidth() * 3 / 2.5f;
|
||||||
QuadRect bounds = new QuadRect(0, 0, tileBox.getPixWidth(), tileBox.getPixHeight());
|
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
|
||||||
bounds.inset(-bounds.width()/4, -bounds.height()/4);
|
|
||||||
QuadTree<QuadRect> boundIntersections = new QuadTree<>(bounds, 4, 0.6f);
|
|
||||||
List<QuadRect> result = new ArrayList<>();
|
|
||||||
|
|
||||||
DataTileManager<Recording> recs = plugin.getRecordings();
|
DataTileManager<Recording> recs = plugin.getRecordings();
|
||||||
final QuadRect latlon = tileBox.getLatLonBounds();
|
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 x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
|
||||||
float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
|
float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
|
||||||
|
|
||||||
boolean intersects = false;
|
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
|
||||||
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) {
|
|
||||||
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
|
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
|
||||||
} else {
|
} else {
|
||||||
boundIntersections.insert(visibleRect,
|
|
||||||
new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom));
|
|
||||||
fullObjects.add(o);
|
fullObjects.add(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,10 +91,8 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
||||||
if (tileBox.getZoom() >= startZoom) {
|
if (tileBox.getZoom() >= startZoom) {
|
||||||
float iconSize = FavoriteImageDrawable.getOrCreate(view.getContext(), 0,
|
float iconSize = FavoriteImageDrawable.getOrCreate(view.getContext(), 0,
|
||||||
tileBox.getDensity()).getIntrinsicWidth() * 3 / 2.5f;
|
tileBox.getDensity()).getIntrinsicWidth() * 3 / 2.5f;
|
||||||
QuadRect bounds = new QuadRect(0, 0, tileBox.getPixWidth(), tileBox.getPixHeight());
|
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
|
||||||
bounds.inset(-bounds.width()/4, -bounds.height()/4);
|
|
||||||
QuadTree<QuadRect> boundIntersections = new QuadTree<>(bounds, 4, 0.6f);
|
|
||||||
List<QuadRect> result = new ArrayList<>();
|
|
||||||
// request to load
|
// request to load
|
||||||
final QuadRect latLonBounds = tileBox.getLatLonBounds();
|
final QuadRect latLonBounds = tileBox.getLatLonBounds();
|
||||||
List<LocationPoint> fullObjects = new ArrayList<>();
|
List<LocationPoint> fullObjects = new ArrayList<>();
|
||||||
|
@ -102,21 +100,9 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
||||||
float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
|
float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
|
||||||
float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
|
float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
|
||||||
|
|
||||||
boolean intersects = false;
|
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
|
||||||
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) {
|
|
||||||
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
|
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
|
||||||
} else {
|
} else {
|
||||||
boundIntersections.insert(visibleRect,
|
|
||||||
new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom));
|
|
||||||
fullObjects.add(o);
|
fullObjects.add(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import android.graphics.Path;
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
import android.graphics.PorterDuff.Mode;
|
import android.graphics.PorterDuff.Mode;
|
||||||
import android.graphics.PorterDuffColorFilter;
|
import android.graphics.PorterDuffColorFilter;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
|
@ -277,10 +278,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
||||||
if (tileBox.getZoom() >= startZoom) {
|
if (tileBox.getZoom() >= startZoom) {
|
||||||
float iconSize = FavoriteImageDrawable.getOrCreate(view.getContext(), 0,
|
float iconSize = FavoriteImageDrawable.getOrCreate(view.getContext(), 0,
|
||||||
tileBox.getDensity()).getIntrinsicWidth() * 3 / 2.5f;
|
tileBox.getDensity()).getIntrinsicWidth() * 3 / 2.5f;
|
||||||
QuadRect bounds = new QuadRect(0, 0, tileBox.getPixWidth(), tileBox.getPixHeight());
|
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
|
||||||
bounds.inset(-bounds.width()/4, -bounds.height()/4);
|
|
||||||
QuadTree<QuadRect> boundIntersections = new QuadTree<>(bounds, 4, 0.6f);
|
|
||||||
List<QuadRect> result = new ArrayList<>();
|
|
||||||
// request to load
|
// request to load
|
||||||
final QuadRect latLonBounds = tileBox.getLatLonBounds();
|
final QuadRect latLonBounds = tileBox.getLatLonBounds();
|
||||||
for (SelectedGpxFile g : selectedGPXFiles) {
|
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 x = tileBox.getPixXFromLatLon(o.lat, o.lon);
|
||||||
float y = tileBox.getPixYFromLatLon(o.lat, o.lon);
|
float y = tileBox.getPixYFromLatLon(o.lat, o.lon);
|
||||||
|
|
||||||
boolean intersects = false;
|
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
|
||||||
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) {
|
|
||||||
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
|
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
|
||||||
} else {
|
} else {
|
||||||
boundIntersections.insert(visibleRect,
|
|
||||||
new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom));
|
|
||||||
fullObjects.add(o);
|
fullObjects.add(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,12 @@ package net.osmand.plus.views;
|
||||||
|
|
||||||
import gnu.trove.list.array.TIntArrayList;
|
import gnu.trove.list.array.TIntArrayList;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import net.osmand.data.QuadRect;
|
import net.osmand.data.QuadRect;
|
||||||
|
import net.osmand.data.QuadTree;
|
||||||
import net.osmand.data.RotatedTileBox;
|
import net.osmand.data.RotatedTileBox;
|
||||||
import net.osmand.plus.ContextMenuAdapter;
|
import net.osmand.plus.ContextMenuAdapter;
|
||||||
import net.osmand.util.MapAlgorithms;
|
import net.osmand.util.MapAlgorithms;
|
||||||
|
@ -13,6 +15,7 @@ import android.graphics.Canvas;
|
||||||
import android.graphics.Path;
|
import android.graphics.Path;
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
public abstract class OsmandMapLayer {
|
public abstract class OsmandMapLayer {
|
||||||
|
@ -158,6 +161,27 @@ public abstract class OsmandMapLayer {
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public QuadTree<QuadRect> 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<QuadRect> boundIntersections, float x, float y, float width, float height) {
|
||||||
|
List<QuadRect> 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) {
|
public QuadRect calculateRect(float x, float y, float width, float height) {
|
||||||
QuadRect rf;
|
QuadRect rf;
|
||||||
double left = x - width / 2.0d;
|
double left = x - width / 2.0d;
|
||||||
|
|
|
@ -238,10 +238,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
|
||||||
objects = data.getResults();
|
objects = data.getResults();
|
||||||
if (objects != null) {
|
if (objects != null) {
|
||||||
float iconSize = poiBackground.getWidth() * 3 / 2;
|
float iconSize = poiBackground.getWidth() * 3 / 2;
|
||||||
QuadRect bounds = new QuadRect(0, 0, tileBox.getPixWidth(), tileBox.getPixHeight());
|
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
|
||||||
bounds.inset(-bounds.width()/4, -bounds.height()/4);
|
|
||||||
QuadTree<QuadRect> boundIntersections = new QuadTree<>(bounds, 4, 0.6f);
|
|
||||||
List<QuadRect> result = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Amenity o : objects) {
|
for (Amenity o : objects) {
|
||||||
float x = tileBox.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation()
|
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()
|
float y = tileBox.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation()
|
||||||
.getLongitude());
|
.getLongitude());
|
||||||
|
|
||||||
boolean intersects = false;
|
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
|
||||||
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) {
|
|
||||||
canvas.drawBitmap(poiBackgroundSmall, x - poiBackgroundSmall.getWidth() / 2, y - poiBackgroundSmall.getHeight() / 2, paintIconBackground);
|
canvas.drawBitmap(poiBackgroundSmall, x - poiBackgroundSmall.getWidth() / 2, y - poiBackgroundSmall.getHeight() / 2, paintIconBackground);
|
||||||
} else {
|
} else {
|
||||||
boundIntersections.insert(visibleRect,
|
|
||||||
new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom));
|
|
||||||
fullObjects.add(o);
|
fullObjects.add(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue