Start a new topic

Remove RADAR Circle

Remove RADAR Circle


Hi
I don't speak very well english, so i apologize if i say something wrong.
I am looking how to remove circles of the radar in my architectView.
Now, i remove the geo objects by the command "jsonObject.poiObj.locations.destroy();", but it does not remove the circles on the radar of my architectView.

What can i do to remove the objects of the radar?

 

 

Thanks Wolfgang

I am sure that what you said is right, but i can not use in my code.

I am using the example of wikitude skd to do that, i will paste my code and maybe you can help me a litelle bit more.

Thanks and I hope you can help me.

 

My code:

function newData(jsonData){

  if(jsonObject != null){
   for(var i = 0; i < jsonObject.length; i++)
                 {
    jsonObject.poiObj.remove();
   }
  }   

                jsonObject = jsonData;
                document.getElementById("statusElement").innerHTML='Cargando Puntos De Interes';
   
               
                for(var i = 0; i < jsonObject.length; i++)
                {
                    var poidrawables = new Array();
                    var label = new AR.Label(jsonObject.name,1.0, {offsetY : -1.5,
                                             triggers: {
                                             onClick:
                                             createClickTrigger(jsonObject.id)},
                                             style : {textColor : '#FFC100',backgroundColor : '#FFFFFF80'}});
                   
                    jsonObject.arLabel = label;
                   
                    var poiImage;

                    if(jsonObject.type == 1)
                    {
                        poiImage = AcademiaImage;
                    }
                    else if(jsonObject.type == 2)
                    {
                        poiImage = AlimentacionImage;
                    }
                    else if(jsonObject.type == 3)
                    {
                        poiImage = DeporteImage;
                    }
                    else if(jsonObject.type == 4)
                    {
                        poiImage = EventoImage;
                    }
        else if(jsonObject.type == 5)
                    {
                        poiImage = TallerImage;
                    }
     else if(jsonObject.type == 6)
                    {
                        poiImage = LaboratorioImage;
                    }
        else if(jsonObject.type == 7)
                    {
                        poiImage = OtrosImage;
                    }
                   
     
                    var img = new AR.ImageDrawable(poiImage, 2.0,
                                                   {triggers: {
                                                   onClick:
                                                   createClickTrigger(jsonObject.id)}}
                                                   );
                   
                    jsonObject.animation = createOnClickAnimation(img);
                    jsonObject.img = img;
     
      var radarCircle = new AR.Circle(0.05, {style: {fillColor: '#83ff7b'}});
                   
                    poidrawables.push(label);
                    poidrawables.push(img);  
                    geoLoc = new AR.GeoLocation(jsonObject.Point.latitude,jsonObject.Point.longitude,jsonObject

.Point.altitude);
      var obj = new AR.GeoObject(geoLoc, {drawables: {cam: poidrawables, radar: radarCircle}});
  

      obj.remove = function() {
    radarCircle.destroy();
    img.destroy();
    geoLoc.destroy();
   obj.destroy();
       };

                    jsonObject.poiObj = obj;
   
                }
               
                document.getElementById("statusElement").innerHTML='JaverianAR'; 
               
            }

 

i get and error like : "destroy can not be used in the object" or something like that.

You will need to destroy the whole object including it's drawables. Currently you are just destroying the location.

Here is what you can do:

At creation of the geoObject attach a new function the GeoObject that destorys all objects. e.g.: 

var radarCircle = new AR.Cirlce(...);
var imgDrawable = new AR.ImageDrawable(...);
var loc = new AR.GeoLocation(..);
var obj = new AR.GeoObject(loc, {drawalbes: {cam: imgDrawable, radar: radarCircle}});

obj.remove = function() {
radarCircle.destroy();
imgDrawable.destroy();
loc.destroy();
obj.destroy();
};

 

this is a bit tricky in javascript. I will try to shortly explain the problem and solution, but you might want to read up on the topic.

variables in javascript always have a function scope

when you create the remove function only a reference to the variables (radarCircle, img, geoloc, ...) is used. thus after the for loop finishes the varialbes will point to the last element you created.

Now if you call the remove function it will actually try to destroy the last element multiple times. Thus resulting in the error when it wants to destroy the same object a second time.

 

Solution:

create a separate function that encapsulates the creation of a poi or read up on closures and on how to use them.
Login or Signup to post a comment