Send a layer to the Attribute Table widget

The following steps explain how to send a layer from your widget to the Attribute Table widget. Since the attribute table only displays layers in the map, make sure to add the layer to the map.

  1. Import the jimu/LayerInfos/LayerInfos module.
  2. Get the instance of LayerInfos, and bind the layerInfosChanged event.
    LayerInfos.getInstance(map, map.itemInfo).then(lang.hitch(this, function(layerInfosObj) {
      this.own(layerInfosObj.on(
        'layerInfosChanged',
        lang.hitch(this, this.onLayerInfosChanged)));
    }));
    • If the layer has already been added to the map, use the instance of LayerInfos to get layerInfo by layer id.
      var layerInfo = this.layerInfosObj.getLayerInfoById(fLayer.id);
      this.publishData({
          'target': 'AttributeTable',
          'layer': layerInfoSelf
      });
    • Otherwise, add a new layer to the map, get the new layerInfo from the onLayerInfosChanged function, and publish it to the attribute table.
      map.addLayer(fLayer);
      
      onLayerInfosChanged: function(layerInfo, changeType, layerInfoSelf) {
        if (!layerInfoSelf || !layerInfo) {
          return;
        }
        if ('added' === changeType) {
          layerInfoSelf.getSupportTableInfo().then(lang.hitch(this, function(supportTableInfo) {
            if (supportTableInfo.isSupportedLayer) {
              this.publishData({
              'target': 'AttributeTable',
              'layer': layerInfoSelf
              });
            }
          }));
        } else if ('removed' === changeType) {
          // do something
        }
      }

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.