1

I'm getting some information from a server using fetch and using jQuery append to dinamically add the widgets to my page, but I need to know when the widget is done loading, there's any trigger that shows me that the widget is already loaded? here's my piece of code

  function drawLayers(sqlSource, style, ctrl, id_layer, widgetsObj, visibility){
    fetch(sqlSource)
    .then(response => response.json())
    .then(function(data){
    source[ctrl] = new carto.source.GeoJSON(data);
    vizLayer[ctrl] = new carto.Layer('layer', source[ctrl], style);
    vizLayer[ctrl].id = id_layer;

    layerBridge[ctrl] = new AsBridge.VLBridge({
      carto: carto,
      map: map,
      layer: vizLayer[ctrl],
      source: source[ctrl]
    });
    drawWidgets(widgetsObj, vizLayer[ctrl], layerBridge[ctrl]);
    vizLayer[ctrl].addTo(map, 'watername_ocean');
    if(!visibility){
      vizLayer[ctrl].hide();
    }



    layerBridge[ctrl].build();



 });
}




function drawWidgets(widgetsObj, vizLay, bridgeCtrl){
  for(var i = 0; i<widgetsObj.length;i++){
    if(vizLay.id == widgetsObj[i].source.id){
      if(widgetsObj[i].type == 'category'){
        $('.as-sidebar--right').append('<div class="as-box '+widgetsObj[i].source.id+'"><as-category-widget visible-categories="5" show-clear heading='+widgetsObj[i].title+'  id='+widgetsObj[i].options.column+'></as-category-widget></div>');
    bridgeCtrl.category('#'+widgetsObj[i].options.column, widgetsObj[i].options.column, {
      readOnly: false
    });
    vizmod = new carto.Viz('@widgets: viewportFeatures($'+widgetsObj[i].options.column+')');
    vizLay.blendToViz(vizmod);

    }

I need to use jquery to mod some properties from the widget after is loaded, I've tried to use the code below, just for an example, but it doesn't work

$('#'+widgetsObj[i].options.column).on('loaded', example_function);
2

You can change the properties of the widget right after the append call. For instance, you could change visibleCategories and it should work. If you need to read the properties back, you have to wait until the next tick.

From a VL <--> Airship perspective, the widget will update on every update event on the layer it's bridged to. You could listen to that event and then do whatever changes you require to the properties.

However, keep in mind that certain properties of the widget are updated by the bridge, so you changes might get overwritten on the next update event.

It might be interesting adding a callback that fires each time the widget is updated, I will open an issue for it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.