I am trying to get the graphics & objectid of a point on the map and am using the identifyTask. I am following this example. This is my code
this.map.on("click", function (e) {
_this.map.graphics.clear();
identifyTask = new IdentifyTask("https://server/arcgis/rest/services/MUNICIPALITY_BUNDLE/ZK_KATASTAR_NA_ZELENILO/MapServer");
identifyParams = new IdentifyParameters();
identifyParams.tolerance = 3;
identifyParams.returnGeometry = true;
identifyParams.layerIds = [0, 2];
identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
identifyParams.width = _this.map.width;
identifyParams.height = _this.map.height;
identifyParams.geometry = e.mapPoint;
identifyParams.mapExtent = _this.map.extent;
console.log("identifyParams", identifyParams);
identifyTask.execute(identifyParams, function (idResults) {
console.log("test", idResults);
});
});
idResults returns an empty array and I am unsure as to why.
Any ideas or pointers as to what I am doing wrong?
Try setting the spatial reference to see if that makes any difference.
identifyParams.spatialReference = _this.map.spatialReference;
It's still the same.
Are the layerIds you're setting correct? Can you share the URL you're using to verify the process?
Then you'll want to modify this line since there is no layer 0. Your IdentifyTask would only include what is found is Layer 2. Include the layer ids you want to identify.
identifyParams.layerIds = [0, 2];
.
identifyParams.layerIds = [1];
identifyParams.layerIds = [1, 2];
I have made both of these modifications. For a fact, I know that the layer 1 has records in it and it still returns an empty array.
Whether I include all of the layers as above, or just one single layer it still returns an empty array.
try changing you layerOption value, the documentation says it should be a string, either "top", "visible" or "all".