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());
}
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;
}
}
}
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);
}
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;
}
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;
}
Aggregations