How to know when MapView finishing zooming?

Tutorials that use the MapActivity. Many using GPS functionality.

How to know when MapView finishing zooming?

Postby lapacho » Thu Apr 01, 2010 7:50 pm

Hi,

I have overlays items for markers and an overlay for a drawing. I really don't like the idea of drawing just for drawing and using cpu cylces in vain, so I need to know how we can assure that the MapView has finishing his zoom to get the properly projection of it.

What I mean? Well, If you implement an Overlay, you will see that if you zoom the MapView the API function getZoomLevel() will return the NEW zoom level but the draw isn't finished by the MapView.

To be clear, here is an example of what I want to accomplish:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.    
  2.  
  3. GeoPoint oldMapCenter = mapCenter;
  4.  
  5. GeoPoint mapCenter  = mapv.getMapCenter();
  6.  
  7. projection = mapv.getProjection();
  8.  
  9. Point center = projection.toPixels(mapCenter, null);
  10.  
  11. if ( oldMapCenter == null ) {
  12.  
  13.         mPath  = new Path();       
  14.  
  15.         for(int i = 0; i < itemCount; i++) {
  16.  
  17.               mItem = mPoints.get(i);
  18.  
  19.               if ( !mItem.isInterestPoint() ) {
  20.  
  21.                      if ( i == 0 ) {
  22.  
  23.                             point = projection.toPixels(mItem.getGeoPoint(), null);
  24.  
  25.                             mPath.moveTo(point.x, point.y);
  26.  
  27.                         }
  28.  
  29.                         else {
  30.  
  31.                             point = projection.toPixels(mItem.getGeoPoint(), null);
  32.  
  33.                             mPath.lineTo(point.x, point.y);
  34.  
  35.                         }
  36.  
  37.                 }
  38.  
  39.         }
  40.  
  41. }
  42.  
  43. else if ( mapCenter.getLatitudeE6()  != oldMapCenter.getLatitudeE6() ||
  44.  
  45.         mapCenter.getLongitudeE6() != oldMapCenter.getLongitudeE6() ) {
  46.  
  47.         offset = projection.toPixels(oldMapCenter, null);
  48.  
  49.         mPath.offset(offset.x - center.x , offset.y - center.y);
  50.  
  51. }
  52.  
  53. else {
  54.  
  55.         //nothing to be done. DO NOT MAKE ANOTHER PATH OBJECT IN VAIN.
  56.  
  57. }
  58.  
  59. canvas.drawPath(mPath, mPaint);
  60.  
  61.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


The problem is that when you zoom, the old path will be shown and I want to get then a new path with the new projection. I have tried using an oldZoom and currentZoom, but as zoom you set the zoom to the controller, you will get the new zoom level but the projection will be the old.

It seems that google guys missed here that, because MapView calls the draw method on every overlay, including an itemized overlay. At least I tried that and when I draw the new path with the new zoom level, the path is drawn in the same place (I assume is because the projection is the old one). Then, I zoom again, and the new path is drawn on the place that should be drawn before.

Any hints, ideas or something to accomplish this? I need to know WHEN the MapView really has his projection ready for the current ZoomLevel.

Regards,
lapacho
Freshman
Freshman
 
Posts: 6
Joined: Sun Mar 28, 2010 5:02 am

Top

Return to Map Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests