This commit is contained in:
@@ -20,12 +20,16 @@
|
||||
*/
|
||||
package org.oscim.layers.vector;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.LineString;
|
||||
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.core.GeoPoint;
|
||||
import org.oscim.core.Point;
|
||||
import org.oscim.layers.vector.geometries.LineDrawable;
|
||||
import org.oscim.layers.vector.geometries.Style;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.utils.GeoPointUtils;
|
||||
import org.oscim.utils.geom.GeomBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -42,6 +46,9 @@ public class PathLayer extends VectorLayer {
|
||||
protected Style mStyle;
|
||||
protected LineDrawable mDrawable;
|
||||
|
||||
private final Point mPoint1 = new Point();
|
||||
private final Point mPoint2 = new Point();
|
||||
|
||||
public PathLayer(Map map, Style style) {
|
||||
super(map);
|
||||
mStyle = style;
|
||||
@@ -194,6 +201,12 @@ public class PathLayer extends VectorLayer {
|
||||
remove(mDrawable);
|
||||
mDrawable = new LineDrawable(path, mStyle);
|
||||
add(mDrawable);
|
||||
|
||||
mPoints.clear();
|
||||
for (int i = 0; i < path.getNumPoints(); i++) {
|
||||
Coordinate c = path.getCoordinateN(i);
|
||||
mPoints.add(new GeoPoint(c.y, c.x));
|
||||
}
|
||||
}
|
||||
mWorker.submit(0);
|
||||
}
|
||||
@@ -204,8 +217,29 @@ public class PathLayer extends VectorLayer {
|
||||
remove(mDrawable);
|
||||
mDrawable = new LineDrawable(lonLat, mStyle);
|
||||
add(mDrawable);
|
||||
|
||||
mPoints.clear();
|
||||
for (int i = 0; i < lonLat.length; i += 2)
|
||||
mPoints.add(new GeoPoint(lonLat[i + 1], lonLat[i]));
|
||||
}
|
||||
mWorker.submit(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean contains(float x, float y) {
|
||||
// Touch min 20 px at baseline mdpi (160dpi)
|
||||
double distance = Math.max(20 / 2 * CanvasAdapter.getScale(), mStyle.strokeWidth);
|
||||
for (int i = 0; i < mPoints.size() - 1; i++) {
|
||||
if (i == 0)
|
||||
mMap.viewport().toScreenPoint(mPoints.get(i), false, mPoint1);
|
||||
else {
|
||||
mPoint1.x = mPoint2.x;
|
||||
mPoint1.y = mPoint2.y;
|
||||
}
|
||||
mMap.viewport().toScreenPoint(mPoints.get(i + 1), false, mPoint2);
|
||||
if (GeoPointUtils.distanceSegmentPoint(mPoint1.x, mPoint1.y, mPoint2.x, mPoint2.y, x, y) <= distance)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,9 +26,13 @@ import com.vividsolutions.jts.simplify.DouglasPeuckerSimplifier;
|
||||
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.core.Box;
|
||||
import org.oscim.core.GeoPoint;
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.event.Gesture;
|
||||
import org.oscim.event.GestureListener;
|
||||
import org.oscim.event.MotionEvent;
|
||||
import org.oscim.layers.vector.geometries.Drawable;
|
||||
import org.oscim.layers.vector.geometries.LineDrawable;
|
||||
import org.oscim.layers.vector.geometries.PointDrawable;
|
||||
@@ -41,6 +45,7 @@ import org.oscim.theme.styles.LineStyle;
|
||||
import org.oscim.utils.FastMath;
|
||||
import org.oscim.utils.QuadTree;
|
||||
import org.oscim.utils.SpatialIndex;
|
||||
import org.oscim.utils.geom.GeomBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -57,7 +62,7 @@ import static org.oscim.core.MercatorProjection.longitudeToX;
|
||||
* package and
|
||||
* JTS geometries together with a GeometryStyle
|
||||
*/
|
||||
public class VectorLayer extends AbstractVectorLayer<Drawable> {
|
||||
public class VectorLayer extends AbstractVectorLayer<Drawable> implements GestureListener {
|
||||
|
||||
public static final Logger log = LoggerFactory.getLogger(VectorLayer.class);
|
||||
|
||||
@@ -351,4 +356,19 @@ public class VectorLayer extends AbstractVectorLayer<Drawable> {
|
||||
(float) (y + radius * Math.sin(i * step)));
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized boolean contains(float x, float y) {
|
||||
GeoPoint geoPoint = mMap.viewport().fromScreenPoint(x, y);
|
||||
Point point = new GeomBuilder().point(geoPoint.getLongitude(), geoPoint.getLatitude()).toPoint();
|
||||
for (Drawable drawable : tmpDrawables) {
|
||||
if (drawable.getGeometry().contains(point))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onGesture(Gesture g, MotionEvent e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user