Search in sources :

Example 6 with QuadPointDouble

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

the class MapillaryImageDialog method fetchTiles.

public void fetchTiles() {
    RotatedTileBox tileBox = getMapActivity().getMapView().getCurrentRotatedTileBox().copy();
    if (fetchedTileLat == tileBox.getLatitude() && fetchedTileLon == tileBox.getLongitude()) {
        return;
    }
    ITileSource map = TileSourceManager.getMapillaryVectorSource();
    int nzoom = tileBox.getZoom();
    if (nzoom < map.getMinimumZoomSupported()) {
        return;
    }
    ResourceManager mgr = getMapActivity().getMyApplication().getResourceManager();
    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);
    int dzoom = nzoom - TILE_ZOOM;
    int div = (int) Math.pow(2.0, dzoom);
    Map<String, Pair<QuadPointDouble, GeometryTile>> tiles = new HashMap<>();
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            int tileX = (left + i) / div;
            int tileY = (top + j) / div;
            String tileId = mgr.calculateTileId(map, tileX, tileY, TILE_ZOOM);
            Pair<QuadPointDouble, GeometryTile> p = tiles.get(tileId);
            if (p == null) {
                GeometryTile tile = null;
                // asking tile image async
                boolean imgExist = mgr.tileExistOnFileSystem(tileId, map, tileX, tileY, TILE_ZOOM);
                if (imgExist) {
                    if (sync) {
                        tile = mgr.getGeometryTilesCache().getTileForMapSync(tileId, map, tileX, tileY, TILE_ZOOM, false);
                        sync = false;
                    } else {
                        tile = mgr.getGeometryTilesCache().getTileForMapAsync(tileId, map, tileX, tileY, TILE_ZOOM, false);
                    }
                }
                if (tile != null) {
                    tiles.put(tileId, new Pair<>(new QuadPointDouble(tileX, tileY), tile));
                }
            }
        }
    }
    fetchedTileLat = tileBox.getLatitude();
    fetchedTileLon = tileBox.getLongitude();
    this.tiles = new ArrayList<>(tiles.values());
}
Also used : RotatedTileBox(net.osmand.data.RotatedTileBox) HashMap(java.util.HashMap) ResourceManager(net.osmand.plus.resources.ResourceManager) QuadRect(net.osmand.data.QuadRect) Point(com.vividsolutions.jts.geom.Point) SuppressLint(android.annotation.SuppressLint) ITileSource(net.osmand.map.ITileSource) GeometryTile(net.osmand.data.GeometryTile) Pair(android.support.v4.util.Pair) QuadPointDouble(net.osmand.data.QuadPointDouble)

Example 7 with QuadPointDouble

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

the class MapillaryVectorLayer method drawTileMap.

@Override
public void drawTileMap(Canvas canvas, RotatedTileBox tileBox) {
    ITileSource map = this.map;
    if (map == null) {
        return;
    }
    int nzoom = tileBox.getZoom();
    if (nzoom < map.getMinimumZoomSupported()) {
        return;
    }
    ResourceManager mgr = resourceManager;
    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);
    int dzoom = nzoom - TILE_ZOOM;
    int div = (int) Math.pow(2.0, dzoom);
    boolean useInternet = (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null || OsmandPlugin.getEnabledPlugin(MapillaryPlugin.class) != null) && settings.USE_INTERNET_TO_DOWNLOAD_TILES.get() && settings.isInternetConnectionAvailable() && map.couldBeDownloadedFromInternet();
    Map<String, GeometryTile> tiles = new HashMap<>();
    Map<QuadPointDouble, Map> visiblePoints = new HashMap<>();
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            int tileX = (left + i) / div;
            int tileY = (top + j) / div;
            String tileId = mgr.calculateTileId(map, tileX, tileY, TILE_ZOOM);
            GeometryTile tile = tiles.get(tileId);
            if (tile == null) {
                // asking tile image async
                boolean imgExist = mgr.tileExistOnFileSystem(tileId, map, tileX, tileY, TILE_ZOOM);
                if (imgExist || useInternet) {
                    tile = mgr.getGeometryTilesCache().getTileForMapAsync(tileId, map, tileX, tileY, TILE_ZOOM, useInternet);
                }
                if (tile != null) {
                    tiles.put(tileId, tile);
                    if (tile.getData() != null) {
                        drawLines(canvas, tileBox, tileX, tileY, tile);
                        if (nzoom > 15) {
                            drawPoints(canvas, tileBox, tileX, tileY, tile, visiblePoints);
                        }
                    }
                }
            }
        }
    }
    this.visiblePoints = visiblePoints;
    drawSelectedPoint(canvas, tileBox);
}
Also used : HashMap(java.util.HashMap) ResourceManager(net.osmand.plus.resources.ResourceManager) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) QuadRect(net.osmand.data.QuadRect) Point(com.vividsolutions.jts.geom.Point) Paint(android.graphics.Paint) ITileSource(net.osmand.map.ITileSource) GeometryTile(net.osmand.data.GeometryTile) HashMap(java.util.HashMap) Map(java.util.Map) QuadPointDouble(net.osmand.data.QuadPointDouble)

