Select to view content in your preferred language

How to add feature layer programatically with Popup enabled?

2066
1
Jump to solution
02-18-2016 10:17 AM
RamónVélez
Emerging Contributor

Hi,

  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.
define(['dojo/_base/array',
        'dojo/_base/lang',
        'esri/lang'
],
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);
            this.lstLayers.push(layer);
        },

        //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) {
                map.removeLayer(currLayer);           
            });
            
            this.lstLayers = []; 
        }
     };
});
       
//Example call to AddLayerWithName function
//Class code and module loading removed for brevity
//mapFromWAB comes from this.map in Widget.js
var flayer = new FeatureLayer("http://myFeatureServiceUrl");
LayerListHelper.AddLayerWithName(mapFromWAB, flayer, "My New Layer", 0); 
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Ramón,

   Here is your answer:

Enable Pop-up

View solution in original post

1 Reply
RobertScheitlin__GISP
MVP Emeritus

Ramón,

   Here is your answer:

Enable Pop-up