No need to worry about the screen pixels relative to your waypoints. The
overlay manager handles that for you, and only renders the part that is on
screen. Load all the points.
On Thursday, May 17, 2012 12:19:33 PM UTC-4, Simon Giddings wrote:
>
> I am developing a maps application which will display a user defined
> driving itinerary.
> I obtain the driving directions from the Directions Web Service and parse
> the json response in a separate thread.
>
> I then hand the resulting itinerary object to my custom overlay for
> display.
> Before appending the overlay to the maps overlay list, I decode the
> polyline strings to obtain the coordinates.
>
> My drawing code obtains the projection object and draws out the line -
> this is taking 18 seconds ! ! !
> Here is my code :
>
> @Override
> public void draw(Canvas cv, MapView view, boolean shadow)
> {
> GeoCoordsE6 point = null; // utility class holding a geopoint and
> a point class with a method to handle projection manipulation
> int iScreenWidth = view.getWidth();
> int iScreenHeight = view.getHeight();
> Paint paintLine = null;new Paint();
>
> if(shadow)
> {
> super.draw(cv, view, shadow);
> return;
> }
>
> long lStartMs = android.os.SystemClock.uptimeMillis();
>
> paintLine = new Paint();
> paintLine.setColor(m_iLineClr);
> paintLine.setAntiAlias(true);
> paintLine.setStyle(Paint.Style.FILL_AND_STROKE);
> paintLine.setStrokeJoin(Paint.Join.ROUND);
> paintLine.setStrokeCap(Paint.Cap.ROUND);
> paintLine.setStrokeWidth(4);
>
> // get the projection to work with
> Projection pj = view.getProjection();
>
> // get the first lat/lng position
> point = m_ItinLine.item(0);
> // convert the coorinates to screen pixels
> point.ResolvePosition(pj);
> // store the start position
> m_ptStart.x = point.m_pt.x;
> m_ptStart.y = point.m_pt.y;
>
> // now walk through the array list
> for(int i = 1; i < m_ItinLine.count(); i++)
> {
> point = m_ItinLine.item(i);
> point.ResolvePosition(pj);
> m_ptEnd.x = point.m_pt.x;
> m_ptEnd.y = point.m_pt.y;
>
> if(m_ptStart.x < 0 && m_ptEnd.x < 0 || // to the left
> m_ptStart.y < 0 && m_ptEnd.y < 0 || // above the top
> m_ptStart.x > iScreenWidth && m_ptEnd.x > iScreenWidth
> || // to the right
> m_ptStart.y > iScreenHeight && m_ptEnd.y >
> iScreenHeight) // below the bottom
> {
> // ignore the drawing
> }
> else if(m_ptStart.x == m_ptEnd.x && m_ptStart.y == m_ptEnd.y)
> continue;
> else
> {
> cv.drawLine(m_ptStart.x, m_ptStart.y, m_ptEnd.x,
> m_ptEnd.y, paintLine);
> }
>
> m_ptStart.x = m_ptEnd.x;
> m_ptStart.y = m_ptEnd.y;
> }
>
> long lEndMs = android.os.SystemClock.uptimeMillis();
> Log.d("ItineraryOverlay", "Drawing took " + (lEndMs - lStartMs) +
> "ms");
>
> super.draw(cv, view, shadow);
> }
>
> Knowing that a number of people have done similar tasks, can anyone advise
> me as to how to improve the performance ?
> Should I be building a path object and fill it with ALL of the points ?
>
>
>
--
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