use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.
the class MapContextMenuFragment method showOnMap.
private void showOnMap(LatLon latLon, boolean updateCoords, boolean needMove, boolean alreadyAdjusted) {
// AnimateDraggingMapThread thread = map.getAnimatedDraggingThread(); todo amimation
int fZoom = getZoom();
double flat = latLon.getLatitude();
double flon = latLon.getLongitude();
RotatedTileBox cp = getBox();
// cp.setCenterLocation(0.5f, map.getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f : 0.5f);
cp.setLatLonCenter(flat, flon);
cp.setZoom(fZoom);
flat = cp.getLatFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);
flon = cp.getLonFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);
if (updateCoords) {
mapCenter = new LatLon(flat, flon);
menu.setMapCenter(mapCenter);
origMarkerX = cp.getCenterPixelX();
origMarkerY = cp.getCenterPixelY();
}
if (!alreadyAdjusted) {
LatLon adjustedLatLon = getAdjustedMarkerLocation(getPosY(), new LatLon(flat, flon), true, fZoom);
flat = adjustedLatLon.getLatitude();
flon = adjustedLatLon.getLongitude();
}
if (needMove) {
// thread.startMoving(flat, flon, fZoom, true); todo animation
PointI targetI = Utilities.convertLatLonTo31(new net.osmand.core.jni.LatLon(flat, flon));
getMainActivity().setTarget(targetI);
getMainActivity().setZoom(fZoom);
}
}
use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.
the class MeasurementToolLayer method addCenterPoint.
public WptPt addCenterPoint() {
RotatedTileBox tb = view.getCurrentRotatedTileBox();
LatLon l = tb.getLatLonFromPixel(tb.getCenterPixelX(), tb.getCenterPixelY());
WptPt pt = new WptPt();
pt.lat = l.getLatitude();
pt.lon = l.getLongitude();
boolean allowed = editingCtx.getPointsCount() == 0 || !editingCtx.getPoints().get(editingCtx.getPointsCount() - 1).equals(pt);
if (allowed) {
editingCtx.addPoint(pt);
return pt;
}
return null;
}
use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.
the class MapContextMenuFragment method calculateCenterLatLon.
private LatLon calculateCenterLatLon(LatLon latLon, int zoom, boolean updateOrigXY) {
double flat = latLon.getLatitude();
double flon = latLon.getLongitude();
RotatedTileBox cp = map.getCurrentRotatedTileBox().copy();
cp.setCenterLocation(0.5f, map.getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f : 0.5f);
cp.setLatLonCenter(flat, flon);
cp.setZoom(zoom);
flat = cp.getLatFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);
flon = cp.getLonFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);
if (updateOrigXY) {
origMarkerX = cp.getCenterPixelX();
origMarkerY = cp.getCenterPixelY();
}
return new LatLon(flat, flon);
}
use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.
the class MapContextMenuFragment method setCustomMapRatio.
private void setCustomMapRatio() {
LatLon latLon = menu.getLatLon();
RotatedTileBox tb = map.getCurrentRotatedTileBox().copy();
float px = tb.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
float py = tb.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
float ratioX = px / tb.getPixWidth();
float ratioY = py / tb.getPixHeight();
map.setCustomMapRatio(ratioX, ratioY);
map.setLatLon(latLon.getLatitude(), latLon.getLongitude());
}
use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.
the class MapContextMenuFragment method getAdjustedMarkerLocation.
private LatLon getAdjustedMarkerLocation(int y, LatLon reqMarkerLocation, boolean center, int zoom) {
double markerLat = reqMarkerLocation.getLatitude();
double markerLon = reqMarkerLocation.getLongitude();
RotatedTileBox box = map.getCurrentRotatedTileBox().copy();
box.setCenterLocation(0.5f, map.getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f : 0.5f);
box.setZoom(zoom);
boolean hasMapCenter = mapCenter != null;
int markerMapCenterX = 0;
int markerMapCenterY = 0;
if (hasMapCenter) {
markerMapCenterX = (int) box.getPixXFromLatLon(mapCenter.getLatitude(), mapCenter.getLongitude());
markerMapCenterY = (int) box.getPixYFromLatLon(mapCenter.getLatitude(), mapCenter.getLongitude());
}
float cpyOrig = box.getCenterPixelPoint().y;
box.setCenterLocation(0.5f, 0.5f);
int markerX = (int) box.getPixXFromLatLon(markerLat, markerLon);
int markerY = (int) box.getPixYFromLatLon(markerLat, markerLon);
QuadPoint cp = box.getCenterPixelPoint();
float cpx = cp.x;
float cpy = cp.y;
float cpyDelta = menu.isLandscapeLayout() ? 0 : cpyOrig - cpy;
markerY += cpyDelta;
y += cpyDelta;
float origMarkerY = this.origMarkerY + cpyDelta;
LatLon latlon;
if (center || !hasMapCenter) {
latlon = reqMarkerLocation;
} else {
latlon = box.getLatLonFromPixel(markerMapCenterX, markerMapCenterY);
}
if (menu.isLandscapeLayout()) {
int x = menu.getLandscapeWidthPx();
if (markerX - markerPaddingXPx < x || markerX > origMarkerX) {
int dx = (x + markerPaddingXPx) - markerX;
int dy = 0;
if (center) {
dy = (int) cpy - markerY;
} else {
cpy = cpyOrig;
}
if (dx >= 0 || center) {
latlon = box.getLatLonFromPixel(cpx - dx, cpy - dy);
}
}
} else {
if (markerY + markerPaddingPx > y || markerY < origMarkerY) {
int dx = 0;
int dy = markerY - (y - markerPaddingPx);
if (markerY - dy <= origMarkerY) {
if (center) {
dx = markerX - (int) cpx;
}
latlon = box.getLatLonFromPixel(cpx + dx, cpy + dy);
}
}
}
return latlon;
}
Aggregations