Search in sources :

Example 11 with QuadRect

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);
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection) QuadRect(net.osmand.data.QuadRect) SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor)

Example 12 with QuadRect

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);
            }
        }
    }
}
Also used : TransportStopType(net.osmand.plus.transport.TransportStopType) Node(net.osmand.osm.edit.Node) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) QuadRect(net.osmand.data.QuadRect) Paint(android.graphics.Paint) Way(net.osmand.osm.edit.Way) TIntArrayList(gnu.trove.list.array.TIntArrayList) Bitmap(android.graphics.Bitmap) TransportStop(net.osmand.data.TransportStop)

Example 13 with QuadRect

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;
        }
    };
}
Also used : Path(android.graphics.Path) RotatedTileBox(net.osmand.data.RotatedTileBox) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) ResultMatcher(net.osmand.ResultMatcher) DisplayMetrics(android.util.DisplayMetrics) QuadRect(net.osmand.data.QuadRect) WindowManager(android.view.WindowManager) Comparator(java.util.Comparator) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TransportStop(net.osmand.data.TransportStop)

Example 14 with QuadRect

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;
}
Also used : QuadRect(net.osmand.data.QuadRect)

Example 15 with QuadRect

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;
}
Also used : TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) QuadRect(net.osmand.data.QuadRect)

Aggregations

QuadRect (net.osmand.data.QuadRect)60 Paint (android.graphics.Paint)19 ArrayList (java.util.ArrayList)19 LatLon (net.osmand.data.LatLon)13 Bitmap (android.graphics.Bitmap)8 RotatedTileBox (net.osmand.data.RotatedTileBox)8 WptPt (net.osmand.plus.GPXUtilities.WptPt)8 TIntArrayList (gnu.trove.list.array.TIntArrayList)7 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)6 Amenity (net.osmand.data.Amenity)5 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)4 Point (com.vividsolutions.jts.geom.Point)4 List (java.util.List)4 QuadPointDouble (net.osmand.data.QuadPointDouble)4 TransportStop (net.osmand.data.TransportStop)4 PoiCategory (net.osmand.osm.PoiCategory)4 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)4 Rect (android.graphics.Rect)3 RectF (android.graphics.RectF)3 File (java.io.File)3