我已经完成了在我的叠加层上画线,但我怎么能画自由式!?不是固定的几何形状,比如线条和圆圈,而是在我想画的地方画!?
我已经拥有的是:
public class OverlayMap extends Overlay {
private List<MapGeoLine> geoLines = new ArrayList<MapGeoLine>();
private GeoPoint geoFrom = null;
private GeoPoint geoTo = null;
@Override
public boolean onTouchEvent(MotionEvent motionEvent, MapView mapView) {
if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
geoFrom = mapView.getProjection().fromPixels((int)motionEvent.getX(),(int)motionEvent.getY());
}
if(motionEvent.getAction() == MotionEvent.ACTION_UP){
geoTo = mapView.getProjection().fromPixels((int)motionEvent.getX(),(int)motionEvent.getY());
}
if(geoFrom != null && geoTo != null){
geoLines.add(new MapGeoLine(geoFrom, geoTo));
}
return super.onTouchEvent(motionEvent, mapView);
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
if(geoLines.size() > 0){
Paint mPaint = new Paint();
mPaint.setStrokeWidth(2);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setAntiAlias(true);
Projection projection = mapView.getProjection();
Path path = new Path();
for(MapGeoLine line: geoLines){
Log.d("test", "p1: "+line.getFrom().getLatitudeE6()+ " ");
Log.d("test", "p2: "+line.getTo().getLatitudeE6()+ " ");
Point from = new Point();
Point to = new Point();
projection.toPixels(line.getFrom(), from);
projection.toPixels(line.getTo(), to);
path.moveTo(from.x, from.y);
path.lineTo(to.x, to.y);
}
canvas.drawPath(path, mPaint);
mapView.invalidate();
}
super.draw(canvas, mapView, shadow);
}
}