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