Search in sources :

Example 51 with QuadRect

use of net.osmand.data.QuadRect in project Osmand by osmandapp.

the class FavouritesLayer method onPrepareBufferImage.

@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
    cache.clear();
    if (this.settings.SHOW_FAVORITES.get()) {
        if (tileBox.getZoom() >= startZoom) {
            float iconSize = FavoriteImageDrawable.getOrCreate(view.getContext(), 0, true).getIntrinsicWidth() * 3 / 2.5f;
            QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
            // request to load
            final QuadRect latLonBounds = tileBox.getLatLonBounds();
            List<FavouritePoint> fullObjects = new ArrayList<>();
            List<LatLon> fullObjectsLatLon = new ArrayList<>();
            List<LatLon> smallObjectsLatLon = new ArrayList<>();
            for (FavouritePoint o : getPoints()) {
                if (!o.isVisible()) {
                    continue;
                }
                float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
                float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
                if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
                    @ColorInt int col = o.getColor() == 0 || o.getColor() == Color.BLACK ? defaultColor : o.getColor();
                    paintIcon.setColorFilter(new PorterDuffColorFilter(col, PorterDuff.Mode.MULTIPLY));
                    canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
                    smallObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude()));
                } else {
                    fullObjects.add(o);
                    fullObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude()));
                }
            }
            for (FavouritePoint o : fullObjects) {
                if (o != contextMenuLayer.getMoveableObject()) {
                    boolean syncedPoint = mapMarkersHelper.isSynced(o);
                    drawPoint(canvas, tileBox, latLonBounds, o, syncedPoint);
                }
            }
            this.fullObjectsLatLon = fullObjectsLatLon;
            this.smallObjectsLatLon = smallObjectsLatLon;
        }
    }
    if (textLayer.isVisible()) {
        textLayer.putData(this, cache);
    }
}
Also used : LatLon(net.osmand.data.LatLon) ColorInt(android.support.annotation.ColorInt) FavouritePoint(net.osmand.data.FavouritePoint) ArrayList(java.util.ArrayList) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) QuadRect(net.osmand.data.QuadRect) FavouritePoint(net.osmand.data.FavouritePoint) Paint(android.graphics.Paint)

Example 52 with QuadRect

use of net.osmand.data.QuadRect in project Osmand by osmandapp.

the class GPXLayer method drawSplitItems.

private void drawSplitItems(Canvas canvas, RotatedTileBox tileBox, List<GpxDisplayItem> items, DrawSettings settings) {
    final QuadRect latLonBounds = tileBox.getLatLonBounds();
    int r = (int) (12 * tileBox.getDensity());
    paintTextIcon.setTextSize(r);
    int dr = r * 3 / 2;
    int px = -1;
    int py = -1;
    for (int k = 0; k < items.size(); k++) {
        GpxDisplayItem i = items.get(k);
        WptPt o = i.locationEnd;
        if (o != null && o.lat >= latLonBounds.bottom && o.lat <= latLonBounds.top && o.lon >= latLonBounds.left && o.lon <= latLonBounds.right) {
            int x = (int) tileBox.getPixXFromLatLon(o.lat, o.lon);
            int y = (int) tileBox.getPixYFromLatLon(o.lat, o.lon);
            if (px != -1 || py != -1) {
                if (Math.abs(x - px) <= dr && Math.abs(y - py) <= dr) {
                    continue;
                }
            }
            px = x;
            py = y;
            String nm = i.splitName;
            if (nm != null) {
                int ind = nm.indexOf(' ');
                if (ind > 0) {
                    nm = nm.substring(0, ind);
                }
                Rect bounds = new Rect();
                paintTextIcon.getTextBounds(nm, 0, nm.length(), bounds);
                int nmWidth = bounds.width();
                int nmHeight = bounds.height();
                RectF rect = new RectF(x - nmWidth / 2 - 2 * (float) Math.ceil(tileBox.getDensity()), y + nmHeight / 2 + 3 * (float) Math.ceil(tileBox.getDensity()), x + nmWidth / 2 + 3 * (float) Math.ceil(tileBox.getDensity()), y - nmHeight / 2 - 2 * (float) Math.ceil(tileBox.getDensity()));
                canvas.drawRoundRect(rect, 0, 0, paintInnerRect);
                canvas.drawRoundRect(rect, 0, 0, paintOuterRect);
                // canvas.drawRect(rect, paintInnerRect);
                // canvas.drawRect(rect, paintOuterRect);
                canvas.drawText(nm, x, y + nmHeight / 2, paintTextIcon);
            }
        }
    }
}
Also used : RectF(android.graphics.RectF) WptPt(net.osmand.plus.GPXUtilities.WptPt) Rect(android.graphics.Rect) QuadRect(net.osmand.data.QuadRect) GpxDisplayItem(net.osmand.plus.GpxSelectionHelper.GpxDisplayItem) QuadRect(net.osmand.data.QuadRect) Paint(android.graphics.Paint)

