how to get arcgis IdentyfyTask addCallback `s value?

2783
7
06-14-2016 08:58 AM
ParkSeungHyun
New Contributor II

i was tested to the IdentyfyTask.

But I could not get a response before the value addCallback.

i want to the pnu values.

But pnu vaule was alwayes undefined...

my code is follows.

    function poiClick(){

    agmap.addEvent("click", function(evt){

  

    getPoi= krcgis.Function.PoiClick(agmap ,evt);

    

    console.log("X === ",getPoi.x);

    console.log("Y === ",getPoi.y);

    console.log("PNU === ",getPoi.pnu);

    });

    }

   

     PoiClick : function(map, evt) {

    poiInfo = {};

    poiInfo.x =evt.mapPoint.x;

    poiInfo.y =evt.mapPoint.y;

    var targetLayerId = 'LP_PA_CBND';

    var url = map.Layers.getLayerInfo(targetLayerId).SVC_URL;

    var map = map.getMap();

    //파라미터 설정.

    var idParams = new krcgis.core.tasks.IdentifyParameters();

    idParams.geometry = evt.mapPoint;

    idParams.mapExtent = map.extent;

    idParams.returnGeometry = true;

    idParams.tolerance = 0;

    idParams.layerOption = krcgis.core.tasks.IdentifyParameters.LAYER_OPTION_ALL;

    idParams.width = map.width;

    idParams.height = map.height;

  

  

    idTask = new krcgis.core.tasks.IdentyfyTask(url);

    idTask

    .execute(idParams)

    .addCallback(function (response) {

    if (response) {

    poiInfo.pnu =response[0].value;

    }

    });

    return poiInfo;

    }

The results were as follows.

123.png

0 Kudos
7 Replies
KenBuja
MVP Esteemed Contributor

I believe what's happening is that you're executing the PoiClick function but before the response has been returned, you're trying to access the pnu value in the console. What happens when you put the console.log lines in the addCallback function?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Park,

  A couple of questions.

Why are you setting the tolerance to 0?

Why are your classes coming from krcgis.core and not esri?

Are you aware that the result of an identify task is a IndentifyResult class?

Have you tried to write the whole identify task results to the console to see if you are getting what you are expecting from the IdentifyTask?

0 Kudos
ParkSeungHyun
New Contributor II

I made sure to identify task results in the console.

But I do not know how to retrun the results.

The results were seen in other function.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Park,

  The Identify Results return as an array of features and features are actually Graphics so to access the graphics attributes you have to use

console.log("PNU === ",getPoi.attributes.pnu);

I also do not see where you are defining the IdentifyParameters.layerIds. This should be the layer id number of the layer you wish to identify from the map service you are working with.

idParams.layerIds= [1]; (i.e. 1 for the second layer in the map service).

0 Kudos
ParkSeungHyun
New Contributor II

i was confirmed pnu value by console.

i`m developing a system openapi.

So the user must return the x, y, pnu value to the user calling the poiclick function.

But.. i don`t know. how to return that pnu value.

IdentyfyTask executes addCallback then function is being performed, so as to not make the pnu value.

What should I do?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Park,

  Did you see my last reply? I provided some suggestions there.

0 Kudos
ParkSeungHyun
New Contributor II

OK, I'll test ~!! Thanks~ your answer.

0 Kudos