Adding and Removing the same POIs

So we have the situation where we will want to add and remove the same set of POIs on the map at any given time.  One issue we are having with that is a problem with the AS3 function on the map called removePOI(poi).  The function will remove it visually from the map, but the map still has the object reference in it’s memory.  So if try to add the POI once it has been added then removed, the map will add it with the same key, as it should, but you will get an error if you try to remove it.  I have not seen any fixes in the unsupported version for Flex either. 

So to clerify: 
myMap.removeShape(myMap.getByKey(shapeId));
     AND
myMap.removePoi(Poi(myMap.getByKey(shapeId)));

will only visually remove the POI object from the map, not relationally (physically) 

However, the function myMap.removeAllPois() will remove all of the POIs from the map in every way.  The map no longer has a reference to them at all.  That works out well, if you can remove all of the POIs.  The problem comes in when you only need to remove a couple. 

WORK AROUND:

if(showTypePoi())
{
    
if(myMap.getByKey(myPoi.id) == null
)//if it is not on the map put it on
          addPoi(myPoi);
     else//map still has reference just show the object
         
Poi(myMap.getByKey(myPoi.id)).draw();
}

else//remove it from the map
{
     myMap.removeShape(myMap.getByKey(myPoi.id));
}

 

3 Responses to this post.

  1. Posted by mqguru on January 12, 2009 at 5:36 pm

    I sent this into MapQuest before I posted it, and I was told to follow some steps that are used in another app. Here is another work around:

    var shpC:ShapeCollection = new ShapeCollection();
    shpC.add(myMap.getByKey(myPoi.id))
    myMap.removeShapeCollection(shpC);

    That is said to work, I have not personally tested it yet, but it does seem to work in their code. I would personally like to see the shape remove when I call the removeShape() function. If i want to hide it, I should be able to set the visibility of the item.

    Reply

  2. Posted by mqguru on January 12, 2009 at 9:02 pm

    Another suggestion that was made by the MapQuest team is the following

    You can remove individual pois from the collection and they will be removed from the map. Once the poi is added as part of a collection, the poi can not be removed indivually. For example…

    private var bc:int = 0;
    private function breakIt():void{
    var sc:ShapeCollection = myMap.getShapeCollections()[0];
    sc.remove(sc.get(bc++)); // remove from collection

    Reply

  3. Posted by mqguru on January 19, 2009 at 2:18 pm

    For a quick removal of all pois, do not use the removeAllPois() function, use the following:

    var sc:ShapeCollection = myMap.getShapeCollections()[0];
    sc.removeAll();

    the removeAllPois function will just remove them at the view level, they will come back when you zoom in and out.

    Reply

Respond to this post