Get x,y from identifed feature(s)

749
4
Jump to solution
01-10-2014 08:59 AM
JohnPreston
Occasional Contributor
Hi, I would like to get the x,y from identified features when user clicks on map. I would also like to get the count of features found. Does anyone have an exmaple or resource to point me to? Thank you!

Here is code to identify features when user clicks...

function mapReady(map) {
            getLocation();
            dojo.connect(map, "onClick", executeIdentifyTask);
            identifyTask = new esri.tasks.IdentifyTask("http://gisappserv3/ArcGIS/rest/services/Engineering/MaintenancePoints/MapServer");
            identifyParams = new esri.tasks.IdentifyParameters();
            identifyParams.tolerance = 5;
            identifyParams.returnGeometry = true;
            identifyParams.layerIds = [2, 15];
            identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
            identifyParams.width = map.width;
            identifyParams.height = map.height;
        }

function executeIdentifyTask(evt) {
            identifyParams.geometry = evt.mapPoint;
            alert(identifyParams.geometry('x'));        
            identifyParams.mapExtent = myMap.extent;              
            var deferred = identifyTask.execute(identifyParams);
            deferred.addCallback(function (response) {
                return dojo.map(response, function (result) {
                    var feature = result.feature;
                    feature.attributes.layerName = result.layerName;
                    console.log(feature.attributes.Location);
                    if (result.layerName === 'Maintenance Districts') {
                        $('input:radio[name="radioMaintDist"]').filter('[value="' + feature.attributes['District'] + '"]').next().click();
                    }
                    else {
                        $('#popStructureType').val(feature.attributes['Display Name']);
                    }
                    $('#popSWUStructure').popup('open');
                    var template = new esri.InfoTemplate("", "Facility ID: ${Manhole I.D.} <br/>");
                    feature.setInfoTemplate(template);
                    return feature;
                });
            });             
        }
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
But you can get back many results from executing an IdentifyTask

identifyTask.execute(identifyParams, function (results) {      console.log(results.length); }); 

View solution in original post

0 Kudos
4 Replies
JohnPreston
Occasional Contributor
I was able to figure out how to get the x,y by adding this code in the return dojo.map(response, function (result) {...
var mp = result.feature.geometry
alert(mp.x + " " + mp.y);

I still want to be able to county the number of features identified.
0 Kudos
JonathanUihlein
Esri Regular Contributor
Documentation for result of an IdentifyTask:

https://developers.arcgis.com/en/javascript/jsapi/identifyresult-amd.html

As you can see, it returns one feature (as a graphic). You've already discovered result.feature.geometry.x and result.feature.geometry.y, but it is all outlined in the documentation.

Hope this helps!
0 Kudos
KenBuja
MVP Esteemed Contributor
But you can get back many results from executing an IdentifyTask

identifyTask.execute(identifyParams, function (results) {      console.log(results.length); }); 
0 Kudos
JohnPreston
Occasional Contributor
Thanks Jon and Ken!
0 Kudos