Example 53 with QuadRect

use of net.osmand.data.QuadRect in project Osmand by osmandapp.

the class GPXLayer method drawSelectedFilesPoints.

private void drawSelectedFilesPoints(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles) {
    if (tileBox.getZoom() >= startZoom) {
        float iconSize = FavoriteImageDrawable.getOrCreate(view.getContext(), 0, true).getIntrinsicWidth() * 3 / 2.5f;
        QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
        List<LatLon> fullObjectsLatLon = new ArrayList<>();
        List<LatLon> smallObjectsLatLon = new ArrayList<>();
        // request to load
        final QuadRect latLonBounds = tileBox.getLatLonBounds();
        for (SelectedGpxFile g : selectedGPXFiles) {
            List<WptPt> pts = getListStarPoints(g);
            List<WptPt> fullObjects = new ArrayList<>();
            @ColorInt int fileColor = getFileColor(g);
            boolean synced = isSynced(g);
            for (WptPt o : pts) {
                if (o.lat >= latLonBounds.bottom && o.lat <= latLonBounds.top && o.lon >= latLonBounds.left && o.lon <= latLonBounds.right && o != contextMenuLayer.getMoveableObject()) {
                    if (synced) {
                        if (mapMarkersHelper.getMapMarker(o) == null) {
                            continue;
                        }
                    }
                    cache.add(o);
                    float x = tileBox.getPixXFromLatLon(o.lat, o.lon);
                    float y = tileBox.getPixYFromLatLon(o.lat, o.lon);
                    if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
                        @ColorInt int pointColor = getPointColor(o, fileColor);
                        paintIcon.setColorFilter(new PorterDuffColorFilter(pointColor, PorterDuff.Mode.MULTIPLY));
                        canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
                        smallObjectsLatLon.add(new LatLon(o.lat, o.lon));
                    } else {
                        fullObjects.add(o);
                        fullObjectsLatLon.add(new LatLon(o.lat, o.lon));
                    }
                }
                pointFileMap.put(o, g);
            }
            for (WptPt o : fullObjects) {
                float x = tileBox.getPixXFromLatLon(o.lat, o.lon);
                float y = tileBox.getPixYFromLatLon(o.lat, o.lon);
                drawBigPoint(canvas, o, fileColor, x, y, synced);
            }
        }
        if (trackChartPoints != null) {
            LatLon highlightedPoint = trackChartPoints.getHighlightedPoint();
            if (highlightedPoint != null) {
                if (highlightedPoint.getLatitude() >= latLonBounds.bottom && highlightedPoint.getLatitude() <= latLonBounds.top && highlightedPoint.getLongitude() >= latLonBounds.left && highlightedPoint.getLongitude() <= latLonBounds.right) {
                    float x = tileBox.getPixXFromLatLon(highlightedPoint.getLatitude(), highlightedPoint.getLongitude());
                    float y = tileBox.getPixYFromLatLon(highlightedPoint.getLatitude(), highlightedPoint.getLongitude());
                    paintIcon.setColorFilter(null);
                    canvas.drawBitmap(selectedPoint, x - selectedPoint.getWidth() / 2, y - selectedPoint.getHeight() / 2, paintIcon);
                }
            }
        }
        this.fullObjectsLatLon = fullObjectsLatLon;
        this.smallObjectsLatLon = smallObjectsLatLon;
    }
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) ArrayList(java.util.ArrayList) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) QuadRect(net.osmand.data.QuadRect) Paint(android.graphics.Paint) LatLon(net.osmand.data.LatLon) ColorInt(android.support.annotation.ColorInt) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile)

Example 54 with QuadRect

use of net.osmand.data.QuadRect in project Osmand by osmandapp.

the class GPXLayer method drawXAxisPoints.

