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.
Solved! Go to Solution.
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).
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
Stan,
Yes I am using same concept as the local layer widget to load the layer.
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).