Search in sources :

Example 36 with QuadRect

use of net.osmand.data.QuadRect 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 37 with QuadRect

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

the class MapillaryVectorLayer method draw.

protected void draw(Coordinate[] points, Canvas canvas, RotatedTileBox tileBox, int tileX, int tileY) {
    if (points.length > 1) {
        int dzoom = tileBox.getZoom() - TILE_ZOOM;
        int mult = (int) Math.pow(2.0, dzoom);
        QuadRect tileBounds = tileBox.getTileBounds();
        Coordinate lastPt = points[0];
        float x;
        float y;
        float lastx = 0;
        float lasty = 0;
        double px, py, tpx, tpy, tlx, tly;
        double lx = lastPt.x / EXTENT;
        double ly = lastPt.y / EXTENT;
        boolean reCalculateLastXY = true;
        int size = points.length;
        for (int i = 1; i < size; i++) {
            Coordinate pt = points[i];
            px = pt.x / EXTENT;
            py = pt.y / EXTENT;
            tpx = (tileX + px) * mult;
            tpy = (tileY + py) * mult;
            tlx = (tileX + lx) * mult;
            tly = (tileY + ly) * mult;
            if (tileBounds.contains(tpx, tpy, tpx, tpy) || tileBounds.contains(tlx, tly, tlx, tly)) {
                if (reCalculateLastXY) {
                    lastx = tileBox.getPixXFromTile(tileX + lx, tileY + ly, TILE_ZOOM);
                    lasty = tileBox.getPixYFromTile(tileX + lx, tileY + ly, TILE_ZOOM);
                    reCalculateLastXY = false;
                }
                x = tileBox.getPixXFromTile(tileX + px, tileY + py, TILE_ZOOM);
                y = tileBox.getPixYFromTile(tileX + px, tileY + py, TILE_ZOOM);
                canvas.drawLine(lastx, lasty, x, y, paintLine);
                lastx = x;
                lasty = y;
            } else {
                reCalculateLastXY = true;
            }
            lx = px;
            ly = py;
        }
    }
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) QuadRect(net.osmand.data.QuadRect) Point(com.vividsolutions.jts.geom.Point) Paint(android.graphics.Paint)

Example 38 with QuadRect

use of net.osmand.data.QuadRect 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 39 with QuadRect

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

the class FavouritePointMenuBuilder method findAmenity.

private Amenity findAmenity(String nameStringEn, double lat, double lon) {
    QuadRect rect = MapUtils.calculateLatLonBbox(lat, lon, 15);
    List<Amenity> amenities = app.getResourceManager().searchAmenities(new BinaryMapIndexReader.SearchPoiTypeFilter() {

        @Override
        public boolean accept(PoiCategory type, String subcategory) {
            return true;
        }

        @Override
        public boolean isEmpty() {
            return false;
        }
    }, rect.top, rect.left, rect.bottom, rect.right, -1, null);
    for (Amenity amenity : amenities) {
        String stringEn = amenity.toStringEn();
        if (stringEn.equals(nameStringEn)) {
            return amenity;
        }
    }
    return null;
}
Also used : Amenity(net.osmand.data.Amenity) PoiCategory(net.osmand.osm.PoiCategory) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) QuadRect(net.osmand.data.QuadRect)

Example 40 with QuadRect

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

the class TransportStopController method processTransportStop.

public List<TransportStopRoute> processTransportStop() {
    ArrayList<TransportStopRoute> routes = new ArrayList<>();
    List<TransportIndexRepository> reps = getMapActivity().getMyApplication().getResourceManager().searchTransportRepositories(transportStop.getLocation().getLatitude(), transportStop.getLocation().getLongitude());
    boolean useEnglishNames = getMapActivity().getMyApplication().getSettings().usingEnglishNames();
    for (TransportIndexRepository t : reps) {
        if (t.acceptTransportStop(transportStop)) {
            boolean empty = transportStop.getReferencesToRoutes() == null || transportStop.getReferencesToRoutes().length == 0;
            if (!empty) {
                addRoutes(routes, useEnglishNames, t, transportStop, transportStop, 0);
            }
            ArrayList<TransportStop> ls = new ArrayList<>();
            QuadRect ll = MapUtils.calculateLatLonBbox(transportStop.getLocation().getLatitude(), transportStop.getLocation().getLongitude(), SHOW_STOPS_RADIUS_METERS);
            t.searchTransportStops(ll.top, ll.left, ll.bottom, ll.right, -1, ls, null);
            for (TransportStop tstop : ls) {
                if (tstop.getId().longValue() != transportStop.getId().longValue() || empty) {
                    addRoutes(routes, useEnglishNames, t, tstop, transportStop, (int) MapUtils.getDistance(tstop.getLocation(), transportStop.getLocation()));
                }
            }
        }
    }
    Collections.sort(routes, new Comparator<TransportStopRoute>() {

        @Override
        public int compare(TransportStopRoute o1, TransportStopRoute o2) {
            if (o1.distance != o2.distance) {
                return Algorithms.compare(o1.distance, o2.distance);
            }
            int i1 = Algorithms.extractFirstIntegerNumber(o1.desc);
            int i2 = Algorithms.extractFirstIntegerNumber(o2.desc);
            if (i1 != i2) {
                return Algorithms.compare(i1, i2);
            }
            return o1.desc.compareTo(o2.desc);
        }
    });
    return routes;
}
Also used : TransportStopRoute(net.osmand.plus.transport.TransportStopRoute) ArrayList(java.util.ArrayList) TransportIndexRepository(net.osmand.plus.resources.TransportIndexRepository) TransportStop(net.osmand.data.TransportStop) 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