Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Android: Remove specific point from ItemizedOverlay

    So I built an app on Android which uses a map and ItemizedOverlay to display points/markers on it.
    Code:
    OverlayItem overlayItem = new OverlayItem(theGeoPoint, title, description);
    itemizedOverlay.addOverlay(overlayItem);
    mapOverlays.add(itemizedOverlay);
    Is there a way to remove a specific point from the itemizedOverlay?

    Example, say I've added lots of points at different latitudes/longitudes and I wish to remove a point at a specific latitude: 32.3121212 and specific longitude: 33.1230912, which was added earlier.

    How can I remove JUST that point??

    I really need this so I hope someone can help.

    Thanks.

    Full story scenario (in case you have a different idea on how to solve this): Adding events to a map that are caught from a database. Now when events are deleted from the database, I wish to sync the map and remove just those which were deleted. (please don't suggest I re-download all points excluding the deleted ones even though I've thought of that but it isn't an option concerning what I want to do. )

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Haven't a clue about these classes since I've never done android development, but you need to indicate what this itemizedOverlay and mapOverlays datatypes are.
    The docs I found here: https://developers.google.com/maps/d...oid/reference/ do not indicate that even an .addOverlay is available on any of these classes or interfaces.

  • #3
    New to the CF scene
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is the code of the MapOverlay
    Code:
    	class MapOverlay extends Overlay
    	{
    	  private GeoPoint pointToDraw;
    	
    	  public void setPointToDraw(GeoPoint point) {
    	    pointToDraw = point;
    	  }
    	
    	  public GeoPoint getPointToDraw() {
    	    return pointToDraw;
    	  }
    	  
    	  @Override
    	  public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
    	    super.draw(canvas, mapView, shadow);           
    	
    	    // convert point to pixels
    	    Point screenPts = new Point();
    	    mapView.getProjection().toPixels(pointToDraw, screenPts);
    	
    	    // add marker
    	    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.marker);
    	    canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 24, null);    
    	    return true;
    	  }
    	}
    and this is the code of the itemizedOverlay which is a MyItemizedOverlay type:

    Code:
    public class MyItemizedOverlay extends BalloonItemizedOverlay<OverlayItem>
    {
     private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
     private Context mContext;
     
     Context mContext2;
    
     AlertDialog.Builder dialog;
         AlertDialog alert;
    
     
     public MyItemizedOverlay(Drawable defaultMarker, MapView mapView)
     {
     super(boundCenterBottom(defaultMarker), mapView);
     mContext = mapView.getContext();
    
     populate();
     }
    
     public void addOverlay(OverlayItem overlay)
     {
     mOverlays.add(overlay);
     populate();
     }
     @Override
     protected OverlayItem createItem(int i)
     {
     return mOverlays.get(i);
     }
     @Override
     public int size()
     {
     return mOverlays.size();
     }
    	
    public void doPopulate(){
    	    populate();
    	    setLastFocusedIndex(-1);
    }
    
    	 public void removeOverlay(MyItemizedOverlay itemizedOverlay2)
    	 {
    	 mOverlays.remove(itemizedOverlay2);
    	 setLastFocusedIndex(-1);
    	 populate();
    	 }
    	 public void clear() {
    		 mOverlays.clear();
    	 }
    Last edited by bubbly; 05-18-2012 at 10:03 AM.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    It looks to me that you have the ability to remove MyItemizedOverlay objects from your MyItemizedOverlay class.
    There's a discrepancy here though, but not necessarily an error. You add objects to your list of type OverlayItem, but you remove items that are of type MyItemizedOverlay. I don't know what BaloonItemizedOverlay is either, but given that its generic it would indicate that its a collection of OverlayItem instead of being OverlayItem (although that may also not be the case especially with a chain of command style pattern so it may simply be a decorated type).
    Needless to say, I think a lot of the weight falls to the method populate() in the BalloonItemizedOverlay method, which appears to be called on any changes occurring. Guessing it would likely take care of the drawing itself. If that assumption is correct then once you can get the removeOverlay to work (assuming it doesn't with its current signature), then it may be as simple as changing the datatype there.

    I'm not sure how many mobile developers are on these forums at all. You may need to go to android's forums for the use of these types of classes.

  • #5
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,929
    Thanks
    46
    Thanked 203 Times in 202 Posts
    I don't think it is an android thing or even a custom class thing... could be wrong- but here is my take on it...
    you are essentially saying this
    I have a 'list of stuff' ... I am doing things with this 'list of stuff', and at some point i would like the ability to remove things from this 'list of stuff'.
    i have no clue how your list is set up, but if you are actively using it in a loop, you can't remove it from there or it would mess up the loop.
    so... pardon the C#/Java hybrid
    Code:
    public class Demo extends Activity{
    @Override
       public void onCreate(Bundle savedinstancestate){
          super.onCreate(savedinstancestate);
          setContentView(R.layout.main);
    
          // and now you have your list
          List<OverlayItem> _overlaylist = new List<OverlatItem>();
          // then you fill your list
          fillList();
          // then loops
          foreach(OverlayItem _o in _overlaylist)
          {
               if(something == something)
                  _overlaylist.Remove(_o);
           }
           // or...
           for(int i=0; i < _overlaylist.length; i++)
           {
                if(something == something)
                  _overlaylist.Remove.indexof(i);
           }
         
        }
    
        private void fillList(){...};
    that won't work... I don't think it would compile, and if it did you are at high risk of throwing an error at runtime. you need to change up the logic to maybe something like...

    Code:
    public class Demo extends Activity{
    @Override
      
       List<OverlayItem> _overlaylist = new List<OverlatItem>();
       // note that the list is now a global variable
    
       public void onCreate(Bundle savedinstancestate){
          super.onCreate(savedinstancestate);
          setContentView(R.layout.main);
    
          // then you fill your list
          fillList();
          while(!something)
          {
             scanlist();
             Thread.sleep(2000);
          }
        }
        
        private void scanlist()
        {
             // note: you can do this in the 'main' void but I think it's best to break things
             // into functions- also once you end this function your temp list will be disposed of
             List<OverlayItem> tmpList = new List<OverlayItem>();
             foreach(OverlatItem _o in _overlaylist)
             {
                if(something == something)
                  tmpList.Add(_o);
             }
             // now that you are out of the list loop...
             foreach(OverlayItem _o in tmpList)
             {
                _overlayitemlist.Remove(_o);
             }
        }
    
        private void fillList(){...};
    does that make any sense or help?

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •