Search in sources :

Example 1 with GeometryTile

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

the class GeometryTilesCache method getTileObject.

@Override
protected GeometryTile getTileObject(TileLoadDownloadRequest req) {
    GeometryTile tile = null;
    File en = new File(req.dirWithTiles, req.tileId);
    if (en.exists()) {
        try {
            tile = BinaryVectorTileReader.readTile(en);
            downloadIfExpired(req, en.lastModified());
        } catch (IOException e) {
            log.error("Cannot read tile", e);
        } catch (OutOfMemoryError e) {
            log.error("Out of memory error", e);
            clearTiles();
        }
    }
    return tile;
}
Also used : IOException(java.io.IOException) GeometryTile(net.osmand.data.GeometryTile) File(java.io.File)

Example 2 with GeometryTile

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

the class MapillaryImageDialog method acquireSequenceImages.

private void acquireSequenceImages() {
    fetchTiles();
    List<MapillaryImage> sequenceImages = new ArrayList<>();
    if (!Algorithms.isEmpty(sKey)) {
        double px, py;
        for (Pair<QuadPointDouble, GeometryTile> pt : tiles) {
            QuadPointDouble point = pt.first;
            GeometryTile tile = pt.second;
            for (Geometry g : tile.getData()) {
                if (g instanceof Point && !g.isEmpty() && g.getUserData() != null && g.getUserData() instanceof HashMap) {
                    HashMap userData = (HashMap) g.getUserData();
                    String sKey = (String) userData.get("skey");
                    if (this.sKey.equals(sKey)) {
                        Point p = (Point) g;
                        px = p.getCoordinate().x / EXTENT;
                        py = p.getCoordinate().y / EXTENT;
                        MapillaryImage image = new MapillaryImage(MapUtils.getLatitudeFromTile(TILE_ZOOM, point.y + py), MapUtils.getLongitudeFromTile(TILE_ZOOM, point.x + px));
                        if (image.setData(userData)) {
                            sequenceImages.add(image);
                        }
                    }
                }
            }
        }
    }
    Collections.sort(sequenceImages, new Comparator<MapillaryImage>() {

        @Override
        public int compare(MapillaryImage img1, MapillaryImage img2) {
            return img1.getCapturedAt() < img2.getCapturedAt() ? -1 : (img1.getCapturedAt() == img2.getCapturedAt() ? 0 : 1);
        }
    });
    this.sequenceImages = sequenceImages;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Point(com.vividsolutions.jts.geom.Point) Geometry(com.vividsolutions.jts.geom.Geometry) GeometryTile(net.osmand.data.GeometryTile) QuadPointDouble(net.osmand.data.QuadPointDouble)

Example 3 with GeometryTile

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

the class MapillaryImageDialog method acquireSequenceKey.

private void acquireSequenceKey() {
    fetchTiles();
    for (Pair<QuadPointDouble, GeometryTile> pt : tiles) {
        GeometryTile tile = pt.second;
        for (Geometry g : tile.getData()) {
            if (g instanceof Point && !g.isEmpty() && g.getUserData() != null && g.getUserData() instanceof HashMap) {
                HashMap userData = (HashMap) g.getUserData();
                String key = (String) userData.get("key");
                if (this.key.equals(key)) {
                    sKey = (String) userData.get("skey");
                    return;
                }
            }
        }
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) HashMap(java.util.HashMap) Point(com.vividsolutions.jts.geom.Point) GeometryTile(net.osmand.data.GeometryTile) QuadPointDouble(net.osmand.data.QuadPointDouble)

Example 4 with GeometryTile

use of net.osmand.data.GeometryTile 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 5 with GeometryTile

use of net.osmand.data.GeometryTile 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)

Aggregations

GeometryTile (net.osmand.data.GeometryTile)5 Point (com.vividsolutions.jts.geom.Point)4 HashMap (java.util.HashMap)4 QuadPointDouble (net.osmand.data.QuadPointDouble)4 Geometry (com.vividsolutions.jts.geom.Geometry)2 QuadRect (net.osmand.data.QuadRect)2 ITileSource (net.osmand.map.ITileSource)2 ResourceManager (net.osmand.plus.resources.ResourceManager)2 SuppressLint (android.annotation.SuppressLint)1 Paint (android.graphics.Paint)1 Pair (android.support.v4.util.Pair)1 LineString (com.vividsolutions.jts.geom.LineString)1 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 RotatedTileBox (net.osmand.data.RotatedTileBox)1