use of net.osmand.data.QuadRect in project Osmand by osmandapp.
the class HillshadeLayer method createTileSource.
private SQLiteTileSource createTileSource(MapActivity activity) {
return new SQLiteTileSource(activity.getMyApplication(), null, new ArrayList<TileSourceTemplate>()) {
@Override
protected SQLiteConnection getDatabase() {
throw new UnsupportedOperationException();
}
public boolean isLocked() {
return false;
}
List<String> getTileSource(int x, int y, int zoom) {
ArrayList<String> ls = new ArrayList<String>();
int z = (zoom - ZOOM_BOUNDARY);
if (z > 0) {
indexedResources.queryInBox(new QuadRect(x >> z, y >> z, (x >> z), (y >> z)), ls);
} else {
indexedResources.queryInBox(new QuadRect(x << -z, y << -z, (x + 1) << -z, (y + 1) << -z), ls);
}
return ls;
}
@Override
public boolean exists(int x, int y, int zoom) {
List<String> ts = getTileSource(x, y, zoom);
for (String t : ts) {
SQLiteTileSource sqLiteTileSource = resources.get(t);
if (sqLiteTileSource != null && sqLiteTileSource.exists(x, y, zoom)) {
return true;
}
}
return false;
}
@Override
public Bitmap getImage(int x, int y, int zoom, long[] timeHolder) {
List<String> ts = getTileSource(x, y, zoom);
for (String t : ts) {
SQLiteTileSource sqLiteTileSource = resources.get(t);
if (sqLiteTileSource != null) {
Bitmap bmp = sqLiteTileSource.getImage(x, y, zoom, timeHolder);
if (bmp != null) {
return sqLiteTileSource.getImage(x, y, zoom, timeHolder);
}
}
}
return null;
}
@Override
public int getBitDensity() {
return 32;
}
@Override
public int getMinimumZoomSupported() {
return 5;
}
@Override
public int getMaximumZoomSupported() {
return 11;
}
@Override
public int getTileSize() {
return 256;
}
@Override
public boolean couldBeDownloadedFromInternet() {
return false;
}
@Override
public String getName() {
return "Hillshade";
}
@Override
public String getTileFormat() {
return "jpg";
}
};
}
use of net.osmand.data.QuadRect in project Osmand by osmandapp.
the class MapActivityActions method createReloadTitleDialog.
private Dialog createReloadTitleDialog(final Bundle args) {
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
builder.setMessage(R.string.context_menu_item_update_map_confirm);
builder.setNegativeButton(R.string.shared_string_cancel, null);
final OsmandMapTileView mapView = mapActivity.getMapView();
builder.setPositiveButton(R.string.context_menu_item_update_map, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int zoom = args.getInt(KEY_ZOOM);
BaseMapLayer mainLayer = mapView.getMainLayer();
if (!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()) {
Toast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
return;
}
final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap();
if (mapSource == null || !mapSource.couldBeDownloadedFromInternet()) {
Toast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
return;
}
final RotatedTileBox tb = mapView.getCurrentRotatedTileBox();
final QuadRect tilesRect = tb.getTileBounds();
int left = (int) Math.floor(tilesRect.left);
int top = (int) Math.floor(tilesRect.top);
int width = (int) (Math.ceil(tilesRect.right) - left);
int height = (int) (Math.ceil(tilesRect.bottom) - top);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
((OsmandApplication) mapActivity.getApplication()).getResourceManager().clearTileForMap(null, mapSource, i + left, j + top, zoom);
}
}
mapView.refreshMap();
}
});
return builder.create();
}
use of net.osmand.data.QuadRect in project Osmand by osmandapp.
the class TrackActivity method addPoint.
public void addPoint(PointDescription pointDescription) {
Intent currentIntent = getIntent();
if (currentIntent != null) {
currentIntent.putExtra(TrackActivity.OPEN_POINTS_TAB, true);
}
final OsmandSettings settings = app.getSettings();
GPXFile gpx = getGpx();
LatLon location = settings.getLastKnownMapLocation();
QuadRect rect = getRect();
NewGpxPoint newGpxPoint = new NewGpxPoint(gpx, pointDescription, rect);
if (gpx != null && location != null) {
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), pointDescription, false, newGpxPoint);
MapActivity.launchMapActivityMoveToTop(this);
}
}
use of net.osmand.data.QuadRect in project Osmand by osmandapp.
the class TrackActivity method getRect.
public QuadRect getRect() {
double left = 0, right = 0;
double top = 0, bottom = 0;
if (getGpx() != null) {
for (GPXUtilities.Track track : getGpx().tracks) {
for (GPXUtilities.TrkSegment segment : track.segments) {
for (WptPt p : segment.points) {
if (left == 0 && right == 0) {
left = p.getLongitude();
right = p.getLongitude();
top = p.getLatitude();
bottom = p.getLatitude();
} else {
left = Math.min(left, p.getLongitude());
right = Math.max(right, p.getLongitude());
top = Math.max(top, p.getLatitude());
bottom = Math.min(bottom, p.getLatitude());
}
}
}
}
for (WptPt p : getGpx().getPoints()) {
if (left == 0 && right == 0) {
left = p.getLongitude();
right = p.getLongitude();
top = p.getLatitude();
bottom = p.getLatitude();
} else {
left = Math.min(left, p.getLongitude());
right = Math.max(right, p.getLongitude());
top = Math.max(top, p.getLatitude());
bottom = Math.min(bottom, p.getLatitude());
}
}
for (GPXUtilities.Route route : getGpx().routes) {
for (WptPt p : route.points) {
if (left == 0 && right == 0) {
left = p.getLongitude();
right = p.getLongitude();
top = p.getLatitude();
bottom = p.getLatitude();
} else {
left = Math.min(left, p.getLongitude());
right = Math.max(right, p.getLongitude());
top = Math.max(top, p.getLatitude());
bottom = Math.min(bottom, p.getLatitude());
}
}
}
}
return new QuadRect(left, top, right, bottom);
}
use of net.osmand.data.QuadRect in project Osmand by osmandapp.
the class AudioNotesLayer method onPrepareBufferImage.
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if (tileBox.getZoom() >= startZoom) {
float iconSize = audio.getWidth() * 3 / 2.5f;
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
DataTileManager<Recording> recs = plugin.getRecordings();
final QuadRect latlon = tileBox.getLatLonBounds();
List<Recording> objects = recs.getObjects(latlon.top, latlon.left, latlon.bottom, latlon.right);
List<Recording> fullObjects = new ArrayList<>();
List<LatLon> fullObjectsLatLon = new ArrayList<>();
List<LatLon> smallObjectsLatLon = new ArrayList<>();
for (Recording o : objects) {
if (o != contextMenuLayer.getMoveableObject()) {
float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
smallObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude()));
} else {
fullObjects.add(o);
fullObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude()));
}
}
}
for (Recording o : fullObjects) {
float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
drawRecording(canvas, o, x, y);
}
this.fullObjectsLatLon = fullObjectsLatLon;
this.smallObjectsLatLon = smallObjectsLatLon;
}
}
Aggregations