Best practice for multiple types of IDENTIFY

1045
2
01-16-2013 03:52 AM
WalterEralio
New Contributor III
Here's what I'm dealing with:

I have map and a toolbar ... regular CLICK on map will do an IdentifyTask on the VISIBLE layers... 
From the toolbar I have a tool that, when selected, a different IdentifyTask is launched...

To handle the different actions to take according to the tool selected I have a select-case according to the selected tool on the click event, do I have to do the SAME (a select case according to the tool selected) on the identify results??
0 Kudos
2 Replies
ReneRubalcava
Frequent Contributor
Let me see if I follow.
You have two identify tasks, one triggered by a map click at all times and one triggered by a button then a map click, correct?

Since both are triggered by a map click, in the map click handler you check to see what state you are in?

Something like

connect.connect(map, 'onClick', function(e){
 if (ID_STATE = 'DEFAULT') {
  // execute =idtask1
 } else if (ID_STATE == 'BUTTON_CLICK') {
  // execute idtask2
 }
});


Does each identify task have it's own handler or are you passing the same handler function to each Identify Task?
If you need to process the results differently, then yes you would need to do the same, but if that's the case, then I suggest a different handler per Identify Task.

But, if you are handling your clicks this way, might a suggest a different method. This actually has worked since the API moved to Dojo 1.7, I just didn't have a real need for it until earlier this week.

Dojo has a dojo/on method that works on all dom events. Since the map is a dom element and has a click event, this will work.
http://dojotoolkit.org/reference-guide/1.8/dojo/on.html
Here is a sample working with a map
https://gist.github.com/4542944

So in your case you could do something like this.

var handler1 = on.pausable(map, 'click', function() {
 // stuff
 idtask1.execute(/*stuff*/);
});

on(button, 'click', function() {
 // here's the cool part, this event only happens one time
 var id_handler = on.once(map, 'click', function() {
  idtask2.execute(params, function() {
   /** handle results **/
   handler1.resume(); // turn the default map click handler back on
  });
 });
});


Add in an error handler to resume default map click events and you are good to go.
0 Kudos
WalterEralio
New Contributor III
WOW.. thanks for the quick answer.. and yes.. both identify had their own handler  (but I merged them to 1 and now working with the switch case option... however I'll try the dojo on function this afternoon..

Thanks!
0 Kudos