private void drawXAxisPoints(Canvas canvas, RotatedTileBox tileBox) {
    int color = trackChartPoints.getSegmentColor();
    if (color == 0) {
        GpxDataItem gpxDataItem = null;
        if (!trackChartPoints.getGpx().showCurrentTrack) {
            gpxDataItem = view.getApplication().getGpxDatabase().getItem(new File(trackChartPoints.getGpx().path));
        }
        color = gpxDataItem != null ? gpxDataItem.getColor() : 0;
        if (trackChartPoints.getGpx().showCurrentTrack) {
            color = currentTrackColor;
        }
        if (color == 0) {
            color = cachedColor;
        }
        trackChartPoints.setSegmentColor(color);
    }
    paintGridCircle.setColor(color);
    paintGridCircle.setAlpha(255);
    QuadRect latLonBounds = tileBox.getLatLonBounds();
    float r = 3 * tileBox.getDensity();
    List<WptPt> xAxisPoints = trackChartPoints.getXAxisPoints();
    if (xAxisPoints != null) {
        for (int i = 0; i < xAxisPoints.size(); i++) {
            WptPt axisPoint = xAxisPoints.get(i);
            if (axisPoint != null) {
                if (axisPoint.getLatitude() >= latLonBounds.bottom && axisPoint.getLatitude() <= latLonBounds.top && axisPoint.getLongitude() >= latLonBounds.left && axisPoint.getLongitude() <= latLonBounds.right) {
                    float x = tileBox.getPixXFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude());
                    float y = tileBox.getPixYFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude());
                    canvas.drawCircle(x, y, r + 2 * (float) Math.ceil(tileBox.getDensity()), paintGridOuterCircle);
                    canvas.drawCircle(x, y, r + (float) Math.ceil(tileBox.getDensity()), paintGridCircle);
                }
            }
        }
    }
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) GpxDataItem(net.osmand.plus.GPXDatabase.GpxDataItem) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) QuadRect(net.osmand.data.QuadRect) Paint(android.graphics.Paint)

Example 55 with QuadRect

use of net.osmand.data.QuadRect in project Osmand by osmandapp.

the class MapTileLayer method drawTileMap.

