How to remove a layer from the map?

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

How to remove a layer from the map?

Postby shipinlou8 » Wed Jul 16, 2008 10:39 am

There are several layers on my map and I want to remove one of them
the code I wrote are as follows:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                 List<Overlay> layers = mOc.getOverlays();
  3.  
  4.                 Overlay theLayer=null;
  5.  
  6.                 for(int i=0;i<layers.size();i++) {
  7.  
  8.                         if(layers.get(i) instanceof DemoMyLayer){
  9.  
  10.                                 theLayer=layers.get(i);
  11.  
  12.                                 break;
  13.  
  14.                         }
  15.  
  16.                        
  17.  
  18.                 }
  19.  
  20.                 if(theLayer!=null)
  21.  
  22.                         layers.remove(theLayer);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


but the last line cause an exeption.
What should I do to remove an overlay?
shipinlou8
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Jul 14, 2008 2:19 am

Top

Postby plusminus » Wed Jul 16, 2008 2:16 pm

Hello shipinlou8,

the SDK-documentation says:
SDK-Documentation wrote:public List getOverlays()
Returns
* an unmodifiable list containing all overlays that have been added.


Maybe sth like this is what you are searching for:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.           List<Overlay> layers = mOc.getOverlays();
  2.  
  3.           Overlay theLayer=null;
  4.  
  5.           final int overlayCount = layers.size();
  6.  
  7.           for(int i=0;i<overlayCount; i++) {
  8.  
  9.                if(layers.get(i) instanceof DemoMyLayer){
  10.  
  11.                     mOc.deactivate(theLayer);
  12.  
  13.                     break;
  14.  
  15.                }
  16.  
  17.           }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 2 guests