Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I know its a little too late, but since i came up with a solution that helped me, i thought of sharing it so that it helps programmers in the future.. </p> <p>@hooked82 : the problem with doing just</p> <pre><code>overlays.remove(position) </code></pre> <p>is that its a list. so when you remove one item from the list, every item to the right of this item, in the list, is shifted one place to the left, which will eventually mess up your positions making it really tedious to keep a track of them all over time. </p> <p>During one of my projects, i faced the same issue. Since i was adding and removing overlays upon some updates, after a point of time, it was really difficult to keep a track of the overlay positions in the list. </p> <p>Here is what i did as a work around for the problem, and so far there have been no issues.</p> <p><strong>Step 1:</strong> create your custom Overlay Class</p> <pre><code>public class MyOverlay extends Overlay { private String overlayUUID; @Override public void draw(Canvas canvas, MapView mapView, boolean shadow) { -- do what you need to do here -- } public String getOverlayUUID() { return overlayUUID } } </code></pre> <p><strong>Step 2:</strong> in the MapClass where you handle the overlays. Please be sure that the mapOverlays list is a global list in the MapView class where you add all your mapOverlays</p> <pre><code> List&lt;Overlay&gt; mapOverlays = mapView.getOverlays(); public void removeChosenOverlay(String overlayUUID) { for(int i=0; i&lt;mapOverlays.size(); i++) { String className = mapOverlays.get(i).getClass().getSimpleName(); if(className.equals("MyOverlay")) { MyOverlay myOverlay = (MyOverlay) mapOverlays.get(i); if((myOverlay != null) &amp;&amp; (myOverlay.getOverlayUUID.equals(overlayUUID))) { mapOverlays.remove(i); mapView.invalidate() break; } } } } </code></pre> <p>With the above method, one can uniquely identify each overlay with a UUID (in my case it was a string, but you can custom create your UUID's in any format you wish to) and remove the corresponding overlay item successfully from the list of overlays, without having to worry about their relative positions in the list. </p> <p>I hope it helps others who face the same issues with uniquely identifying overlays.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload