AttributeTable crash when remove layer from the map by code, that was added by code...

2819
3
07-06-2015 01:36 PM
marceloctorres
Esri Contributor

We have developed a WAB Widget that add a FeatureLayer to the map by code. This layer is build using a featureCollection. Later, this FeatureLayer have to be removed to add another FeatureLayer with another featureCollection as source. After the first FeatureLayer have been removed from the map the AttributeTable widget crash. Are there some special steps to do before a FeatureLayer can be removed to the map without have a negative effect to the Attribute Table?

Thanks,

Marcelo

Marcelo César Torres
0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Marcelo,

  I add and remove feature layers using a Feature collection with out any issue in my eSearch widget. This is how I am doing it each time someone clears the search results in my widget:

      _removeAllOperatonalLayers: function(){

        var layers = this.operationalLayers;

        while(layers.length > 0){

          var layer = layers[0];

          if(layer){

            this.map.removeLayer(layer);

          }

          layers[0] = null;

          layers.splice(0,1);

        }

        this.operationalLayers = [];

      },

marceloctorres
Esri Contributor

We have an issue with AttributeTable Widget...this is my code:<

        callbackFeaturesEstadistica: function (featureLayer) {
            if (featureLayer.graphics.length > 0) {
                featureLayer.name = this._consulta.name;

                this.map.addLayer(featureLayer);
                featureLayer.show();
                featureLayer.redraw();
                this.publishData({
                    'target': 'AttributeTable',
                    'layer': featureLayer
                });

                this.map.graphicsLayerIds.forEach(lang.hitch(this, function (layerId) {
                    if (layerId == this._idLayerQuery) {
                        var lyr = this.map.getLayer(layerId);
                        this.map.removeLayer(lyr);
                    }
                }))
                this._idLayerQuery = featureLayer.id;
            }
            else {
                this._divMensaje.innerText = "La consulta no arrojo datos.";
                this.seleccionarDiv(this._divMensaje);
            }
        },

And this is the result:

Captura20150715.PNG

Thanks for your help!

Marcelo César Torres
0 Kudos
ZeZhengLi
Occasional Contributor

Marcelo,

    The layer parameter you published to AttributeTable must be an instance of `LayerInfo` not a featurelayer.

     1、import module ‘jimu/LayerInfos/LayerInfos’ to your module.

     2、call getInstance method

LayerInfos.getInstance(map, map.itemInfo).then(layerInfosObj){......}

     3、bind the 'layerInfosChanged' event

this.own(layerInfosObj.on(

            'layerInfosChanged',

            lang.hitch(this, this.onLayerInfosChanged)));

     4、get the layerInfo and then publish to AttributeTable

onLayerInfosChanged: function(layerInfo, changeType, layerInfoSelf) {

  this.publishData({

  target: 'AttributeTable',

  layer: layerInfoSelf

  });

}

     I think the code in "client\stemapp\widgets\LayerList\PopupMenuInfo.js line:260" can help you.

     This the code that how does LayerList widget open the AttributeTable.

_onTableItemClick: function(evt) {

      // new version, send layerInfo object.

      this._layerInfo.getLayerType().then(lang.hitch(this, function(layerType) {

        if (this._layerInfo._getLayerTypesOfSupportTable().indexOf(layerType) >= 0) {

          evt.layerListWidget.publishData({

            'target': 'AttributeTable',

            'layer': this._layerInfo

          });

        }

      }));

    },