Strange Issue with the IdentifyTask

896
4
02-24-2011 01:10 PM
DanielYim
New Contributor II
When I try to identify a feature, the IdentifyTask's execute function is invoking an error that simply contains the message "Unable to complete operation."

The strange thing is, this identify function works as it should when I use it at either the map's full extent or a specific extent of a feature (when I zoom to a feature via the results in a Datagrid), but once I pan the map even slightly out of that specific extent, the IdentifyTask throws that error.

My code is listed in the following. It's a loose interpretation of the "Identify features on a map" sample provided by ArcGIS.
doIdentify = function(evt) {
    // Hide the previous results
    myMap.infoWindow.hide();
    
    var task = null;
    var params = null;
    
    task = new esri.tasks.IdentifyTask(url.baseMap);
    
    params = new esri.tasks.IdentifyParameters();
    params.tolerance = 4;
    params.returnGeometry = true;
    params.layerIds = [3, 4, 5, 6];
    params.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
    params.width = myMap.width;
    params.height = myMap.height;
    params.geometry = evt.mapPoint;
    params.mapExtent = myMap.extent;
    task.execute(params, function(idResults) {
        identifyInfoWin(idResults, evt);
    }, function(err) {
        console.log("doIdentify: (" + err.name + ") " + err.message);
    });
};


I consider myself well-acquainted with the ArcGIS JS API, but I have been staring at this problem for much too long without seeking help.

Thanks in advance
0 Kudos
4 Replies
HemingZhu
Occasional Contributor III
When I try to identify a feature, the IdentifyTask's execute function is invoking an error that simply contains the message "Unable to complete operation."

The strange thing is, this identify function works as it should when I use it at either the map's full extent or a specific extent of a feature (when I zoom to a feature via the results in a Datagrid), but once I pan the map even slightly out of that specific extent, the IdentifyTask throws that error.

My code is listed in the following. It's a loose interpretation of the "Identify features on a map" sample provided by ArcGIS.
doIdentify = function(evt) {
    // Hide the previous results
    myMap.infoWindow.hide();
    
    var task = null;
    var params = null;
    
    task = new esri.tasks.IdentifyTask(url.baseMap);
    
    params = new esri.tasks.IdentifyParameters();
    params.tolerance = 4;
    params.returnGeometry = true;
    params.layerIds = [3, 4, 5, 6];
    params.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
    params.width = myMap.width;
    params.height = myMap.height;
    params.geometry = evt.mapPoint;
    params.mapExtent = myMap.extent;
    task.execute(params, function(idResults) {
        identifyInfoWin(idResults, evt);
    }, function(err) {
        console.log("doIdentify: (" + err.name + ") " + err.message);
    });
};


I consider myself well-acquainted with the ArcGIS JS API, but I have been staring at this problem for much too long without seeking help.

Thanks in advance


Take out this optional function function(err) from your code and try again. Believe it or not sometime this function do harm that it do good.
0 Kudos
HemingZhu
Occasional Contributor III
Take out this optional function function(err) from your code and try again. Believe it or not sometime this function do harm that it do good.


Just a follow up for what i was saying. I found out that sometimes onComplete and onError both fired up if you put both in execute method. if i put them seperately using dojo.connect, it works just fine. I could not figure out why.
0 Kudos
DanielYim
New Contributor II
Wow, hzhu, that really is wacky. I hoped that what you said was the problem with my code:

    task.execute(params);
    dojo.connect(task, "onComplete", function(idResults) {
        identifyInfoWin(idResults, evt);
        // Hide the loading bar when a result is found
    });
    dojo.connect(task, "onError", function(err) {
        console.log("doIdentify: (" + err.name + ") " + err.message);
    });


Unfortunately, I still get the same error under the same circumstances.
0 Kudos
DanielYim
New Contributor II
I finally figured it out.

I was using a bad Extent object as an initial extent for my map:
    // This is entirely the WRONG way to declare an extent
    var startExtent = new esri.geometry.Extent({
        xmin: -107.62971356312966,
        ymin: 25.850355124455604,
        xmax: -92.35392362656452,
        ymax: 36.59093275985384,
        spatialReference: {
            wkid: "4269"
        }
    });
    
    myMap = new esri.Map("mapDiv", {
        extent: startExtent,
        logo: false,
        slider: false
    });


I don't know where I got that extent format from, but it's wrong and using that format will mess with your application, particularly IdentifyTask in my case.

Use the following format instead, as per the JS API:
    startExtent = new esri.geometry.Extent(-101.120185812004, 34.39538449192201, -100.983017186634, 34.49182927651549, new esri.SpatialReference({
        wkid: 4269
    }));



Thanks for reading.
0 Kudos