AnsweredAssumed Answered

How to add feature layer programatically with Popup enabled?

Question asked by rvelezgmtgis-esridist Employee on Feb 18, 2016
Latest reply on Feb 18, 2016 by rscheitlin


  I'm using WAB 1.3 and when I add a FeatureLayer programatically to the map it shows up in

the LayerList  Widget with the Popup disabled by default?

Is there a way to enable the Popup programatically?


Below is a snippet of the function I'm using to add the layer to the LayerList Widget with a name

of my choice.

//Filename: LayerListHelper.js 
//Helper static class used for adding a layer in the LayerListWidget
//and renaming it after adding it to the map.
function (array, lang, esriLang) {
    return {
        lstLayers: [],
        //Adds a layer in the map and Layer List Widget and renames it to 
        //the given name.
        //@param('esri/Map')map - The map in which the copied layer will be added
        //@param('esri/layers/Layer')layer - The layer to be renamed
        //@param(string)name - The new name of the layers
        //@param(int)positionIndex? - (Optional)The position in which the layer 
        //will be added to the map, defaults to 0
        AddLayerWithNewName: function(map, layer, name, positionIndex) {
            lang.mixin(layer, {label: name});
            var index = positionIndex;
            if (!(esriLang.isDefined(positionIndex))) {
                index = 0;    
            map.addLayer(layer, index);

        //Removes the layers added by using the method AddLayerWithName
        //@param('esri/Map')map - The map from which the added layers will be removed
        RemoveAddedLayers: function(map) {
            array.forEach(this.lstLayers, function(currLayer) {
            this.lstLayers = []; 
//Example call to AddLayerWithName function
//Class code and module loading removed for brevity
//mapFromWAB comes from in Widget.js
var flayer = new FeatureLayer("http://myFeatureServiceUrl");
LayerListHelper.AddLayerWithName(mapFromWAB, flayer, "My New Layer", 0);