Issue with mapPoint precision for IdentifyTask operation

2336
6
08-28-2013 08:47 PM
CoreyMoten
New Contributor
I am having an issue selecting features in my web map for an IdentifyTask operation. I have a dynamic map service that contains a few sublayers that I would like to be able to click and have a popup or infowindow display the attribution for the selected feature. Currently onclick of the "map", the IdentifyTask execution fires off. The problem is that the precision of the map click seems to be off. When I click a feature with the cursor, the feature is not selected and the InfoWindow displays 'No Results' way below where I clicked the cursor. The InfoWindow typically is supposed to display where a user clicks the cursor right? I have to click above the intended feature in order to actually select the feature and have the IdentifyTask recognize it. Its weird. I played around with the tolerance values for the IdentifyParameters object but no luck. Has anybody ever had a similar issue? Is there a way to specify the precision for a mapClick event? Any help would be greatly appreciated. Below is the code I'm using to show the results of the IdentifyTask.

//Create IdentifyTask object
userConfig.identifyTask = new esri.tasks.IdentifyTask(currentServiceUrl);

//Create and setup IdentifyParameters
userConfig.identifyParams = new esri.tasks.IdentifyParameters();
userConfig.identifyParams.height = userConfig.map.height;
userConfig.identifyParams.width = userConfig.map.width;
userConfig.identifyParams.mapExtent = userConfig.map.extent;
userConfig.identifyParams.tolerance = 3;
userConfig.identifyParams.returnGeometry = true;

//Define the layers to identify
var layersToId = [];
if (currentUtilId == "barksdale") {
    var layers = userConfig.barksdaleService.visibleLayers;
    for (var i = 0; i < layers.length; i++) {
        if (layers != 27 && layers != 40 && layers != 82) {
            layersToId.push(layers);
        }
    } //End loop
}
else if (currentUtilId == "malmstrom") {
    var layers = userConfig.malmstromService.visibleLayers;
    for (var i = 0; i < layers.length; i++) {
        if (layers != 27 && layers != 40 && layers != 82) {
            layersToId.push(layers);
        }
    } //End loop
}
else if (currentUtilId == "minot") {
    var layers = userConfig.minotService.visibleLayers;
    for (var i = 0; i < layers.length; i++) {
        if (layers != 27 && layers != 40 && layers != 82) {
            layersToId.push(layers);
        }
    } //End loop
}
else if (currentUtilId == "whiteman") {
    var layers = userConfig.whitemanService.visibleLayers;
    for (var i = 0; i < layers.length; i++) {
        if (layers != 27 && layers != 40 && layers != 82) {
            layersToId.push(layers);
        }
    } //End loop
}
else if (currentUtilId == "warren") {
    var layers = userConfig.warrenService.visibleLayers;
    for (var i = 0; i < layers.length; i++) {
        if (layers != 27 && layers != 40 && layers != 82) {
            layersToId.push(layers);
        }
    } //End loop
}
userConfig.identifyParams.layerIds = layersToId;
userConfig.identifyParams.geometry = evt.mapPoint;

var deferred = userConfig.identifyTask.execute(userConfig.identifyParams);

deferred.addCallback(function (response) {
    // Response is array of identify result objects
    // Return an array of features.
    return dojo.map(response, function (result) {
        var feature = result.feature;
        var attribution = feature.attributes;
        var infoTemplate = new esri.InfoTemplate();
        var templateString = "";
        //Parse and print the key-value pairs in the attribution object
        for (prop in attribution) {
            templateString = templateString + "<b>" + prop + "</b>: " + attribution[prop] + "<br>";
        }
        infoTemplate.setTitle("Identify Results");
        infoTemplate.setContent(templateString);
        feature.setInfoTemplate(infoTemplate);
        return feature;
    });
});

userConfig.map.infoWindow.setFeatures([deferred]);
userConfig.map.infoWindow.show(evt.mapPoint);
0 Kudos
6 Replies
KenBuja
MVP Esteemed Contributor
Have you checked the values for layersToID to see if they're valid?

For showing the infoWindow, try using
map.infoWindow.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));


There is a difference between evt.screenPoint and evt.mapPoint
0 Kudos
CoreyMoten
New Contributor
Hi Ken

The values in layersToId appear to be valid. When the IdentifyTask executes it actually does bring the correct data back from the server. But clicking on the actual feature where it appears on the map results in the InfoWindow coming back with "No Results", basically as if I clicked an empty spot (spot with no feature present) in the map. I have to click well above the intended feature before the feature is selected and the IdentifyTask can do its thing. But when this is done the correct results come back from the map service. It seems like the problem is some kind of click precision issue within the map. I click anywhere in the map and its as if the map sees the click several screen pixels below where I actually clicked. I also tried changing from evt.mapPoint to evt.screenPoint with no luck.
0 Kudos
JasonZou
Occasional Contributor III
Try to move setFeatures and show inside the callback of identify task. Otherwise, the code may hit the setFeatures when identify task not complete. That may explain you may get nothing returned sometime.

var evtCopy = evt;
userConfig.identifyTask.execute(userConfig.identifyParams, function(response) {
    // Response is array of identify result objects
    // Return an array of features.
    var features = dojo.map(response, function (result) {
        var feature = result.feature;
        var attribution = feature.attributes;
        var infoTemplate = new esri.InfoTemplate();
        var templateString = "";
        //Parse and print the key-value pairs in the attribution object
        for (prop in attribution) {
            templateString = templateString + "<b>" + prop + "</b>: " + attribution[prop] + "<br>";
        }
        infoTemplate.setTitle("Identify Results");
        infoTemplate.setContent(templateString);
        feature.setInfoTemplate(infoTemplate);
        return feature;
    });

    userConfig.map.infoWindow.setFeatures(features);
    userConfig.map.infoWindow.show(evtCopy.mapPoint);
});
0 Kudos
CoreyMoten
New Contributor
Hi Jason,

I tried your code suggestion and that resulted in the info window not displaying at all no matter where I clicked in the map. The issue isn't really with the results returned in the info window. The results come back from the IdentifyTask correct whenever a feature is selected in the map. The issue is with the precision of the map click. I can't for the life of me figure out why the map click is being seen or "registered" by the map as being several screen pixels below where I actually click on the map.
0 Kudos
GabrielaBota
New Contributor
Check the layout of your page; I had a similar issue when I placed the toolbar (with the 'identify' function) in the 'div' of the map.
0 Kudos
KathieLivesley1
New Contributor
Have you resolved this issue?  I am having the same exact problem and would be happy to know anything else to check.
0 Kudos