Rotating Map View annd Overlays

Tutorials that use the MapActivity. Many using GPS functionality.

Rotating Map View annd Overlays

Postby verdebreuk » Fri Jun 26, 2009 3:17 am

perhaps someone can help me get on the right path for solving this problem. I spent this evening at it with minimal success. I have a MapView which I rotate so that the users bearing is always vertical on the display. I also have some overlays that I am applying to the map. They are small images.

My problem is that the images, although they rotate and stay in the correct position, they are no longer up-right. For example if the user is moving south and my map is rotated a full 180 degress then so are my images and the user will see them upside down.

My approach to this is to override ItemizedOverlay.draw and apply some transformations to the images to get them the way I want. So first off, is this a reasonable approach. I'm wondering if I should just dispense with using Overlays and draw the icons manually.

My last attempt went something like this

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void draw(final Canvas canvas, MapView mapview, final boolean shadow)
  2.  
  3. {
  4.  
  5.             // Im gonna mess with the canvas here so save it
  6.  
  7.             canvas.save();
  8.  
  9.  
  10.  
  11.             Matrix m = canvas.getMatrix();
  12.  
  13.  
  14.  
  15.             // Im trying to determine here how the original point where the icon was located gets moved by the rotation
  16.  
  17.             float [] pts = { iconPoint.x, iconPoint.y};
  18.  
  19.             m.mapPoints(pts);
  20.  
  21.  
  22.  
  23.             // now try to undo the rotation of the actual icon, but keep it in the same spot on map
  24.  
  25.             m.postRotate(-bearing , pts[0], pts[1] );
  26.  
  27.             canvas.setMatrix(m);
  28.  
  29.  
  30.  
  31.             super.draw(canvas, mapview, shadow);
  32.  
  33.  
  34.  
  35.             canvas.restore();
  36.  
  37. }
  38.  
  39.  
  40.  
  41.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
verdebreuk
Freshman
Freshman
 
Posts: 2
Joined: Fri Jun 26, 2009 1:23 am
Location: ottawa

Top

Postby verdebreuk » Mon Jun 29, 2009 3:36 am

Just a quick update. I solved this problem but not until after taking some time to understand how the transformation matrices work. I was reasonably close in the code snippet above, The problems were first, setting the proper center of rotation, and second using a preRotate versus postRotate. Here is what I have which is now working in the ItemizedOverlay draw() method.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. canvas.save();
  2.  
  3. Point pnt = mapProjection.toPixels(item.getPoint(), null );
  4.  
  5. Matrix m = canvas.getMatrix();
  6.  
  7. m.preRotate((float)bearing, pnt.x, pnt.y);
  8.  
  9. canvas.setMatrix(m);
  10.  
  11. super.draw(canvas, mapview, shadow);
  12.  
  13. canvas.restore();
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
verdebreuk
Freshman
Freshman
 
Posts: 2
Joined: Fri Jun 26, 2009 1:23 am
Location: ottawa

Re: Rotating Map View annd Overlays

Postby tylerdurden45 » Tue Jul 05, 2011 2:12 pm

Could you please share full code of rotate mapview?


kind regards
tylerdurden45
Freshman
Freshman
 
Posts: 4
Joined: Tue Jul 05, 2011 8:50 am

Re: Rotating Map View annd Overlays

Postby qubit » Sun Jul 10, 2011 6:27 am

tylerdurden45 wrote:Could you please share full code of rotate mapview?


kind regards


Google is your friend

http://code.google.com/p/cameralert/wiki/RotateTouches
qubit
Freshman
Freshman
 
Posts: 3
Joined: Thu Feb 11, 2010 1:00 pm

Top

Return to Map Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests