Start a new topic

How to update a POI's label

How to update a POI's label


Hi,

assuming that jsonObject returns an object with a property poiObj and poiObj is a AR.GeoObject:

currToken = jsonObject;
var label = new AR.Label(currInfo.distance, 0.8*currInfo.scale, {offsetY : +0.7*currInfo.scale, offsetX: +1.3*currInfo.scale,
triggers: {
onClick:
createClickTrigger(currInfo.id)},
style : {textColor : '#FFFFFF'}});


 

With which code do I have to replace in order to update the label?

bye

      Christian

 

hi if you want to add the label to the currToken.poiObj  AR.GeoObject have a look in the API spec under AR.ARObject (base class of GeoObject)

Either use:

currToken.poiObj.drawables.cam = new Array(label); to replace all drawables, or:

currToken.poiObj.drawables.addCamDrawable(label) to add the label.

Hi Wolfgang,

thanks for the swift reply. This actually solved the problem. However, there is a strange behaviour and I'm nur sure if this is a Wikitude SDK bug or a bug in my app.

Currently, I trigger an update-label script every second (this is only for debugging - in the final version this script will probably be called every 20 - 30 seconds). This is the code I use to update the label:

var label = new AR.Label(currInfo.distance, 0.8*currInfo.scale, {offsetY : +0.7*currInfo.scale, offsetX: +1.3*currInfo.scale,
triggers: {
onClick:
createClickTrigger(currInfo.id)},
style : {textColor : '#FFFFFF'}});
var img = poiImages;

currToken.poiObj.drawables.cam = new Array(label, img);

 

Everything works fine for the first 60 - 90 calls. Then suddenly the label is not going to be displayed (the image itselft is still being drawn, only the label disappears).

Echoing label.text still produces correct results, i.e. the AR.label seems to be okay. Any suggestions?

Thanks

       Christian

You are running into resource problems as you are creating new labels each time the script runs. However there is an easy fix:

- call .destroy() on the old label that is no longer needed.

e.g

currToken.poiObj.drawables.cam.destroy();

Hi Wolfgang,

thanks a lot! That saved my day ;)

bye

    Christian
Login or Signup to post a comment