How to get the coordinate searched from callback function of QueryTask execute

205
1
06-15-2020 01:42 PM
AdeebFarhan
New Contributor II

I have a function checkCoverage for a particular x,y coordinate. Which executes a QueryTask. And get the result in a call back function.  A Query Object is passed to QueryTask.execute(). The coordinate to search is set in Query as below.

 

Is there any way to find the coordinate (Point x and y) which was set in Query object from the callback function (reportMyCoverage)  result object?

 

This is required because I trying to run this Check Coverage Function for multiple coordinates.

Check Coverage Function

           checkCoverage: function (x, y ) {

               

                var map = mySelfSearch.map;

                var geographicPoint = new Point(x, y);

                var projectedPoint=webMercatorUtils.geographicToWebMercator(geographicPoint);

                var graphic = new Graphic(projectedPoint);

                if (mySelfSearch.map.getLayer('coverageCheckGraphics_point') != undefined) { mySelfSearch.map.getLayer('coverageCheckGraphics_point').clear(); }

                mySelfSearch.map.getLayer('coverageCheckGraphics_point').add(graphic);

                try{

                     mySelfSearch.map.getLayer('coverageCheckGraphics_point').graphics[0]);

                    var chkpnt = map.getLayer('coverageCheckGraphics_point').graphics[0].geometry;

                    var query = new Query();

                    var fiberCovCompletionFlagCheck = mySelfSearch.fiberCoverageCompletion;

                    query.geometry = chkpnt;

                    query.where = " 1=1 ";

                    query.returnGeometry = true;

                    query.spatialRelationship = "esriSpatialRelIntersects";

                   

                    var queryTaskFiber = new QueryTask(mySelfSearch.queryURLFiber);

                    query.outFields = ['*'];

 

                    queryTaskFiber.execute(query, mySelfSearch.reportMyCoverage, function (error) { console.log(getADBDate() + "Error occured in queryTaskFiber.execute  " + error.message); });

                    mySelfSearch.fiberCoverageCompletion=false;

                } catch (e) {

                    console.log("Error occured in check coverage  " + e.message);

                }

            },

reportMyCoverage: function (result)

             reportMyCoverage: function (result) {

               var isCovered = result.features.length > 0;

                if (isCovered) {

                    mySelfSearch.fiberCoverage = 'TRUE';

                } else {

                    mySelfSearch.fiberCoverage = 'FALSE';

                }

           },

0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Esteemed Contributor

Adeeb,

  Sure here is how. This is call JS Closure. You pass the point object to the result function.

queryTaskFiber.execute(query, 
  function(result){
    mySelfSearch.reportMyCoverage(result, chkpnt);
  }, 
  function (error) {
    console.log(getADBDate() + "Error occured in queryTaskFiber.execute  " + error.message); 
  }
);

reportMyCoverage: function (pntGeom, result) {
  var isCovered = result.features.length > 0;
  if (isCovered) {
    console.log(pntGeom);
    mySelfSearch.fiberCoverage = 'TRUE';
  } else {
    mySelfSearch.fiberCoverage = 'FALSE';
  }
},
0 Kudos