add method to set PathOverlay points from GeometryBuffer

This commit is contained in:
Hannes Janetzek 2013-08-10 11:16:41 +02:00
parent d0e34a7886
commit 69fe006725
3 changed files with 40 additions and 8 deletions

View File

@ -89,9 +89,9 @@ public class MapPosition {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("["); builder.append("[");
builder.append("X: "); builder.append("X: ");
builder.append((long)(x * (1 << zoomLevel))); builder.append(x);
builder.append(", Y: "); builder.append(", Y: ");
builder.append((long)(y * (1 << zoomLevel))); builder.append(y);
builder.append(", Z: "); builder.append(", Z: ");
builder.append(zoomLevel); builder.append(zoomLevel);
builder.append("]"); builder.append("]");

View File

@ -111,6 +111,14 @@ public final class MercatorProjection {
out[pos * 2 +1] = 0.5 - Math.log((1.0 + sinLatitude) / (1.0 - sinLatitude)) / (4.0 * Math.PI); out[pos * 2 +1] = 0.5 - Math.log((1.0 + sinLatitude) / (1.0 - sinLatitude)) / (4.0 * Math.PI);
} }
public static void project(double latitude, double longitude, double[] out, int pos) {
out[pos * 2] = (longitude + 180.0) / 360.0;
double sinLatitude = Math.sin(latitude * (Math.PI / 180.0));
out[pos * 2 +1] = 0.5 - Math.log((1.0 + sinLatitude) / (1.0 - sinLatitude)) / (4.0 * Math.PI);
}
/** /**
* @param latitude * @param latitude
* the latitude value which should be checked. * the latitude value which should be checked.

View File

@ -19,9 +19,9 @@ package org.oscim.layers.overlay;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.oscim.view.MapView;
import org.oscim.backend.canvas.Paint.Cap; import org.oscim.backend.canvas.Paint.Cap;
import org.oscim.core.GeoPoint; import org.oscim.core.GeoPoint;
import org.oscim.core.GeometryBuffer;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.core.MercatorProjection; import org.oscim.core.MercatorProjection;
import org.oscim.core.Tile; import org.oscim.core.Tile;
@ -32,6 +32,7 @@ import org.oscim.renderer.sublayers.LineLayer;
import org.oscim.theme.renderinstruction.Line; import org.oscim.theme.renderinstruction.Line;
import org.oscim.utils.FastMath; import org.oscim.utils.FastMath;
import org.oscim.utils.LineClipper; import org.oscim.utils.LineClipper;
import org.oscim.view.MapView;
/** This class draws a path line in given color. */ /** This class draws a path line in given color. */
public class PathOverlay extends Layer { public class PathOverlay extends Layer {
@ -67,6 +68,7 @@ public class PathOverlay extends Layer {
private int mCurX = -1; private int mCurX = -1;
private int mCurY = -1; private int mCurY = -1;
private int mCurZ = -1; private int mCurZ = -1;
private int mNumPoints;
// note: this is called from GL-Thread. so check your syncs! // note: this is called from GL-Thread. so check your syncs!
// TODO use an Overlay-Thread to build up layers (like for Labeling) // TODO use an Overlay-Thread to build up layers (like for Labeling)
@ -86,25 +88,42 @@ public class PathOverlay extends Layer {
mCurY = ty; mCurY = ty;
mCurZ = tz; mCurZ = tz;
int size = mPoints.size(); int size = mNumPoints;
if (mUpdatePoints) { if (mUpdatePoints) {
synchronized (mPoints) { synchronized (mPoints) {
mUpdatePoints = false; mUpdatePoints = false;
mNumPoints = size = mPoints.size();
ArrayList<GeoPoint> geopoints = mPoints; ArrayList<GeoPoint> geopoints = mPoints;
double[] points = mPreprojected; double[] points = mPreprojected;
if (size * 2 > points.length) { if (size * 2 > points.length) {
points = mPreprojected = new double[size*2]; points = mPreprojected = new double[size * 2];
mPPoints = new float[size*2]; mPPoints = new float[size * 2];
} }
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
MercatorProjection.project(geopoints.get(i), points, i); MercatorProjection.project(geopoints.get(i), points, i);
} }
} } else if (mGeom != null) {
GeometryBuffer geom = mGeom;
mGeom = null;
size = geom.index[0];
double[] points = mPreprojected;
if (size > points.length) {
points = mPreprojected = new double[size * 2];
mPPoints = new float[size * 2];
}
for (int i = 0; i < size; i += 2)
MercatorProjection.project(geom.points[i + 1], geom.points[i], points, i >> 1);
mNumPoints = size = size >> 1;
}
if (size == 0) { if (size == 0) {
if (layers.baseLayers != null) { if (layers.baseLayers != null) {
@ -126,7 +145,6 @@ public class PathOverlay extends Layer {
double my = pos.y; double my = pos.y;
double scale = Tile.SIZE * (1 << z); double scale = Tile.SIZE * (1 << z);
// flip around dateline. complicated stuff.. // flip around dateline. complicated stuff..
int flip = 0; int flip = 0;
int flipMax = Tile.SIZE << (z - 1); int flipMax = Tile.SIZE << (z - 1);
@ -310,6 +328,12 @@ public class PathOverlay extends Layer {
} }
} }
GeometryBuffer mGeom;
public void setGeom(GeometryBuffer geom) {
mGeom = geom;
}
public void setPoints(List<GeoPoint> pts) { public void setPoints(List<GeoPoint> pts) {
synchronized (mPoints) { synchronized (mPoints) {
mPoints.clear(); mPoints.clear();