xitingTick / osmdroid

Automatically exported from code.google.com/p/osmdroid
0 stars 0 forks source link

ScaleBarOverlay not fixed at certain position when zoom in and zoom out #425

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Add a ScaleBarOverlay on map
2. when zoom in and zoom out its also moving
3. No fixed at certain position even setting offset.

What is the expected output? What do you see instead?
 Should be fixed at ceratin position where we want

What version of the product are you using? On what operating system?
4.0.3
android:hardwareAccelerated="false"

Please provide any additional information below.

Original issue reported on code.google.com by min2bhan...@gmail.com on 3 May 2013 at 9:35

GoogleCodeExporter commented 8 years ago
Some how i managed to do that I have made transparent the default sclaebar 
overlay and using my own for that..

public class MyScaleBarOverlay extends ScaleBarOverlay {

   private static final String TAG      = MyScaleBarOverlay.class.getSimpleName();
   private TextView            scaleDistance;
   boolean                     imperial = false;
   boolean                     nautical = false;
   private ResourceProxy       resourceProxy;

   public MyScaleBarOverlay(Context arg0, ResourceProxy resourceProxy, TextView scaleDistance) {
      super(arg0, resourceProxy);
      this.resourceProxy = resourceProxy;
      this.scaleDistance = scaleDistance;
      Paint paint = new Paint();
      paint.setARGB(1, 255, 255, 255);
      setBarPaint(paint);
      setTextPaint(paint);
   }

   @Override
   public void setBarPaint(Paint pBarPaint) {
      Paint paint = new Paint();
      paint.setARGB(1, 255, 255, 255);
      super.setBarPaint(paint);
   }

   @Override
   public void setTextPaint(Paint pTextPaint) {
      Paint paint = new Paint();
      paint.setARGB(1, 255, 255, 255);
      super.setTextPaint(paint);
   }

   @Override
   protected String scaleBarLengthText(int meters, boolean imperial, boolean nautical) {
      Log.e(TAG, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + meters);
      if (this.imperial) {
         if (meters >= METERS_PER_STATUTE_MILE * 5) {
            String string = resourceProxy.getString(ResourceProxy.string.format_distance_miles,
                     (int) (meters / METERS_PER_STATUTE_MILE));
            scaleDistance.setText(string);
            return string;

         } else if (meters >= METERS_PER_STATUTE_MILE / 5) {
            String string = resourceProxy.getString(ResourceProxy.string.format_distance_miles,
                     ((int) (meters / (METERS_PER_STATUTE_MILE / 10.0))) / 10.0);
            scaleDistance.setText(string);
            return string;
         } else {
            String string = resourceProxy.getString(ResourceProxy.string.format_distance_feet, (int) (meters * FEET_PER_METER));
            scaleDistance.setText(string);
            return string;
         }
      } else if (this.nautical) {
         if (meters >= METERS_PER_NAUTICAL_MILE * 5) {
            String string = resourceProxy.getString(ResourceProxy.string.format_distance_nautical_miles,
                     ((int) (meters / METERS_PER_NAUTICAL_MILE)));
            scaleDistance.setText(string);
            return string;
         } else if (meters >= METERS_PER_NAUTICAL_MILE / 5) {
            String string = resourceProxy.getString(ResourceProxy.string.format_distance_nautical_miles,
                     (((int) (meters / (METERS_PER_NAUTICAL_MILE / 10.0))) / 10.0));
            scaleDistance.setText(string);
            return string;
         } else {
            String string = resourceProxy.getString(ResourceProxy.string.format_distance_feet, ((int) (meters * FEET_PER_METER)));
            scaleDistance.setText(string);
            return string;
         }
      } else {
         if (meters >= 1000 * 5) {
            String string = resourceProxy.getString(ResourceProxy.string.format_distance_kilometers, (meters / 1000));
            scaleDistance.setText(string);
            return string;
         } else if (meters >= 1000 / 5) {
            String string = resourceProxy.getString(ResourceProxy.string.format_distance_kilometers, (int) (meters / 100.0) / 10.0);
            scaleDistance.setText(string);
            return string;
         } else {
            String string = resourceProxy.getString(ResourceProxy.string.format_distance_meters, meters);
            scaleDistance.setText(string);
            return string;
         }
      }

   }

}

Original comment by min2bhan...@gmail.com on 3 May 2013 at 9:50

GoogleCodeExporter commented 8 years ago
The zoom-in/out animations animate the entire view and that includes anything 
drawn to the screen - we currently have no control over that. If you notice, 
when you pinch zoom in/out the scale bar (and compass) do not move because we 
handle animation differently there. Perhaps we could drop the android view 
animations and use the canvas matrix manipulation we do for the pinch zoom but 
at this point there is no solution. I don't understand what the code you posted 
is for.

Original comment by kurtzm...@gmail.com on 3 May 2013 at 12:45

GoogleCodeExporter commented 8 years ago
See issue 248.

Original comment by kurtzm...@gmail.com on 3 May 2013 at 1:29

GoogleCodeExporter commented 8 years ago
See issue 453.

Original comment by kurtzm...@gmail.com on 25 Jul 2013 at 10:16

GoogleCodeExporter commented 8 years ago
A working patch has been posted to issue 453. However it looks like the 
ScaleBarOverlay turns itself off when zooming because the scale will be 
incorrect while scaling:

    // If map view is animating, don't update, scale will be wrong.
    if (mapView.isAnimating()) {
        return;
    }

More work would be needed to get it to produce correct values when scaling. We 
could extract the scaling value from the canvas matrix, or we could implement a 
getZoomLevel() that returns a float value.

Original comment by kurtzm...@gmail.com on 6 Aug 2013 at 7:14