Select to view content in your preferred language

Enable Pop-up

5808
3
Jump to solution
05-28-2015 02:45 PM
RickeyFight
MVP Regular Contributor

I am adding a layer when a widget loads.

I am trying to have popups enabled when it loads.

I cannot find the script to enable popup on load.

I hope this is an easy option.

1 Solution

Accepted Solutions
XiaodongWang
Esri Contributor

Rickey,

Try the code below:

     // require('jimu/LayerInfos/LayerInfos')

     // testCode funciton is in Windget's context;

      testCode: function() {

        var url = "http://sampleserver6.arcgisonline.com/arcgis/rest" +                        "/services/CommercialDamageAssessment/FeatureServer/0";

        var featureLayer = new FeatureLayer(url);

        this.map.addLayer(featureLayer);

        featureLayer.on('load', lang.hitch(this, function() {

          LayerInfos.getInstance(this.map, this.map.itemInfo).then(lang.hitch(this, function(layerInfos) {

            var featureLayerInfo = layerInfos.getLayerInfoById(featureLayer.id);

            featureLayerInfo.loadInfoTemplate().then(lang.hitch(this, function() {

              featureLayerInfo.enablePopup();

            }));

          }));

        }));

      },

LayerInfos is data structure of WAB that reflects the relationships of all operational layers of map. After add a layer to the map, you can get its 'LayerInfo' using layerId by layerInfos.getLayerInfoById(), and then using layerInfo to control popup(loadInfoTempalte and enable popup).

View solution in original post

3 Replies
StanMcShinsky
Frequent Contributor

​typically you configure and enable pop ups through AGOL web map. I am assuming you are adding this layer after the map is loaded?

-Stan

0 Kudos
RickeyFight
MVP Regular Contributor

Stan,

Yes I am using same concept as the local layer widget to load the layer.

0 Kudos
XiaodongWang
Esri Contributor

Rickey,

Try the code below:

     // require('jimu/LayerInfos/LayerInfos')

     // testCode funciton is in Windget's context;

      testCode: function() {

        var url = "http://sampleserver6.arcgisonline.com/arcgis/rest" +                        "/services/CommercialDamageAssessment/FeatureServer/0";

        var featureLayer = new FeatureLayer(url);

        this.map.addLayer(featureLayer);

        featureLayer.on('load', lang.hitch(this, function() {

          LayerInfos.getInstance(this.map, this.map.itemInfo).then(lang.hitch(this, function(layerInfos) {

            var featureLayerInfo = layerInfos.getLayerInfoById(featureLayer.id);

            featureLayerInfo.loadInfoTemplate().then(lang.hitch(this, function() {

              featureLayerInfo.enablePopup();

            }));

          }));

        }));

      },

LayerInfos is data structure of WAB that reflects the relationships of all operational layers of map. After add a layer to the map, you can get its 'LayerInfo' using layerId by layerInfos.getLayerInfoById(), and then using layerInfo to control popup(loadInfoTempalte and enable popup).