Using IdentifyTasks/IdentifyParamters to find a grid cell

557
4
07-26-2019 05:09 AM
JustinBridwell2
Occasional Contributor II

I have a simple map service API that serves a grid feature and I want to grab an attribute ("Grid_Cell2") that has the grid cell name when the user clicks a button. The grid feature has start and end points (x, y) for each cell and a field called "Grid_Cell2" which is basically the grid cell name (ex: "Grid_Cell49_19"). I am already capturing my x, y for the mouse click on the map in my application. The examples I have seen for IdentifyTask and IdentifyParameters generally show the .executefor the IdentifyTask method being launched when the user clicks on the map (ex:map.on("click", executeIdentifyTask);`) and then populating a popup. I only want to grab the desired feature based on the users x, y (which I have already captured in a variable) when the user clicks the button. Assume I have already added the required module and function and initialized the function at the top:

document.getElementById("btnGetInterval").onclick = function () {
    var point = additionalInfo["pointGeomOfInterest"]; //this is an x, y coordinate captured earlier in my code from the user's mouse click on the map
    identifyTask = new IdentifyTask(grid_url);
    identifyParams = new IdentifyParameters();
    identifyParams.geometry = point;
    identifyParams.returnGeometry = false; //I don't want to return any geometry
    identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL; //Not sure about this. I just want to return the one feature for the grid cell whose boundaries my user's mouse click (x, y) falls within....

From here, I'm honestly not sure where to go; I assume I want to use a .execute statement but I am not sure how the `IdentifyParameters come into play. I also may need an empty var/array/list to hold the returned value (["Grid_Cell2"]). Any suggestions here?

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Justin,

   First off the point var needs to be an actual esri geometry. In your case an actual point class. Next your identifyParams need some more properties filled.

var point = new Point(yourx, yourY, yourPointsSR);‍
identifyParams = new IdentifyParameters();
identifyParams.geometry = point;
identifyParams.returnGeometry = false;
identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
identifyParams.spatialReference = map.spatialReference;
identifyParams.layerIds = [0]; //The specific layers of the map Service you will be identifying‍‍‍‍‍‍‍
identifyParams.height = map.height;
identifyParams.width= map.width;‍‍‍‍‍‍‍‍‍
identifyParams.mapExtent = map.extent;
JustinBridwell2
Occasional Contributor II

Question: since I am basically just trying to get the value of a single field from a single feature on my map service, would it be easier to use `Query` and `QueryTask`?  Also, what you're saying is that I can't simply plug in an x, y coordinate into .geometry? I need to initialize it as an ESRI point first? So, something like this: 

var spatRef = new esri.SpatialReference({wkid:4326});
var point = new Point(additionalInfo["pointGeomOfInterest"].x, additionalInfo["pointGeomOfInterest"].y, spatRef);

I assume SR = spatial reference. 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Justin,

  Yes, I believe a query task would be more appropriate in this scenario. Yes you have to create a actual Point class not just pass an XY array and SR is Spatial Reference.

0 Kudos
JustinBridwell2
Occasional Contributor II

I'm going to try that (queryTask) and then repost if I have similar questions.

0 Kudos