Issue
I want to draw arrows manually over map. I'm not using the rotation of drawables for performance issues as I have many overlays that slow the app if drawn using this technique.
I will draw arrows manually, given a gps point and rotation angle I need to draw the arrow over that point. I will extend overlay class and on the draw method, I will do the drawing work.
Any suggestions ?
Solution
I dealt with the same problem in my app. The code is on github
Basically I override draw
and rotate the canvas before drawing the arrow.
@Override
public void draw(Canvas canvas) {
//NOTE: 0, 0 is the bottom center point of the bus icon
//first draw the bus
vehicle.draw(canvas);
//then draw arrow
if (arrow != null && heading != BusLocation.NO_HEADING)
{
//put the arrow in the bus window
int arrowLeft = -(arrow.getIntrinsicWidth() / 4);
int arrowTop = -vehicle.getIntrinsicHeight() + arrowTopDiff;
//NOTE: use integer division when possible. This code is frequently executed
int arrowWidth = (arrow.getIntrinsicWidth() * 6) / 10;
int arrowHeight = (arrow.getIntrinsicHeight() * 6) / 10;
int arrowRight = arrowLeft + arrowWidth;
int arrowBottom = arrowTop + arrowHeight;
arrow.setBounds(arrowLeft, arrowTop, arrowRight, arrowBottom);
canvas.save();
//set rotation pivot at the center of the arrow image
canvas.rotate(heading, arrowLeft + arrowWidth/2, arrowTop + arrowHeight / 2);
Rect rect = arrow.getBounds();
arrow.draw(canvas);
arrow.setBounds(rect);
canvas.restore();
}
}
Answered By - noisecapella
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.