Fix qt builds with routes

This commit is contained in:
Victor Shcherb 2015-01-25 21:52:10 +01:00
parent ec42479638
commit d6d63e1cb2
3 changed files with 66 additions and 15 deletions

View file

@ -1,5 +1,7 @@
package net.osmand.plus.views;
import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -304,7 +306,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
WptPt ls = l.get(i);
if (startIndex == -1) {
if (ls.lat >= latLonBounds.bottom - 0.1 && ls.lat <= latLonBounds.top + 0.1 && ls.lon >= latLonBounds.left - 0.1
&& ls.lon <= latLonBounds.right + 0.1 && !isPointVisited(ls)) {
&& ls.lon <= latLonBounds.right + 0.1) {
startIndex = i > 0 ? i - 1 : i;
}
} else if (!(latLonBounds.left <= ls.lon + 0.1 && ls.lon - 0.1 <= latLonBounds.right
@ -326,18 +328,16 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private void drawSegment(Canvas canvas, RotatedTileBox tb, List<WptPt> l, int startIndex, int endIndex) {
int px = tb.getPixXFromLonNoRot(l.get(startIndex).lon);
int py = tb.getPixYFromLatNoRot(l.get(startIndex).lat);
path.moveTo(px, py);
for (int i = startIndex + 1; i <= endIndex; i++) {
TIntArrayList tx = new TIntArrayList();
TIntArrayList ty = new TIntArrayList();
for (int i = startIndex; i <= endIndex; i++) {
WptPt p = l.get(i);
if(isPointVisited(p)) {
continue;
}
int x = tb.getPixXFromLonNoRot(p.lon);
int y = tb.getPixYFromLatNoRot(p.lat);
path.lineTo(x, y);
tx.add(x);
ty.add(y);
}
calculatePath(tb, tx, ty, path);
if(isPaint_1) {
canvas.drawPath(path, paint_1);
}

View file

@ -1,10 +1,14 @@
package net.osmand.plus.views;
import gnu.trove.list.array.TIntArrayList;
import java.util.Map;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.util.MapAlgorithms;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.PointF;
import android.os.AsyncTask;
import android.view.MotionEvent;
@ -69,6 +73,49 @@ public abstract class OsmandMapLayer {
}
}
private boolean isIn(int x, int y, int lx, int ty, int rx, int by) {
return x >= lx && x <= rx && y >= ty && y <= by;
}
public void calculatePath(RotatedTileBox tb, TIntArrayList xs, TIntArrayList ys, Path path) {
boolean start = false;
int px = xs.get(0);
int py = ys.get(0);
int h = tb.getPixHeight();
int w = tb.getPixWidth();
boolean pin = isIn(px, py, 0, 0, w, h);
for(int i = 1; i < xs.size(); i++) {
int x = xs.get(i);
int y = ys.get(i);
boolean in = isIn(x, y, 0, 0, w, h);
if(pin && in) {
if(!start) {
path.moveTo(px, py);
}
path.lineTo(x, y);
start = true;
} else{
long intersection = MapAlgorithms.calculateIntersection(x, y, px, py, 0, w, h, 0);
if(intersection != -1) {
int bx = (int) (intersection >> 32);
int by = (int) (intersection & 0xffffffff);
if(!start) {
path.moveTo(bx, by);
}
path.lineTo(x, y);
start = true;
} else {
start = false;
}
}
pin = in;
px = x;
py = y;
}
}
public abstract class MapLayerData<T> {
public int ZOOM_THRESHOLD = 1;
public RotatedTileBox queriedBox;

View file

@ -1,5 +1,7 @@
package net.osmand.plus.views;
import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -8,6 +10,7 @@ import net.osmand.Location;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.R;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.render.OsmandRenderer;
import net.osmand.plus.render.OsmandRenderer.RenderingContext;
import net.osmand.plus.routing.RoutingHelper;
@ -161,16 +164,17 @@ public class RouteLayer extends OsmandMapLayer {
private void drawSegment(RotatedTileBox tb, Canvas canvas) {
if (points.size() > 0) {
paint.setStrokeWidth(12 * tb.getDensity());
int px = tb.getPixXFromLonNoRot(points.get(0).getLongitude());
int py = tb.getPixYFromLatNoRot(points.get(0).getLatitude());
path.moveTo(px, py);
for (int i = 1; i < points.size(); i++) {
TIntArrayList tx = new TIntArrayList();
TIntArrayList ty = new TIntArrayList();
for (int i = 0; i < points.size(); i++) {
Location o = points.get(i);
int x = tb.getPixXFromLonNoRot(o.getLongitude());
int y = tb.getPixYFromLatNoRot(o.getLatitude());
path.lineTo(x, y);
tx.add(x);
ty.add(y);
}
calculatePath(tb, tx, ty, path);
if(isPaint_1) {
canvas.drawPath(path, paint_1);
}