AnsweredAssumed Answered

How to turn on label after using query widget

Question asked by tuannguyen_rti on May 14, 2018
Latest reply on May 15, 2018 by rscheitlin

I want to show label for feature points after a query is executed using the Query Widget. 

For the query widget, I edited for following code in the widget.js file: 

 

//create a FeatureLayer
_createNewResultLayer: function(currentAttrs, queryName){
var resultLayer = null;
var renderer = null;
var taskIndex = currentAttrs.queryTr.taskIndex;

var layerInfo = lang.clone(currentAttrs.layerInfo);

//override layerInfo
layerInfo.name = queryName;
//ImageServiceLayer doesn't have drawingInfo
if (!layerInfo.drawingInfo) {
layerInfo.drawingInfo = {
"showLabels":true
};
}

layerInfo.drawingInfo.transparency = 0;
layerInfo.minScale = 0;
layerInfo.maxScale = 0;
layerInfo.effectiveMinScale = 0;
layerInfo.effectiveMaxScale = 0;
layerInfo.defaultVisibility = true;
delete layerInfo.extent;

//only keep necessary fields
var singleQueryLoader = new SingleQueryLoader(this.map, currentAttrs);
var necessaryFieldNames = singleQueryLoader.getOutputFields();
layerInfo.fields = array.filter(layerInfo.fields, lang.hitch(this, function(fieldInfo) {
return necessaryFieldNames.indexOf(fieldInfo.name) >= 0;
}));
var featureCollection = {
layerDefinition: layerInfo,
featureSet: null
};

//For now, we should not add the FeatureLayer into map.
resultLayer = new FeatureLayer(featureCollection,{
showLabels: true
});


// resultLayer.keepResultsOnMapAfterCloseWidget = currentAttrs.config.keepResultsOnMapAfterCloseWidget;
//set taskIndex for resutlLayer
resultLayer._queryWidgetTaskIndex = taskIndex;
//set popupTemplate
var popupInfo = lang.clone(currentAttrs.config.popupInfo1);
var popupTemplate = new PopupTemplate(popupInfo);
console.log(popupInfo);
if(popupInfo.showAttachments){
var url = currentAttrs.config.url;
var objectIdField = currentAttrs.config.objectIdField;
queryUtils.overridePopupTemplateMethodGetAttachments(popupTemplate, url, objectIdField);
}
resultLayer.setInfoTemplate(popupTemplate);


var labelingInfo= lang.clone(currentAttrs.config.labelingInfo1);
console.log(labelingInfo)
var labelClass = new LabelClass(labelingInfo);

resultLayer.labelsVisible = true;
resultLayer.labelingInfo = [labelClass];
resultLayer.setLabelingInfo([labelClass]);


currentAttrs.query.resultLayer = resultLayer;

Outcomes