Merge pull request #4020 from osmandapp/add_ruler

Add ruler
This commit is contained in:
Alexey 2017-07-03 15:54:08 +03:00 committed by GitHub
commit 9ad49fa23d
5 changed files with 80 additions and 32 deletions

View file

@ -53,7 +53,7 @@ public class DoubleTapScaleDetector {
}
public boolean onTouchEvent(MotionEvent event) {
if (event.getPointerCount() != 1) {
if (event.getPointerCount() != 1 || !view.mapGestureAllowed(OsmandMapLayer.MapGestureType.DOUBLE_TAP_ZOOM_CHANGE)) {
resetEvents();
mIsDoubleTapping = false;
mScrolling = false;

View file

@ -1,24 +1,5 @@
package net.osmand.plus.views;
import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import net.osmand.data.LatLon;
import net.osmand.data.QuadRect;
import net.osmand.data.QuadTree;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.render.OsmandRenderer;
import net.osmand.plus.render.OsmandRenderer.RenderingContext;
import net.osmand.render.RenderingRuleSearchRequest;
import net.osmand.render.RenderingRulesStorage;
import net.osmand.util.MapAlgorithms;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
@ -34,11 +15,41 @@ import android.os.AsyncTask;
import android.support.annotation.NonNull;
import android.view.MotionEvent;
import net.osmand.data.LatLon;
import net.osmand.data.QuadRect;
import net.osmand.data.QuadTree;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.render.OsmandRenderer;
import net.osmand.plus.render.OsmandRenderer.RenderingContext;
import net.osmand.render.RenderingRuleSearchRequest;
import net.osmand.render.RenderingRulesStorage;
import net.osmand.util.MapAlgorithms;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import gnu.trove.list.array.TIntArrayList;
public abstract class OsmandMapLayer {
protected List<LatLon> fullObjectsLatLon;
protected List<LatLon> smallObjectsLatLon;
public enum MapGestureType {
DOUBLE_TAP_ZOOM_IN,
DOUBLE_TAP_ZOOM_CHANGE,
TWO_POINTERS_ZOOM_OUT
}
public boolean isMapGestureAllowed(MapGestureType type) {
return true;
}
public abstract void initLayer(OsmandMapTileView view);
public abstract void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings);

View file

@ -226,6 +226,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
@Override
public void onTwoFingerTap() {
//afterTwoFingersTap = true;
if (!mapGestureAllowed(OsmandMapLayer.MapGestureType.TWO_POINTERS_ZOOM_OUT)) {
return;
}
if (isZoomingAllowed(getZoom(), -1.1f)) {
getAnimatedDraggingThread().startZooming(getZoom() - 1, currentViewport.getZoomFloatPart(), false);
if (wasMapLinkedBeforeGesture) {
@ -335,6 +338,15 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
this.wasZoomInMultiTouch = wasZoomInMultiTouch;
}
public boolean mapGestureAllowed(OsmandMapLayer.MapGestureType type) {
for (OsmandMapLayer layer : layers) {
if (!layer.isMapGestureAllowed(type)) {
return false;
}
}
return true;
}
public void setIntZoom(int zoom) {
zoom = zoom > getMaxZoom() ? getMaxZoom() : zoom;
zoom = zoom < getMinZoom() ? getMinZoom() : zoom;

View file

@ -108,10 +108,18 @@ public class RulerControlLayer extends OsmandMapLayer {
};
}
@Override
public boolean isMapGestureAllowed(MapGestureType type) {
if (rulerModeOn() && type == MapGestureType.TWO_POINTERS_ZOOM_OUT) {
return false;
} else {
return true;
}
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
if (mapActivity.getMapLayers().getMapWidgetRegistry().isVisible("ruler") &&
rightWidgetsPanel.getVisibility() == View.VISIBLE) {
if (rulerModeOn()) {
lineAttrs.updatePaints(view, settings, tb);
circleAttrs.updatePaints(view, settings, tb);
circleAttrs.paint2.setStyle(Style.FILL);
@ -150,6 +158,11 @@ public class RulerControlLayer extends OsmandMapLayer {
}
}
private boolean rulerModeOn() {
return mapActivity.getMapLayers().getMapWidgetRegistry().isVisible("ruler") &&
rightWidgetsPanel.getVisibility() == View.VISIBLE;
}
public void refreshMapDelayed() {
handler.sendEmptyMessageDelayed(0, DELAY + 50);
}
@ -208,7 +221,7 @@ public class RulerControlLayer extends OsmandMapLayer {
boolean move = tb.getZoom() != cacheIntZoom || Math.abs(tb.getCenterTileX() - cacheTileX) > 1 ||
Math.abs(tb.getCenterTileY() - cacheTileY) > 1;
if (!mapActivity.getMapView().isZooming() && move) {
if (!tb.isZoomAnimated() && move) {
cacheIntZoom = tb.getZoom();
cacheTileX = tb.getCenterTileX();
cacheTileY = tb.getCenterTileY();

View file

@ -207,8 +207,12 @@ public class MapInfoWidgetsFactory {
LatLon centerLoc = map.getMapLocation();
if (currentLoc != null && centerLoc != null) {
setDistanceText(currentLoc.getLatitude(), currentLoc.getLongitude(),
centerLoc.getLatitude(), centerLoc.getLongitude());
if (map.getMapViewTrackingUtilities().isMapLinkedToLocation()) {
setDistanceText(0);
} else {
setDistanceText(currentLoc.getLatitude(), currentLoc.getLongitude(),
centerLoc.getLatitude(), centerLoc.getLongitude());
}
}
} else {
setText(title, null);
@ -216,13 +220,21 @@ public class MapInfoWidgetsFactory {
return true;
}
private void setDistanceText(double firstLat, double firstLon, double secondLat, double secondLon) {
float dist = (float) MapUtils.getDistance(firstLat, firstLon, secondLat, secondLon);
String distance = OsmAndFormatter.getFormattedDistance(dist, map.getMyApplication());
int ls = distance.lastIndexOf(' ');
setText(distance.substring(0, ls), distance.substring(ls + 1));
}
};
private void setDistanceText(float dist) {
calculateAndSetText(dist);
}
private void setDistanceText(double firstLat, double firstLon, double secondLat, double secondLon) {
float dist = (float) MapUtils.getDistance(firstLat, firstLon, secondLat, secondLon);
calculateAndSetText(dist);
}
private void calculateAndSetText(float dist) {
String distance = OsmAndFormatter.getFormattedDistance(dist, map.getMyApplication());
int ls = distance.lastIndexOf(' ');
setText(distance.substring(0, ls), distance.substring(ls + 1));
}
};
rulerControl.setText(title, null);
setRulerControlIcon(rulerControl, map.getMyApplication().getSettings().RULER_MODE.get());