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.
- Import the jimu/LayerInfos/LayerInfos module.
- 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 } }
- If the layer has already been added to the map, use the instance of LayerInfos to get layerInfo by layer id.
We'd love to hear your feedback
Thank you for helping us make ArcGIS Developers even better!