/query-widget

Widget Query personalizado para atender a uma demanda para um aplicativo específico no ArcGis Portal.

Primary LanguageJavaScript

Custom ArcGis Web AppBuilder Query Widget

Custom Query Widget developed to meet a specific requirement for an application in ArcGis Portal. When a search result is clicked, the layer related to the category of the result becomes visible.

Added Code:

  • Inside SingleQueryResult.js:

    _onResultItemClick: function (event) {
      const feature = event.target.closest('.jimu-table-row')?.feature;
      if (!feature) return;
    
      const categoria = feature.attributes?.CATEGORIA;
      if (!categoria) return;
    
      const layerNodes = this.layerStructure.getLayerNodes();
    
      for (const layer of layerNodes) {
        for (const subNode of layer.getSubNodes()) {
          if (subNode.title.toLowerCase().trim() === categoria.toLowerCase().trim()) {
            subNode.show();
          } else {
            subNode.hide();
          }
        }
      }
    },

    A função captura o clique e procura pelo '.jimu-table-row' mais próximo e atribui a categoria para a variável categoria. Depois, é realizado uma iteração para cada camada, e também, para cada subcamada. É verificado se a categoria é igual ao título da subcamada, se for, a camada é mostrada, senão é escondida. The function captures the click and searches for the closest '.jimu-table-row', assigning the category to the variable categoria. Then, it iterates over each layer and each sublayer. It checks if the category matches the sublayer title; if it does, the layer is shown; otherwise, it is hidden.


  • Inside _createQueryResultItem

    // ... Existing code
    html.place(trItem, this.resultsTbody);
    trItem.feature = feature;
    
    // Added code
    var tableItem = query('td', trItem)[0];
    on(tableItem, 'click', lang.hitch(this, function(event) {
      this._onResultItemClick(event);
    }))
    // End of added code
    // Rest of the function ...

    In this code, a click event listener is added to the 'td' elements inside trItem. When clicked, the function _onResultItemClick is executed.