How to delete the itemizedOverlay on map?

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

How to delete the itemizedOverlay on map?

Postby rollin_ya » Sat Jul 04, 2009 9:04 am

I have extended Itemizeoverlay, and I hope when I tap a overlayItem, it will disappear on the map.
It not worked perfectly,sometimes there was a error occured when I click the overlayItem.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class myItemizedOverlay extends ItemizedOverlay<OverlayItem>
  3.  
  4. {
  5.  
  6.         private MapActivity mMapActivity;
  7.  
  8.         private MapView mMapView ;
  9.  
  10.         private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
  11.  
  12.         public myItemizedOverlay(MapActivity mapActivity,MapView mapView ,Drawable defaultMarker)
  13.  
  14.         {
  15.  
  16.                 super(boundCenterBottom(defaultMarker));
  17.  
  18.                 mMapActivity = mapActivity;
  19.  
  20.                 mMapView = mapView  ;
  21.  
  22.                
  23.  
  24.         }
  25.  
  26.         public void addOverlay (OverlayItem overlay)
  27.  
  28.        {
  29.  
  30.             mOverlays.add(overlay);
  31.  
  32.             populate();
  33.  
  34.         }
  35.  
  36.        
  37.  
  38.         public void deleteOverlay (int index)
  39.  
  40.        {
  41.  
  42.             mOverlays.remove(index);
  43.  
  44.             populate();
  45.  
  46.         }
  47.  
  48.        public void deleteOverlay (OverlayItem overlay)
  49.  
  50.        {
  51.  
  52.             mOverlays.remove(overlay);
  53.  
  54.             populate();
  55.  
  56.         }
  57.  
  58.        
  59.  
  60.         @Override
  61.  
  62.         protected OverlayItem createItem(int i)
  63.  
  64.        {
  65.  
  66.           return mOverlays.get(i);         
  67.  
  68.         }
  69.  
  70.  
  71.  
  72.         @Override
  73.  
  74.         public int size() {
  75.  
  76.           return mOverlays.size();
  77.  
  78.         }
  79.  
  80.  
  81.  
  82.         @Override
  83.  
  84.         public boolean onTap(int index)
  85.  
  86.         {
  87.  
  88.               deleteOverlay(getItem(index)) ;
  89.  
  90.               mMapView.invalidate() ;
  91.  
  92.               return super.onTap(index) ;
  93.  
  94.         }
  95.  
  96. }
  97.  
  98.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


the error message:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. 07-04 06:46:54.332: ERROR/AndroidRuntime(23745): Uncaught handler: thread main exiting due to uncaught exception
  3.  
  4. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745): java.lang.ArrayIndexOutOfBoundsException
  5.  
  6. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at com.google.android.maps.ItemizedOverlay.maskHelper(ItemizedOverlay.java:562)
  7.  
  8. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at com.google.android.maps.ItemizedOverlay.setFocus(ItemizedOverlay.java:365)
  9.  
  10. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at com.google.android.maps.ItemizedOverlay.focus(ItemizedOverlay.java:539)
  11.  
  12. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:455)
  13.  
  14. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
  15.  
  16. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:346)
  17.  
  18. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at android.view.GestureDetector.onTouchEvent(GestureDetector.java:503)
  19.  
  20. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at com.google.android.maps.MapView.onTouchEvent(MapView.java:623)
  21.  
  22. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at android.view.View.dispatchTouchEvent(View.java:3368)
  23.  
  24. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:831)
  25.  
  26. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
  27.  
  28. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
  29.  
  30. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
  31.  
  32. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
  33.  
  34. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1707)
  35.  
  36. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1197)
  37.  
  38. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at android.app.Activity.dispatchTouchEvent(Activity.java:1993)
  39.  
  40. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1691)
  41.  
  42. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1525)
  43.  
  44. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at android.os.Handler.dispatchMessage(Handler.java:99)
  45.  
  46. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at android.os.Looper.loop(Looper.java:123)
  47.  
  48. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at android.app.ActivityThread.main(ActivityThread.java:3948)
  49.  
  50. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at java.lang.reflect.Method.invokeNative(Native Method)
  51.  
  52. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at java.lang.reflect.Method.invoke(Method.java:521)
  53.  
  54. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
  55.  
  56. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
  57.  
  58. 07-04 06:46:54.352: ERROR/AndroidRuntime(23745):     at dalvik.system.NativeStart.main(Native Method)
  59.  
  60.  
  61.  
  62.  
Parsed in 0.043 seconds, using GeSHi 1.0.8.4
rollin_ya
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Jul 04, 2009 8:43 am

Top

Postby aspekt9 » Thu Jul 09, 2009 5:43 pm

I'm having the same problem, it's because when you remove an item from the ArrayList, it shrinks the list but the indexes of the points stay the same, thus you get an index which is equal to the size of the array. I'm not sure how to fix this?
aspekt9
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Feb 24, 2009 5:13 am

Postby Christoph » Thu Jul 16, 2009 4:41 am

Hi Androids :-)

This post will help you:
http://groups.google.com/group/android- ... 14e34714c3

summary:

in addition to
populate();
call -> setLastFocusedIndex(-1);
User avatar
Christoph
Developer
Developer
 
Posts: 28
Joined: Thu Jul 02, 2009 3:34 am
Location: Bonn, Germany

Postby arvind » Fri Jul 17, 2009 6:38 pm

Thanks Mr Christoph that was really useful.....
I wanted to ask you.... is there anyway to draw information windows on the itemizedoverlay ....without writing code for drawing the marker...I think if we override the draw fundtion then we have to draw maker also....
I wants to open an Information window on the onTap event...
hope you understands my question.......

Regards
Arvind
arvind
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jun 23, 2009 4:44 am
Location: Mumbai,India

Postby ioscas » Thu Sep 03, 2009 1:55 pm

hey, did u solve the following problem? show a info view without a marker..

arvind wrote:Thanks Mr Christoph that was really useful.....
I wanted to ask you.... is there anyway to draw information windows on the itemizedoverlay ....without writing code for drawing the marker...I think if we override the draw fundtion then we have to draw maker also....
I wants to open an Information window on the onTap event...
hope you understands my question.......

Regards
Arvind
ioscas
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Sep 03, 2009 10:35 am

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 7 guests