Example 8 with QuadPointDouble

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

the class MapVectorLayer method drawRenderedMap.

private boolean drawRenderedMap(Canvas canvas, Bitmap bmp, RotatedTileBox bmpLoc, RotatedTileBox currentViewport) {
    boolean shown = false;
    if (bmp != null && bmpLoc != null) {
        float rot = -bmpLoc.getRotate();
        canvas.rotate(rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY());
        final RotatedTileBox calc = currentViewport.copy();
        calc.setRotate(bmpLoc.getRotate());
        QuadPointDouble lt = bmpLoc.getLeftTopTile(bmpLoc.getZoom());
        QuadPointDouble rb = bmpLoc.getRightBottomTile(bmpLoc.getZoom());
        final float x1 = calc.getPixXFromTile(lt.x, lt.y, bmpLoc.getZoom());
        final float x2 = calc.getPixXFromTile(rb.x, rb.y, bmpLoc.getZoom());
        final float y1 = calc.getPixYFromTile(lt.x, lt.y, bmpLoc.getZoom());
        final float y2 = calc.getPixYFromTile(rb.x, rb.y, bmpLoc.getZoom());
        // LatLon lt = bmpLoc.getLeftTopLatLon();
        // LatLon rb = bmpLoc.getRightBottomLatLon();
        // final float x1 = calc.getPixXFromLatLon(lt.getLatitude(), lt.getLongitude());
        // final float x2 = calc.getPixXFromLatLon(rb.getLatitude(), rb.getLongitude());
        // final float y1 = calc.getPixYFromLatLon(lt.getLatitude(), lt.getLongitude());
        // final float y2 = calc.getPixYFromLatLon(rb.getLatitude(), rb.getLongitude());
        destImage.set(x1, y1, x2, y2);
        if (!bmp.isRecycled()) {
            canvas.drawBitmap(bmp, null, destImage, paintImg);
            shown = true;
        }
        canvas.rotate(-rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY());
    }
    return shown;
}
Also used : RotatedTileBox(net.osmand.data.RotatedTileBox) QuadPointDouble(net.osmand.data.QuadPointDouble)

Example 9 with QuadPointDouble

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

the class OsmandMapTileView method drawBasemap.

private void drawBasemap(Canvas canvas) {
    if (bufferImgLoc != null) {
        float rot = -bufferImgLoc.getRotate();
        canvas.rotate(rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY());
        final RotatedTileBox calc = currentViewport.copy();
        calc.setRotate(bufferImgLoc.getRotate());
        int cz = getZoom();
        QuadPointDouble lt = bufferImgLoc.getLeftTopTile(cz);
        QuadPointDouble rb = bufferImgLoc.getRightBottomTile(cz);
        final float x1 = calc.getPixXFromTile(lt.x, lt.y, cz);
        final float x2 = calc.getPixXFromTile(rb.x, rb.y, cz);
        final float y1 = calc.getPixYFromTile(lt.x, lt.y, cz);
        final float y2 = calc.getPixYFromTile(rb.x, rb.y, cz);
        // final float y2 = calc.getPixYFromLatLon(rb.getLatitude(), rb.getLongitude());
        if (!bufferBitmap.isRecycled()) {
            RectF rct = new RectF(x1, y1, x2, y2);
            canvas.drawBitmap(bufferBitmap, null, rct, paintImg);
        }
        canvas.rotate(-rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY());
    }
}
Also used : RectF(android.graphics.RectF) RotatedTileBox(net.osmand.data.RotatedTileBox) QuadPoint(net.osmand.data.QuadPoint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) QuadPointDouble(net.osmand.data.QuadPointDouble)

Aggregations

QuadPointDouble (net.osmand.data.QuadPointDouble)9 Point (com.vividsolutions.jts.geom.Point)6 HashMap (java.util.HashMap)6 Paint (android.graphics.Paint)4 GeometryTile (net.osmand.data.GeometryTile)4 QuadRect (net.osmand.data.QuadRect)4 RotatedTileBox (net.osmand.data.RotatedTileBox)4 Geometry (com.vividsolutions.jts.geom.Geometry)3 SuppressLint (android.annotation.SuppressLint)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ITileSource (net.osmand.map.ITileSource)2 ResourceManager (net.osmand.plus.resources.ResourceManager)2 Bitmap (android.graphics.Bitmap)1 Config (android.graphics.Bitmap.Config)1 RectF (android.graphics.RectF)1 Pair (android.support.v4.util.Pair)1 LineString (com.vividsolutions.jts.geom.LineString)1 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1