Search code examples
androidgoogle-maps-api-3itemizedoverlay

android google map onTap


i have a bunch of customized items with default marker.

after i'm loading all the markers, i'm using a service to update their Drawable photos. the new photos are 50 X 50.

everything works great, until i'm tapping a marker and my onTap alert box is activate. then my marker get back to original (small) size of the marker new photo.

this is my item:

                Bitmap bitmap = ((BitmapDrawable) picture).getBitmap();
                picture = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, 50, 50, true));
                picture.setBounds(0, 0, 50,50);
                marker.getItem(0).setMarker(picture);
                mapView.invalidate(); 

and the is my onTap:

   protected boolean onTap(int index) {
   OverlayItem item = mapOverlays.get(index);
   Dialog dialog = new Dialog(context);
   dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
   dialog.setContentView(R.layout.map_menu);
   dialog.setCanceledOnTouchOutside(true);
   TextView userName = (TextView)dialog.findViewById(R.id.map_menu_name);
   ImageView profilepicture = (ImageView)dialog.findViewById(R.id.map_menu_profile_picture);
   if (item.getMarker(0) == null)
       profilepicture.setImageDrawable(defaultMarker);
   else
       profilepicture.setImageDrawable(item.getMarker(0));

   userName.setText(item.getTitle());
   //dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
   dialog.show();

  return true;

}

one more thing, when i use the first loading of the map, the dummie marker is at a point. when it changes the marker, the marker moves a bit... i don't know why..

EDIT : Found a solution thanks to the answer bellow:

my new onTap method:

   @Override
  protected boolean onTap(int index) {
   OverlayItem item = mapOverlays.get(index);
   Dialog dialog = new Dialog(context);
   dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
   dialog.setContentView(R.layout.map_menu);
   dialog.setCanceledOnTouchOutside(true);
   TextView userName = (TextView)dialog.findViewById(R.id.map_menu_name);
   ImageView profilePicture = (ImageView)dialog.findViewById(R.id.map_menu_profile_picture);
   if (item.getMarker(0) == null)
     profilePicture.setImageDrawable(defaultMarker);
   else
   {
       Bitmap bitmap = ((BitmapDrawable) item.getMarker(0)).getBitmap();
       Drawable profile = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, 50, 50, true));
       profilePicture.setImageDrawable(profile);
   }

   userName.setText(item.getTitle());
   //dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
   dialog.show();

  return true;

}

Solution

  • I'm guessing you need to create the Drawable again when setting the Drawable for the ImageView - otherwise the ImageView and the marker share the drawable and when the ImageView is layed out both get resized.