I use this code:
public class PolylineOverlay extends Overlay
{
private ArrayList<GeoPoint> polyline; // Contains set of points to be
connected.
private Paint pathPaint = null; // Paint tool that is used to draw
on the map canvas.
public PolylineOverlay(ArrayList<GeoPoint> polyline, int color)
{
this.polyline = new ArrayList<GeoPoint>(polyline);
this.pathPaint = new Paint();
this.pathPaint.setAntiAlias(true);
this.pathPaint.setStrokeWidth(4);
this.pathPaint.setColor(color);
this.pathPaint.setAlpha(120);
this.pathPaint.setStyle(Paint.Style.STROKE);
}
@Override
public void draw(Canvas canvas, MapView mView, boolean shadow)
{
if(!shadow)
{
if(polyline != null)
{
Projection projection = mView.getProjection();
Path routePath = new Path();
Point prevPoint = null;
//Add each point to the routePath.
for(GeoPoint inPoint : polyline)
{
Point outPoint = null;
outPoint = projection.toPixels(inPoint,
outPoint);
if(polyline.indexOf(inPoint) == 0)
routePath.moveTo(outPoint.x,
outPoint.y);
else
{
if(isOnePointVisible(prevPoint,
outPoint, mView))
{
routePath.moveTo(prevPoint.x, prevPoint.y);
routePath.lineTo(outPoint.x, outPoint.y);
}
}
prevPoint = outPoint;
}
canvas.drawPath(routePath, pathPaint);
}
}
super.draw(canvas, mView, shadow);
}
private boolean isOnePointVisible(Point point, Point point2,
MapView mapView)
{
return (point.x > 0 && point.x < mapView.getWidth() && point.y >
0 && point.y < mapView.getHeight()) ||
(point2.x > 0 && point2.x < mapView.getWidth() && point2.y > 0
&& point2.y < mapView.getHeight());
}
@Override
public boolean onTap(GeoPoint p, MapView mapView) {
// Handle tapping on the overlay here
return false;
}
}
About the size with 300 or 400 GeoPoints i am already having
problems... The method isOnePointVisible is an optimization i did in
order to try to improve performance (seems to work fine).
Thanks!
On 1 jul, 00:16, TreKing <[email protected]> wrote:
> On Thu, Jun 30, 2011 at 4:46 PM, Felix Garcia Lainez <
>
> [email protected]> wrote:
> > On this method i iterate over an array of GeoPoints and using a canvas y
> > connect all points.
>
> What's your actual code?
>
> > It works fine more or less, but i am having issues when drawing long routes
> > with many points.
>
> Define "long routes" and "many points".
>
> ---------------------------------------------------------------------------
> ----------------------
> TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
> transit tracking app for Android-powered devices
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en