Start a new topic

Updating Markers and Corresponding AR.GeoLocation Objects

Hi,

I'm developing an iOS app with 2 screens:

  1. List view for all POIs
  2. AR (Wikitude) view for all POIs
I call an API to fetch data for the AR POIs every time the AR (Wikitude) screen is loaded. On fetching the list I use the following code to show them on the AR (camera) view:

  

let jsonData = try encoder.encode(arObject)
if let jsonString = String(data: jsonData, encoding: .utf8) {
    var arParam = String()
    arParam = String(format:"World.loadPoisFromJsonData(%@)",jsonString)
    DispatchQueue.main.async {
        self.architectView.callJavaScript(arParam)
        self.hideLoader()
    }
}

  And in the World.loadPoisFromJsonData(jsonData) method I always set the World.markerList = [] and then iterate over the new data and create new markers as in the example code.


However I can see that each time this code runs new set of Markers are generated in the view and the old ones are not removed this leads to steady increase in the memory used by the app leading to ultimately freezes the app itself. Please guide me as to how:

  1. I can remove all existing POIs and plot fresh new ones
  2. Update existing POIs if data is updated in any case

Wikitude SDK: 8.2.0 (Javascript SDK)
iOS version: 11 (iPhone 6)
Code used from example folder: 10_BrowsingPois_3_LimitingRange


Hi!


This post deals with a similar topic.

You have to trigger the .destroy()-function to clean the memory. Also consider recycling existing POI drawables by updating the label text and just replace the image representation (ImageDrawable).


Hope this helps.


Best regards,
Andi



Hi guys, I'm from the same team.

The above link to updating the label text was quite helpful. Referring to it I found the following documentation:

I followed it when updating drawables as needed on data update by the following code:

 

// Destroy and remove existing drawables
markerObject.drawables.cam[index].destroy();
markerObject.drawables.removeCamDrawable(index);

// Add the new drawables
markerObject.drawables.addCamDrawable(updatedDrawable, index);

 It didn't work quite as expected as the new drawables were not being added to the specified position. I debugged the issue and into Architect.js itself and found a issue in the implementation where the provided index is directly checked in a condition statement and if provide with 0 coerces it to be a falsy value. The issue can be found here:

  

__addDrawable: function(a,b,c,d) {
  if(b==_PROPERTY_VALIDATOR.validate("drawable,b,{type:_PROPERTY_VALIDATOR.TYPE.ARRAY_OR_PROPERTY,ofType:d}, _PROPERTY_VALIDATOR.RULE.CAN_BE_EMPTY),c) {
    ...
  }
  ...
}

  variable 'c' in above code is the index at which to insert the new drawable and the condition fails if it's value is 0. The condition should instead be:

 

__addDrawable: function(a,b,c,d) {
  if(b==_PROPERTY_VALIDATOR.validate("drawable,b,{type:_PROPERTY_VALIDATOR.TYPE.ARRAY_OR_PROPERTY,ofType:d}, _PROPERTY_VALIDATOR.RULE.CAN_BE_EMPTY),c!=undefined) {
    ...
  }
  ...
}

 

Best Regards,

Huzaifa

Login or Signup to post a comment