Select to view content in your preferred language

QueryTask and IdentifyTask replacement in Arcgis version 4.27

471
1
07-13-2023 06:51 PM
samitalebi
Emerging Contributor

I'm about to update Arcgis from version 3 to 4.27 but don't have any idea how can I convert the below function:

function InfWindow(point, screenPoint) {
var qtLGA = new esri.tasks.QueryTask(WaterConnectMapServerURL + "/16/");
var qLGA = new esri.tasks.Query();

qtLGA.requestTimeout = 180;
qLGA.requestTimeout = 180;

qLGA.returnGeometry = false;
qLGA.outFields = ["ABBNAME"];
qLGA.geometry = point;
var qLGADefer = qtLGA.execute(qLGA);

var identifyTask = new esri.tasks.IdentifyTask(FloodMapServerURL);
identifyTask.requestTimeout = 180;
var identifyParams = new esri.tasks.IdentifyParameters();
identifyParams.tolerance = 0;
identifyParams.returnGeometry = false;
identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
identifyParams.width = map.width;
identifyParams.height = map.height;
identifyParams.geometry = point;
identifyParams.mapExtent = map.extent;
var identifyDefer = identifyTask.execute(identifyParams);

map.infoWindow.show(screenPoint, map.getInfoWindowAnchor(screenPoint));
map.infoWindow.setTitle("Loading...");
map.infoWindow.setContent("");

var promises = new all([qLGADefer, identifyDefer]);
promises.always(function (results) {
var infContent = [];
infContent.push("<table class='tblInfoWindow'>");
infContent.push("<tr class='tblInfoWindowTrHeader'>");
infContent.push("<th>Study</th>");
infContent.push("<th class='th-Internal-Pad'>Layer</th>");
infContent.push("<th class='th-Internal-Pad'>Depth&nbsp;Range&nbsp;(m)</th>");
infContent.push("</tr>");

for (var i = 0; i < results.length; i++) {
if (results[i].features != null) {
if (jQuery.isEmptyObject(results[i].features)) {
map.infoWindow.setTitle("Outside Local Council Area");
}
else {
map.infoWindow.setTitle(results[i].features[0].attributes.ABBNAME);
}
}

if ($.isArray(results[i])) {
if (results[i].length == 0) {

}
for (var j = 0; j < results[i].length; j++) {
infContent.push("<tr class='tblInfoWindowTrData'>");
infContent.push("<td>" + IDtoLabel[results[i][j].layerId] + "</td>");
infContent.push("<td class='td-Internal-Pad'><a title='Turn on layer' href='javascript&colon;void(0)' class='LayerLink " + results[i][j].layerId + "'>" + results[i][j].layerName + "</a></td>");
if (results[i][j].displayFieldName.toUpperCase().indexOf("RANGE") != -1)
infContent.push("<td class='td-Internal-Pad'>" + results[i][j].value + "</td>");
else
infContent.push("<td class='td-Internal-Pad'>Extent only</td>");
infContent.push("</tr>");
}
}
}
infContent.push("</table>");
map.infoWindow.resize(400, 200);
var infContentJoined = infContent.join('');
if (infContentJoined.indexOf("tblInfoWindowTrData") == -1) {
map.infoWindow.setContent("No study data available at this location. Searching nearby...");
SearchWithTolerance(point);
}
else {
map.infoWindow.setContent(infContentJoined);
$(".tblInfoWindow").find("img.pdfIcon_layer").click(function () {
var layerID = $(this).attr("id").replace("img_layer", "");
OpenPDFLink(layerID);
});
$(".tblInfoWindow").find("img.Question").click(function () {
var layerID = $(this).attr("id").replace("question_layer", "");
var layerName = $.trim($(this).parent().text());
OpenQuestionLink(layerID, layerName);
});
$(".LayerLink").click(function () {
var $tree2 = $("#tree2");
var layerId = parseInt($(this).attr("class").replace("LayerLink ", ""), 10);
var node = $tree2.tree('getNodeById', layerId);
if (node) {
$tree2.tree('openNode', node.parent, false);
$tree2.tree('selectNode', node);
DisplayFeature(null, null, layerId, FloodMapServerURL);

if ($("#chkChangeExtent").prop("checked")) {
SetMapExtent(node.parent.extent);
}
$(this).closest("table").find("tr.tblInfoWindowTrSelected").removeClass("tblInfoWindowTrSelected");
$(this).closest("tr").addClass("tblInfoWindowTrSelected");
}
});
}
});
}

QueryTask exixsts in the new version but IdentifyTask has been removed and the replacement is "esri/rest/identify". 

I used identify based on the sample https://codepen.io/pen?editors=1010 and rewrote the code got "promise" error. How can I write the code in Arcgis version 4.x? What is the replacements?

 

0 Kudos
1 Reply
UndralBatsukh
Esri Regular Contributor

Hi there, 

The link to your codepen is points to an empty codepen. In any case you can use the identify similar to what is shown below. 

const params = {
  geometry: event.mapPoint,
  tolerance: 3,
  mapExtent: view.extent
};

identify.identify("https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer", params).then((results)=>{
   console.log(results);
});

 

Hope this helps,

-Undral 

0 Kudos