use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.
the class OsmandMapTileView method fitRectToMap.
public void fitRectToMap(double left, double right, double top, double bottom, int tileBoxWidthPx, int tileBoxHeightPx, int marginTopPx) {
RotatedTileBox tb = currentViewport.copy();
double border = 0.8;
int dy = 0;
int tbw = (int) (tb.getPixWidth() * border);
int tbh = (int) (tb.getPixHeight() * border);
if (tileBoxWidthPx > 0) {
tbw = (int) (tileBoxWidthPx * border);
} else if (tileBoxHeightPx > 0) {
tbh = (int) (tileBoxHeightPx * border);
dy = (tb.getPixHeight() - tileBoxHeightPx) / 2 - marginTopPx;
}
tb.setPixelDimensions(tbw, tbh);
double clat = bottom / 2 + top / 2;
double clon = left / 2 + right / 2;
tb.setLatLonCenter(clat, clon);
while (tb.getZoom() < 17 && tb.containsLatLon(top, left) && tb.containsLatLon(bottom, right)) {
tb.setZoom(tb.getZoom() + 1);
}
while (tb.getZoom() >= 7 && (!tb.containsLatLon(top, left) || !tb.containsLatLon(bottom, right))) {
tb.setZoom(tb.getZoom() - 1);
}
if (dy != 0) {
clat = tb.getLatFromPixel(tb.getPixWidth() / 2, tb.getPixHeight() / 2 + dy);
clon = tb.getLonFromPixel(tb.getPixWidth() / 2, tb.getPixHeight() / 2);
}
animatedDraggingThread.startMoving(clat, clon, tb.getZoom(), true);
}
use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.
the class OsmandMapTileView method getTileBox.
public RotatedTileBox getTileBox(int tileBoxWidthPx, int tileBoxHeightPx, int marginTopPx) {
RotatedTileBox tb = currentViewport.copy();
double border = 0.8;
int dy = 0;
int tbw = (int) (tb.getPixWidth() * border);
int tbh = (int) (tb.getPixHeight() * border);
if (tileBoxWidthPx > 0) {
tbw = (int) (tileBoxWidthPx * border);
} else if (tileBoxHeightPx > 0) {
tbh = (int) (tileBoxHeightPx * border);
dy = (tb.getPixHeight() - tileBoxHeightPx) / 2 - marginTopPx;
}
tb.setPixelDimensions(tbw, tbh);
if (dy != 0) {
double clat = tb.getLatFromPixel(tb.getPixWidth() / 2, tb.getPixHeight() / 2 - dy);
double clon = tb.getLonFromPixel(tb.getPixWidth() / 2, tb.getPixHeight() / 2);
tb.setLatLonCenter(clat, clon);
}
return tb;
}
use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.
the class OsmandMapTileView method refreshMapInternal.
private void refreshMapInternal(DrawSettings drawSettings) {
if (view == null) {
return;
}
final float ratioy;
if (mapRatioY != 0) {
ratioy = mapRatioY;
} else if (mapPosition == OsmandSettings.BOTTOM_CONSTANT) {
ratioy = 0.85f;
} else if (mapPosition == OsmandSettings.MIDDLE_BOTTOM_CONSTANT) {
ratioy = 0.70f;
} else if (mapPosition == OsmandSettings.MIDDLE_TOP_CONSTANT) {
ratioy = 0.25f;
} else {
ratioy = 0.5f;
}
final float ratiox;
if (mapRatioX != 0) {
ratiox = mapRatioX;
} else if (mapPosition == OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT) {
ratiox = 0.7f;
} else {
ratiox = mapPositionX == 0 ? 0.5f : 0.75f;
}
final int cy = (int) (ratioy * view.getHeight());
final int cx = (int) (ratiox * view.getWidth());
if (currentViewport.getPixWidth() != view.getWidth() || currentViewport.getPixHeight() != view.getHeight() || currentViewport.getCenterPixelY() != cy || currentViewport.getCenterPixelX() != cx) {
currentViewport.setPixelDimensions(view.getWidth(), view.getHeight(), ratiox, ratioy);
refreshBufferImage(drawSettings);
}
if (view instanceof SurfaceView) {
SurfaceHolder holder = ((SurfaceView) view).getHolder();
long ms = SystemClock.elapsedRealtime();
synchronized (holder) {
Canvas canvas = holder.lockCanvas();
if (canvas != null) {
try {
// make copy to avoid concurrency
RotatedTileBox viewportToDraw = currentViewport.copy();
drawOverMap(canvas, viewportToDraw, drawSettings);
} finally {
holder.unlockCanvasAndPost(canvas);
}
}
if (MEASURE_FPS) {
main.calculateFPS(ms, SystemClock.elapsedRealtime());
}
}
} else {
view.invalidate();
}
}
use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.
the class OsmandMapTileView method restoreMapRatio.
public void restoreMapRatio() {
RotatedTileBox box = currentViewport.copy();
float rx = (float) box.getCenterPixelX() / box.getPixWidth();
float ry = (float) box.getCenterPixelY() / box.getPixHeight();
if (mapPosition == OsmandSettings.BOTTOM_CONSTANT) {
ry -= 0.35;
}
box.setCenterLocation(rx, ry);
LatLon screenCenter = box.getLatLonFromPixel(box.getPixWidth() / 2, box.getPixHeight() / 2);
mapRatioX = 0;
mapRatioY = 0;
setLatLon(screenCenter.getLatitude(), screenCenter.getLongitude());
}
use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.
the class RouteLayer method onPrepareBufferImage.
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if (helper.getFinalLocation() != null && helper.getRoute().isCalculated()) {
boolean updatePaints = attrs.updatePaints(view, settings, tileBox);
attrs.isPaint3 = false;
attrs.isPaint2 = false;
if (updatePaints) {
paintIconAction.setColorFilter(new PorterDuffColorFilter(attrs.paint3.getColor(), Mode.MULTIPLY));
paintIcon.setColorFilter(new PorterDuffColorFilter(attrs.paint2.getColor(), Mode.MULTIPLY));
}
if (coloredArrowUp == null) {
Bitmap originalArrowUp = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_route_direction_arrow, null);
coloredArrowUp = originalArrowUp;
// coloredArrowUp = Bitmap.createScaledBitmap(originalArrowUp, originalArrowUp.getWidth() * 3 / 4,
// originalArrowUp.getHeight() * 3 / 4, true);
}
int w = tileBox.getPixWidth();
int h = tileBox.getPixHeight();
Location lastProjection = helper.getLastProjection();
final RotatedTileBox cp;
if (lastProjection != null && tileBox.containsLatLon(lastProjection.getLatitude(), lastProjection.getLongitude())) {
cp = tileBox.copy();
cp.increasePixelDimensions(w / 2, h);
} else {
cp = tileBox;
}
final QuadRect latlonRect = cp.getLatLonBounds();
double topLatitude = latlonRect.top;
double leftLongitude = latlonRect.left;
double bottomLatitude = latlonRect.bottom;
double rightLongitude = latlonRect.right;
// double lat = 0;
// double lon = 0;
// this is buggy lat/lon should be 0 but in that case
// it needs to be fixed in case there is no route points in the view bbox
double lat = topLatitude - bottomLatitude + 0.1;
double lon = rightLongitude - leftLongitude + 0.1;
drawLocations(tileBox, canvas, topLatitude + lat, leftLongitude - lon, bottomLatitude - lat, rightLongitude + lon);
if (trackChartPoints != null) {
drawXAxisPoints(canvas, tileBox);
LatLon highlightedPoint = trackChartPoints.getHighlightedPoint();
if (highlightedPoint != null && highlightedPoint.getLatitude() >= latlonRect.bottom && highlightedPoint.getLatitude() <= latlonRect.top && highlightedPoint.getLongitude() >= latlonRect.left && highlightedPoint.getLongitude() <= latlonRect.right) {
float x = tileBox.getPixXFromLatLon(highlightedPoint.getLatitude(), highlightedPoint.getLongitude());
float y = tileBox.getPixYFromLatLon(highlightedPoint.getLatitude(), highlightedPoint.getLongitude());
canvas.drawBitmap(selectedPoint, x - selectedPoint.getWidth() / 2, y - selectedPoint.getHeight() / 2, paintIconSelected);
}
}
}
}
Aggregations