IdentifyTask in API 4.6 trouble finding feature geometry

1162
4
Jump to solution
01-10-2018 02:58 PM
LoriEmerson_McCormack
Occasional Contributor

I want to access the feature geometry when using the IdentifyTask in the JavaScript API 4.6 so that I can add a graphic to my point feature.

I am using the Sample located at https://developers.arcgis.com/javascript/latest/sample-code/tasks-identify/

I added a line

var mp = result.feature.geometry;

but the geometry is null. 

Here is part of the code:

// Executes each time the view is clicked

function executeIdentifyTask(event) {

// Set the geometry to the location of the view click

alert (event.mapPoint.x);

params.geometry = event.mapPoint;

params.mapExtent = view.extent;

dom.byId("viewDiv").style.cursor = "wait";

// This function returns a promise that resolves to an array of features

// A custom popupTemplate is set for each feature based on the layer it

// originates from

identifyTask.execute(params).then(function(response) {

var results = response.results;

return arrayUtils.map(results, function(result) {

var feature = result.feature;

var layerName = result.layerName;

var mp = result.feature.geometry;

End of the code

Here is what the result object looks like in 4.6.  How do I find the geometry?  The "_proto_" and "_accessor_" make it difficult to find anything.

Result Object in JavaScript API 4.6

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Lori,

  Your issue is mis-punctuation of the property name the g has to be upper case

params.returnGeometry = true;

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Lori,

   I do not see in your code where you specify the returnGeometry property of the IdentifyParameters.

https://developers.arcgis.com/javascript/latest/api-reference/esri-tasks-support-IdentifyParameters.... 

0 Kudos
LoriEmerson_McCormack
Occasional Contributor

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>IdentifyTask - 4.6</title>

<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}

.esri-popup .esri-popup-header .esri-title {
font-size: 18px;
font-weight: bolder;
}

.esri-popup .esri-popup-body .esri-popup-content {
font-size: 14px;
}
</style>

<link rel="stylesheet" href="https://js.arcgis.com/4.6/esri/css/main.css">
<script src="https://js.arcgis.com/4.6/"></script>

<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/TileLayer",
"esri/tasks/IdentifyTask",
"esri/tasks/support/IdentifyParameters",
"dojo/_base/array",
"dojo/on",
"dojo/dom",
"dojo/domReady!"
], function(
Map, MapView, TileLayer,
IdentifyTask, IdentifyParameters,
arrayUtils, on, dom
) {

var identifyTask, params;

// URL to the map service where the identify will be performed
var soilURL =
"https://services.arcgisonline.com/arcgis/rest/services/Specialty/Soil_Survey_Map/MapServer";

// Add the map service as a TileLayer for fast rendering
// Tile layers are composed of non-interactive images. For that reason we'll
// use IdentifyTask to query the service to add interactivity to the app
var parcelsLyr = new TileLayer({
url: soilURL,
opacity: 0.85
});

var map = new Map({
basemap: "osm"
});
map.add(parcelsLyr);

var view = new MapView({
map: map,
container: "viewDiv",
center: [-120.174, 47.255],
zoom: 7
});

view.when(function() {
// executeIdentifyTask() is called each time the view is clicked
on(view, "click", executeIdentifyTask);

// Create identify task for the specified map service
identifyTask = new IdentifyTask(soilURL);

// Set the parameters for the Identify
params = new IdentifyParameters();
params.tolerance = 3;
params.layerIds = [0, 1, 2];
params.layerOption = "visible";
params.width = view.width;
params.height = view.height;
params.returngeometry = true;
});

// Executes each time the view is clicked
function executeIdentifyTask(event) {
// Set the geometry to the location of the view click

alert (event.mapPoint.x);
params.geometry = event.mapPoint;
params.mapExtent = view.extent;
dom.byId("viewDiv").style.cursor = "wait";

// This function returns a promise that resolves to an array of features
// A custom popupTemplate is set for each feature based on the layer it
// originates from
identifyTask.execute(params).then(function(response) {

var results = response.results;

return arrayUtils.map(results, function(result) {

var feature = result.feature;
var layerName = result.layerName;
var mp = result.feature.geometry; // this is null

feature.attributes.layerName = layerName;
if (layerName === 'Soil Survey Geographic') {
feature.popupTemplate = { // autocasts as new PopupTemplate()
title: "{Map Unit Name}",
content: "<b>Dominant order:</b> {Dominant Order} ({Dom. Cond. Order %}%)" +
"<br><b>Dominant sub-order:</b> {Dominant Sub-Order} ({Dom. Cond. Suborder %}%)" +
"<br><b>Dominant Drainage Class:</b> {Dom. Cond. Drainage Class} ({Dom. Cond. Drainage Class %}%)" +
"<br><b>Farmland Class:</b> {Farmland Class}"
};
}
else if (layerName === 'State Soil Geographic') {
feature.popupTemplate = { // autocasts as new PopupTemplate()
title: "{Map Unit Name}",
content: "<b>Dominant order:</b> {Dominant Order} ({Dominant %}%)" +
"<br><b>Dominant sub-order:</b> {Dominant Sub-Order} ({Dominant Sub-Order %}%)"
};
}
else if (layerName === 'Global Soil Regions') {
feature.popupTemplate = { // autocasts as new PopupTemplate()
title: layerName,
content: "<b>Dominant order:</b> {Dominant Order}" +
"<br><b>Dominant sub-order:</b> {Dominant Sub-Order}"
};
}
return feature;
});
}).then(showPopup); // Send the array of features to showPopup()

// Shows the results of the Identify in a popup once the promise is resolved
function showPopup(response) {
if (response.length > 0) {
view.popup.open({
features: response,
location: event.mapPoint
});
}
dom.byId("viewDiv").style.cursor = "auto";
}
}
});
</script>
</head>

<body>
<div id="viewDiv"></div>
</body>

</html>

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lori,

  Your issue is mis-punctuation of the property name the g has to be upper case

params.returnGeometry = true;

0 Kudos
LoriEmerson_McCormack
Occasional Contributor

Silly me.  Thanks, Robert.

0 Kudos