Select to view content in your preferred language

How to stop queryTask execution?

2090
13
Jump to solution
11-21-2012 03:32 AM
YvanBérard
Regular Contributor
Hi all,

i've created my own identify tool with the queryTask, but i can't find a way to stop the execution of the queryTask.

Is there a way to stop the execution?

Thanks.

function identificationTool(action,qryUE,queryTaskUE) {  alert(action);  if(action =="go")  {   dojo.connect(map, "onClick", function(evt)    {    console.log("Identification: click");           //onClick event returns the evt point where the user clicked on the map.          //This is contains the mapPoint (esri.geometry.point) and the screenPoint (pixel xy where the user clicked).          //set query geometry = to evt.mapPoint Geometry          qryUE.geometry = evt.mapPoint;           //Execute task and call showResults on completion          queryTaskUE.execute(qryUE, showResults);             });  }  else  {   dojo.connect(map, "onClick", function(evt)    {                         // Here we should stop the execution of the queryTaskUE    map.infoWindow.hide();   });  } }
0 Kudos
13 Replies
__Rich_
Deactivated User
I'm glad that you're happy 🙂

But...and I've misunderstood the solution you've been given...but I don't think I agree with it, normally you'd wouldn't have to keep clicking the identify button repeatedly in a GIS app to perform multiple serial identify requests.

For example, think about ArcMap - you put the application in identify mode then just keep clicking on the map as many times as you like, you don't have to re-click the identify button in the toolbar between map clicks.

Maybe I misunderstood your aim all along...
0 Kudos
YvanBérard
Regular Contributor
I'm glad that you're happy 🙂

But...and I've misunderstood the solution you've been given...but I don't think I agree with it, normally you'd wouldn't have to keep clicking the identify button repeatedly in a GIS app to perform multiple serial identify requests.

For example, think about ArcMap - you put the application in identify mode then just keep clicking on the map as many times as you like, you don't have to re-click the identify button in the toolbar between map clicks.

Maybe I misunderstood you aim all along...


You are totally right and I think the same.

But, I think i still don't understand very well how dojo work to make it happen.

If you are still willing to help me find a way to make it work (like in ArcMap) I'll be very happy. I think the problem is where I should put the dojo.connect(map, "onClick", function(evt)....... and where i should manage the activation of the button.

Do you  have any idea on how I should settle this?
0 Kudos
__Rich_
Deactivated User
If you follow the ArcMap approach completely (you don't have to, but it's easier to explain if you're already comfortable with that) then then you could consider Identify to be a 'mode' that you put your application into.

When the mode is 'on' then map clicks trigger a task to be executed, when the mode is 'off' then map clicks do nothing.

To start with you need a GUI control so that your user can tell you when they want to turn the mode on/off, a toggle button would do or perhaps a checkbox.  One additional thing to consider here is whether this mode needs to be mutually exclusive with any other functionality for example, it would be confusing to have Identify and Measure modes both 'on' at the same time - you can write some simple logic to ensure that turning one 'on' turns the other 'off'.

All this control needs to do is connect/disconnect the map click to/from the appropriate handler, it does not perform the task etc.

I would do this very simple step first, perhaps just put an alert in the handler for now so that you can see what the button and the connect/disconnect does etc.

Once that's in place an working robustly you can move onto implementing the task.

A lot of the lines of code you have already written can probably be re-used, it's just the flow/structure that needs changing, don't worry, it's not too complicated 🙂
0 Kudos
YvanBérard
Regular Contributor
YES!!!

Finally!

It's working like "ArcMap"!!

here is my code if somebody need it.

function init() {         ...          $(document).ready(function()   {   toolAction(map,qryUE,queryTaskUE);  }); }  function toolAction(map,qryUE,queryTaskUE) {        ...     $("#identify_spot").bind("click", function(event)    {     // If it's the same tool   if( getActiveTool() == "#identify_spot" )   {    setActiveTool();                         // Clear all the graphics, but not the infoTemplate and I don't know why.    map.graphics.clear();    dojo.disconnect(getDojoClick());   }   // If it's the not same tool   else   {    setActiveTool("#identify_spot");    setDojoClick(dojo.connect(map, "onClick", function(evt)       {      identificationTool(qryUE,queryTaskUE,evt);      console.log("identification click");     })    );   }  }); }  var thisTool; var dojoAction;  function setActiveTool(tool) {  if(tool != null)  {   thisTool = tool;   $(thisTool).addClass("active_tool");   }  else  {   $(thisTool).removeClass("active_tool");   thisTool = "";   }  console.log(thisTool+" class=active_tool")  }  function getActiveTool() {  return thisTool; }  function setDojoClick(action) {  if( action != null )  {   dojoAction = action;  }  else  {   dojoAction = "vide";  } }  function getDojoClick() {  console.log("kill");  return dojoAction; }
0 Kudos