use of net.osmand.data.QuadRect in project Osmand by osmandapp.
the class SQLiteTileSource method getRectBoundary.
public QuadRect getRectBoundary(int coordinatesZoom, int minZ) {
SQLiteConnection db = getDatabase();
if (db == null || coordinatesZoom > 25) {
return null;
}
SQLiteCursor q;
if (inversiveZoom) {
int minZoom = (17 - minZ) + 1;
// 17 - z = zoom, x << (25 - zoom) = 25th x tile = 8 + z,
q = db.rawQuery("SELECT max(x << (8+z)), min(x << (8+z)), max(y << (8+z)), min(y << (8+z))" + " from tiles where z < " + minZoom, new String[0]);
} else {
q = db.rawQuery("SELECT max(x << (25-z)), min(x << (25-z)), max(y << (25-z)), min(y << (25-z))" + " from tiles where z > " + minZ, new String[0]);
}
q.moveToFirst();
int right = (int) (q.getInt(0) >> (25 - coordinatesZoom));
int left = (int) (q.getInt(1) >> (25 - coordinatesZoom));
int top = (int) (q.getInt(3) >> (25 - coordinatesZoom));
int bottom = (int) (q.getInt(2) >> (25 - coordinatesZoom));
return new QuadRect(left, top, right, bottom);
}
use of net.osmand.data.QuadRect in project Osmand by osmandapp.
the class TransportStopsLayer method onPrepareBufferImage.
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
List<TransportStop> objects = null;
if (tb.getZoom() >= startZoomRoute) {
if (stopRoute != null) {
objects = stopRoute.route.getForwardStops();
int color = stopRoute.getColor(mapActivity.getMyApplication(), settings.isNightMode());
attrs.paint.setColor(color);
attrs.updatePaints(view, settings, tb);
try {
path.reset();
List<Way> ws = stopRoute.route.getForwardWays();
if (ws != null) {
for (Way w : ws) {
TIntArrayList tx = new TIntArrayList();
TIntArrayList ty = new TIntArrayList();
for (int i = 0; i < w.getNodes().size(); i++) {
Node o = w.getNodes().get(i);
int x = (int) tb.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
int y = (int) tb.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
tx.add(x);
ty.add(y);
}
calculatePath(tb, tx, ty, path);
}
}
attrs.drawPath(canvas, path);
} catch (Exception e) {
// ignore
}
}
}
if (showTransportStops && tb.getZoom() >= startZoom && objects == null) {
data.queryNewData(tb);
objects = data.getResults();
}
if (objects != null) {
float iconSize = stopBus.getWidth() * 3 / 2.5f;
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tb);
List<TransportStop> fullObjects = new ArrayList<>();
for (TransportStop o : objects) {
float x = tb.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
float y = tb.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
canvas.drawBitmap(stopSmall, x - stopSmall.getWidth() / 2, y - stopSmall.getHeight() / 2, paintIcon);
} else {
fullObjects.add(o);
}
}
for (TransportStop o : fullObjects) {
float x = tb.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
float y = tb.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
if (stopRoute != null) {
TransportStopType type = TransportStopType.findType(stopRoute.route.getType());
if (type != null) {
Bitmap foregroundIcon = RenderingIcons.getIcon(mapActivity, type.getResName(), false);
canvas.drawBitmap(backgroundIcon, x - backgroundIconHalfWidth, y - backgroundIconHalfHeight, paintIcon);
canvas.drawBitmap(foregroundIcon, x - foregroundIcon.getWidth() / 2, y - foregroundIcon.getHeight() / 2, paintWhiteIcon);
}
} else {
Bitmap b = stopBus;
canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon);
}
}
}
}
use of net.osmand.data.QuadRect in project Osmand by osmandapp.
the class TransportStopsLayer method initLayer.
@SuppressWarnings("deprecation")
@Override
public void initLayer(final OsmandMapTileView view) {
backgroundIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_bg);
backgroundIconHalfWidth = backgroundIcon.getWidth() / 2;
backgroundIconHalfHeight = backgroundIcon.getWidth() / 2;
this.view = view;
DisplayMetrics dm = new DisplayMetrics();
WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.getDefaultDisplay().getMetrics(dm);
paintIcon = new Paint();
paintWhiteIcon = new Paint();
paintWhiteIcon.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(mapActivity, R.color.primary_text_dark), PorterDuff.Mode.SRC_IN));
path = new Path();
stopBus = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_bus);
stopSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_small);
attrs = new RenderingLineAttributes("transport_route");
attrs.defaultWidth = (int) (6 * view.getDensity());
data = new OsmandMapLayer.MapLayerData<List<TransportStop>>() {
{
ZOOM_THRESHOLD = 0;
}
@Override
public boolean isInterrupted() {
return super.isInterrupted();
}
@Override
public void layerOnPostExecute() {
view.refreshMap();
}
@Override
protected List<TransportStop> calculateResult(RotatedTileBox tileBox) {
QuadRect latLonBounds = tileBox.getLatLonBounds();
if (latLonBounds == null) {
return new ArrayList<>();
}
List<TransportStop> res = view.getApplication().getResourceManager().searchTransportSync(latLonBounds.top, latLonBounds.left, latLonBounds.bottom, latLonBounds.right, new ResultMatcher<TransportStop>() {
@Override
public boolean publish(TransportStop object) {
return true;
}
@Override
public boolean isCancelled() {
return isInterrupted();
}
});
Collections.sort(res, new Comparator<TransportStop>() {
@Override
public int compare(TransportStop lhs, TransportStop rhs) {
return lhs.getId() < rhs.getId() ? -1 : (lhs.getId().longValue() == rhs.getId().longValue() ? 0 : 1);
}
});
return res;
}
};
}
use of net.osmand.data.QuadRect in project Osmand by osmandapp.
the class OsmandMapLayer method calculateRect.
public QuadRect calculateRect(float x, float y, float width, float height) {
QuadRect rf;
double left = x - width / 2.0d;
double top = y - height / 2.0d;
double right = left + width;
double bottom = top + height;
rf = new QuadRect(left, top, right, bottom);
return rf;
}
use of net.osmand.data.QuadRect in project Osmand by osmandapp.
the class OsmandMapLayer method intersects.
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;
}
Aggregations