public void drawTileMap(Canvas canvas, RotatedTileBox tileBox) {
    ITileSource map = this.map;
    if (map == null) {
        return;
    }
    ResourceManager mgr = resourceManager;
    int nzoom = tileBox.getZoom();
    final QuadRect tilesRect = tileBox.getTileBounds();
    // recalculate for ellipsoid coordinates
    float ellipticTileCorrection = 0;
    if (map.isEllipticYTile()) {
        ellipticTileCorrection = (float) (MapUtils.getTileEllipsoidNumberY(nzoom, tileBox.getLatitude()) - tileBox.getCenterTileY());
    }
    int left = (int) Math.floor(tilesRect.left);
    int top = (int) Math.floor(tilesRect.top + ellipticTileCorrection);
    int width = (int) Math.ceil(tilesRect.right - left);
    int height = (int) Math.ceil(tilesRect.bottom + ellipticTileCorrection - top);
    boolean useInternet = (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null || OsmandPlugin.getEnabledPlugin(MapillaryPlugin.class) != null) && settings.USE_INTERNET_TO_DOWNLOAD_TILES.get() && settings.isInternetConnectionAvailable() && map.couldBeDownloadedFromInternet();
    int maxLevel = map.getMaximumZoomSupported();
    int tileSize = map.getTileSize();
    boolean oneTileShown = false;
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            int leftPlusI = left + i;
            int topPlusJ = top + j;
            int x1 = tileBox.getPixXFromTileXNoRot(leftPlusI);
            int x2 = tileBox.getPixXFromTileXNoRot(leftPlusI + 1);
            int y1 = tileBox.getPixYFromTileYNoRot(topPlusJ - ellipticTileCorrection);
            int y2 = tileBox.getPixYFromTileYNoRot(topPlusJ + 1 - ellipticTileCorrection);
            bitmapToDraw.set(x1, y1, x2, y2);
            final int tileX = leftPlusI;
            final int tileY = topPlusJ;
            Bitmap bmp = null;
            String ordImgTile = mgr.calculateTileId(map, tileX, tileY, nzoom);
            // asking tile image async
            boolean imgExist = mgr.tileExistOnFileSystem(ordImgTile, map, tileX, tileY, nzoom);
            boolean originalWillBeLoaded = useInternet && nzoom <= maxLevel;
            if (imgExist || originalWillBeLoaded) {
                bmp = mgr.getBitmapTilesCache().getTileForMapAsync(ordImgTile, map, tileX, tileY, nzoom, useInternet);
            }
            if (bmp == null) {
                int div = 1;
                boolean readFromCache = originalWillBeLoaded || imgExist;
                boolean loadIfExists = !readFromCache;
                // asking if there is small version of the map (in cache)
                int allowedScale = Math.min(OVERZOOM_IN + Math.max(0, nzoom - map.getMaximumZoomSupported()), 8);
                int kzoom = 1;
                for (; kzoom <= allowedScale; kzoom++) {
                    div *= 2;
                    String imgTileId = mgr.calculateTileId(map, tileX / div, tileY / div, nzoom - kzoom);
                    if (readFromCache) {
                        bmp = mgr.getBitmapTilesCache().get(imgTileId);
                        if (bmp != null) {
                            break;
                        }
                    } else if (loadIfExists) {
                        if (mgr.tileExistOnFileSystem(imgTileId, map, tileX / div, tileY / div, nzoom - kzoom) || (useInternet && nzoom - kzoom <= maxLevel)) {
                            bmp = mgr.getBitmapTilesCache().getTileForMapAsync(imgTileId, map, tileX / div, tileY / div, nzoom - kzoom, useInternet);
                            break;
                        }
                    }
                }
                if (bmp != null) {
                    int xZoom = (tileX % div) * tileSize / div;
                    int yZoom = (tileY % div) * tileSize / div;
                    // nice scale
                    boolean useSampling = kzoom > 3;
                    bitmapToZoom.set(Math.max(xZoom, 0), Math.max(yZoom, 0), Math.min(xZoom + tileSize / div, tileSize), Math.min(yZoom + tileSize / div, tileSize));
                    if (!useSampling) {
                        canvas.drawBitmap(bmp, bitmapToZoom, bitmapToDraw, paintBitmap);
                    } else {
                        int margin = 1;
                        int scaledSize = tileSize / div;
                        float innerMargin = 0.5f;
                        RectF src = new RectF(0, 0, scaledSize, scaledSize);
                        if (bitmapToZoom.left >= margin) {
                            bitmapToZoom.left -= margin;
                            src.left = innerMargin;
                            src.right += margin;
                        }
                        if (bitmapToZoom.top >= margin) {
                            bitmapToZoom.top -= margin;
                            src.top = innerMargin;
                            src.bottom += margin;
                        }
                        if (bitmapToZoom.right + margin <= tileSize) {
                            bitmapToZoom.right += margin;
                            src.right += margin - innerMargin;
                        }
                        if (bitmapToZoom.bottom + margin <= tileSize) {
                            bitmapToZoom.bottom += margin;
                            src.bottom += margin - innerMargin;
                        }
                        Matrix m = new Matrix();
                        RectF dest = new RectF(0, 0, tileSize, tileSize);
                        m.setRectToRect(src, dest, Matrix.ScaleToFit.FILL);
                        Bitmap sampled = Bitmap.createBitmap(bmp, bitmapToZoom.left, bitmapToZoom.top, bitmapToZoom.width(), bitmapToZoom.height(), m, true);
                        bitmapToZoom.set(0, 0, tileSize, tileSize);
                        // very expensive that's why put in the cache
                        mgr.getBitmapTilesCache().put(ordImgTile, sampled);
                        canvas.drawBitmap(sampled, bitmapToZoom, bitmapToDraw, paintBitmap);
                    }
                }
            } else {
                bitmapToZoom.set(0, 0, tileSize, tileSize);
                canvas.drawBitmap(bmp, bitmapToZoom, bitmapToDraw, paintBitmap);
            }
            if (bmp != null) {
                oneTileShown = true;
            }
        }
    }
    if (mainMap && !oneTileShown && !useInternet && warningToSwitchMapShown < 3) {
        if (resourceManager.getRenderer().containsLatLonMapData(view.getLatitude(), view.getLongitude(), nzoom)) {
            Toast.makeText(view.getContext(), R.string.switch_to_vector_map_to_see, Toast.LENGTH_LONG).show();
            warningToSwitchMapShown++;
        }
    }
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ITileSource(net.osmand.map.ITileSource) ResourceManager(net.osmand.plus.resources.ResourceManager) QuadRect(net.osmand.data.QuadRect) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

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