Modify layers

This commit is contained in:
vshcherb 2013-09-28 01:00:10 +02:00
parent 7f8a088a4a
commit c90d31486f
6 changed files with 77 additions and 36 deletions

View file

@ -415,7 +415,7 @@ public class RotatedTileBox {
final double lat1 = getLatFromPixel(pixX, pixY);
final double lon1 = getLonFromPixel(pixX, pixY);
final double lat2 = getLatFromPixel(pixX2, pixY2);
final double lon2 = getLatFromPixel(pixX2, pixY2);
final double lon2 = getLonFromPixel(pixX2, pixY2);
return MapUtils.getDistance(lat1,lon1, lat2, lon2);
}

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="map_magnifier">Map magnifier</string>
<string name="base_world_map">base world map</string>
<string name="tip_map_styles">Map Styles</string>
<string name="tip_map_styles_t">OsmAnd supports displaying the offline vector maps in different map styles to suit your to needs:

View file

@ -153,7 +153,7 @@ public class AnimateDraggingMapThread {
public void run() {
setTargetValues(endZoom, endZoomScale, finalLat, finalLon);
if(moveZoom != startZoom){
animatingZoomInThread(startZoom, moveZoom, ZOOM_MOVE_ANIMATION_TIME, notifyListener);
animatingZoomInThread(startZoom, (int) moveZoom, moveZoom - (int) moveZoom, ZOOM_MOVE_ANIMATION_TIME, notifyListener);
}
if(!stopped){
@ -164,7 +164,7 @@ public class AnimateDraggingMapThread {
}
if (!stopped && moveZoom != endZoom) {
animatingZoomInThread(moveZoom, endZoom + endZoomScale, ZOOM_MOVE_ANIMATION_TIME, notifyListener);
animatingZoomInThread(moveZoom, endZoom, endZoomScale, ZOOM_MOVE_ANIMATION_TIME, notifyListener);
}
if(!stopped){
tileView.setZoomAnimate(endZoom, endZoomScale, notifyListener);
@ -205,8 +205,9 @@ public class AnimateDraggingMapThread {
}
private void animatingZoomInThread(float zoomStart, float zoomEnd, float animationTime, boolean notifyListener){
private void animatingZoomInThread(float zoomStart, int zoom, float zoomScale, float animationTime, boolean notifyListener){
float curZoom = zoomStart;
float zoomEnd = zoom + zoomScale;
animationTime *= Math.abs(zoomEnd - zoomStart);
// AccelerateInterpolator interpolator = new AccelerateInterpolator(1);
LinearInterpolator interpolator = new LinearInterpolator();
@ -227,30 +228,21 @@ public class AnimateDraggingMapThread {
stopped = true;
}
}
if(curZoom != ((int) Math.round(curZoom))){
if(Math.abs(curZoom - zoomEnd) > 2){
if(zoomStart > zoomEnd){
curZoom = (float) Math.floor(curZoom);
} else {
curZoom = (float) Math.ceil(curZoom);
tileView.setZoomAnimate(zoom, zoomScale, notifyListener);
}
tileView.zoomToAnimate(curZoom, notifyListener);
} else {
tileView.zoomToAnimate(zoomEnd, notifyListener);
}
}
}
public void startZooming(final int zoomEnd, final boolean notifyListener){
startZooming(zoomEnd, tileView.getZoomScale(), notifyListener);
}
public void startZooming(final int zoomEnd, final float zoomScale, final boolean notifyListener){
final float animationTime = ZOOM_ANIMATION_TIME;
startThreadAnimating(new Runnable(){
@Override
public void run() {
final float zoomStart = tileView.getZoom() + tileView.getZoomScale();
setTargetValues(zoomEnd, tileView.getZoomScale(), tileView.getLatitude(), tileView.getLongitude());
animatingZoomInThread(zoomStart, zoomEnd, animationTime, notifyListener);
setTargetValues(zoomEnd, zoomScale, tileView.getLatitude(), tileView.getLongitude());
animatingZoomInThread(zoomStart, zoomEnd, zoomScale, animationTime, notifyListener);
pendingRotateAnimation();
}
}); //$NON-NLS-1$

View file

@ -1,5 +1,8 @@
package net.osmand.plus.views;
import android.app.AlertDialog;
import android.content.DialogInterface;
import gnu.trove.list.array.TIntArrayList;
import net.londatiga.android.ActionItem;
import net.londatiga.android.QuickAction;
import net.osmand.data.RotatedTileBox;
@ -31,6 +34,9 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import java.util.ArrayList;
import java.util.List;
public class MapControlsLayer extends OsmandMapLayer {
private static final int SHOW_ZOOM_LEVEL_MSG_ID = 3;
@ -334,6 +340,50 @@ public class MapControlsLayer extends OsmandMapLayer {
}
});
zoomInButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
float scale = view.getZoomScale();
int p = (int) Math.round(scale * scale * 100) + 100;
final TIntArrayList tlist = new TIntArrayList(new int[] {100, 150, 200, 300, 400});
final List<String> values = new ArrayList<String>();
int i = -1;
for(int k = 0; k <= tlist.size(); k++) {
final boolean end = k == tlist.size();
if(i == -1) {
if ((end || p < tlist.get(k))) {
values.add(p + "%");
i = k;
} else if (p == tlist.get(k)) {
i = k;
}
}
if(k < tlist.size()) {
values.add(tlist.get(k) + "%");
}
}
if(values.size() != tlist.size() ) {
tlist.insert(i, p);
}
bld.setTitle(R.string.map_magnifier);
bld.setSingleChoiceItems(values.toArray(new String[values.size()]),
i, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
float newScale = (float) Math.sqrt((tlist.get(which) - 100f)/ 100f);
view.getAnimatedDraggingThread().startZooming(view.getZoom(), newScale, false);
dialog.dismiss();
}
});
bld.show();
return true;
}
});
zoomOutButton.setOnClickListener(new View.OnClickListener() {
@Override

View file

@ -157,7 +157,7 @@ public class MapTileLayer extends BaseMapLayer {
int x1 = tileBox.getPixXFromTileXNoRot(leftPlusI);
int x2 = tileBox.getPixXFromTileXNoRot(leftPlusI + 1);
int y1 = tileBox.getPixYFromTileYNoRot(topPlusJ);
int y2 = tileBox.getPixYFromTileYNoRot(topPlusJ);
int y2 = tileBox.getPixYFromTileYNoRot(topPlusJ + 1);
// TODO elliptic
// float y1 = (top + j - tileY) * ftileSize + h;
String ordImgTile = mgr.calculateTileId(map, leftPlusI, topPlusJ, nzoom);

View file

@ -170,7 +170,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
dm = new DisplayMetrics();
mgr.getDefaultDisplay().getMetrics(dm);
currentViewport = new RotatedTileBox.RotatedTileBoxBuilder().
setLocation(0, 0).setZoomAndScale(3, 1).setPixelDimensions(getWidth(), getHeight()).build();
setLocation(0, 0).setZoomAndScale(3, 0).setPixelDimensions(getWidth(), getHeight()).build();
currentViewport.setDensity(dm.density);
}
@ -249,7 +249,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
public void setIntZoom(int zoom) {
if (mainLayer != null && zoom <= mainLayer.getMaximumShownMapZoom() && zoom >= mainLayer.getMinimumShownMapZoom()) {
animatedDraggingThread.stopAnimating();
currentViewport.setZoom(zoom, currentViewport.getZoomScale());
currentViewport.setZoom(zoom, currentViewport.getZoomScale(), 0);
currentViewport.setRotate(zoom > LOWEST_ZOOM_TO_ROTATE ? rotate : 0 );
refreshMap();
}
@ -457,10 +457,6 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
return handler.hasMessages(1);
}
public boolean mapIsAnimating() {
return animatedDraggingThread != null && animatedDraggingThread.isAnimating();
}
// this method could be called in non UI thread
public void refreshMap() {
refreshMap(false);
@ -555,7 +551,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
zoomToAnimate -= (int) zoomToAnimate;
}
while (zoomToAnimate < 0) {
zoom++;
zoom--;
zoomToAnimate += 1;
}
if (mainLayer != null && mainLayer.getMaximumShownMapZoom() >= zoom && mainLayer.getMinimumShownMapZoom() <= zoom) {
@ -645,9 +641,10 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
@Override
public void onZoomEnded(float distance, float relativeToStart) {
float dz = (float) (Math.log(relativeToStart) / Math.log(2) * 1.5);
float calcZoom = initialViewport.getZoom() + dz;
changeZoomPosition(dz);
float dz = (float) (Math.log(relativeToStart) / Math.log(2)); //* 1.5);
final int rz = Math.round(dz);
setIntZoom(rz + initialViewport.getZoom());
final int newZoom = getZoom();
if (application.getInternalAPI().accessibilityEnabled()) {
if (newZoom != initialViewport.getZoom()) {
@ -678,7 +675,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
@Override
public void onZooming(float distance, float relativeToStart) {
float dz = (float) (Math.log(relativeToStart) / Math.log(2) * 1.5);
float dz = (float) (Math.log(relativeToStart) / Math.log(2)); // * 1.5);
if (Math.abs(dz) > 0.05) {
changeZoomPosition(dz);
}
@ -687,13 +684,14 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
private void changeZoomPosition(float dz) {
float calcZoom = initialViewport.getZoom() + dz + initialViewport.getZoomScale();
final QuadPoint cp = initialViewport.getCenterPixelPoint();
float dx = initialMultiTouchCenterPoint.x - cp.x;
float dy = initialMultiTouchCenterPoint.y - cp.y;
float dx = cp.x - initialMultiTouchCenterPoint.x ;
float dy = cp.y - initialMultiTouchCenterPoint.y ;
final RotatedTileBox calc = initialViewport.copy();
calc.setLatLonCenter(initialCenterLatLon.getLatitude(), initialCenterLatLon.getLongitude());
calc.setZoom(initialViewport.getZoom(), dz + initialViewport.getZoomScale());
final LatLon r = calc.getLatLonFromPixel(cp.x + dx, cp.y + dy);
zoomToAnimate(calcZoom, true);
setLatLon(r.getLatitude(), r.getLongitude());
zoomToAnimate(calcZoom, true);
}
}