Suspend map click event for identify when floating pane is open

934
7
Jump to solution
06-19-2014 11:57 AM
TracySchloss
Frequent Contributor
I have a map click to do an identify defined initially.  I want to be able to let the user click on my chart button to open a floating pane where I will generate a chart.  While the floating pane is open, I want the click event to run my generate chart function for the selected polygon instead of my standard identify.  I have multiple years of data for each county I want to show, coming out of multiple layers in my service.  The data is gathered through another identify that looks at all layers and formats the data the way the chart needs it. That part is figured out, believe or not.  I'm stuck on managing my identify click handlers.

I've found several threads that discuss switching between the measure tools and identify, but the solution seems to be having a listener on the measure events.  Nothing in those solutions helps me with this situation.

I tried setting a variable when I defined the identify click event as

identifyHandler = map.on('click', identifyClickHandler);


I have a function to open the floating pane as
registry.byId('btnChart').on('click', function (){   idFromClick = false;   chartClick = true;   domConstruct.empty("chartDiv");   openFloatingPane('floater_chart');   makeCountyChartClickHandler = map.on( "click", chartCountyByMapClick);         });


How do I get rid of identifyHandler?  At what point do I turn it back on again?  I'm not sure how what the event is for the floatingPane getting closed.  All the examples I found are still based on dojo.connect and dojo.disconnect. 

I also need to clear out the div that's in my floating pane in preparation to creating a new chart.  I'm trying to use
domConstruct.empty("chartDiv"); 


Since my chart div is in my floating pane, it looks like the pane is getting destroyed, not closed, so I'm not sure when to empty it.

The other thing that is happening is that the chart works OK the first time, but when I click a 2nd time on the same or different county, it's loading my chart over the top of it self multiple times.  I think it's doing it because the identify is firing more than once.  I'm sure it's because I haven't straightened out my click events yet, but it does seem wierd.

Here's my best attempt to post my example:
http://jsfiddle.net/schlot/HPDP7/
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
Good call, Rene. I tried both

aspect.after(fpVideo, 'onHide', function () { console.log("onHide"); }); aspect.after(fpVideo, 'hide', function () { console.log("hide"); });


and only got a "hide" in the console.

View solution in original post

0 Kudos
7 Replies
ReneRubalcava
Frequent Contributor
It sounds like you might want to try dojo/on#pausable
http://dojotoolkit.org/reference-guide/1.10/dojo/on.html#pausable

Here is from a post a while ago
http://forums.arcgis.com/threads/98389-Cancel-Identify-Task?p=353584&viewfull=1#post353584

It also looks like you are trying to toggle what function happens on the map click based on a certain state in your application.

I wrote something up for that recently that might be useful.
https://gist.github.com/odoe/7e6b13cfac66e5cc99a5

You can basically use it like this

var handler = on.switchable(map, 'click', function1, function2); //defaults to function1 first
...//do stuff
handler.toggle(); // now will launch function2 when event occurs
...//do more stuff
handler.toggle(); // returns to using function1 to handle events
0 Kudos
TracySchloss
Frequent Contributor
The function for opening the floating pane now includes a pause for the identify click handler and turns on the handler for the 'make chart' click event.  When I close the floating pane, I don't know what event I'm listening for, so I can't do the reverse:  turn on the identify and turn off the chart making.
0 Kudos
KenBuja
MVP Esteemed Contributor
Can you listen for the FloatingPane's onClose or onHide event?
0 Kudos
TracySchloss
Frequent Contributor
That's what I'm attempting with this, but my console.log never comes up, so I assume its not the right syntax.
registry.byId('floater_chart').on('hide', function () {
  console.log ("floater chart is hidden");
});


I'm getting confused because most AMD has syntax like close, click, hide etc, not onClose, onClick, onHide.  I never have much luck digging through the dojo API reference and the documentation is pretty sparse.
0 Kudos
ReneRubalcava
Frequent Contributor
Since FloatingPane is part of dojox, it may not be an Evented module yet.
You could go back to using dojo/connect or I think the preferred way to handle these modules is using dojo/aspect
http://dojotoolkit.org/reference-guide/1.10/dojo/aspect.html

aspect.after(floatingPane, 'onHide', handlerFunction);
0 Kudos
KenBuja
MVP Esteemed Contributor
Good call, Rene. I tried both

aspect.after(fpVideo, 'onHide', function () { console.log("onHide"); }); aspect.after(fpVideo, 'hide', function () { console.log("hide"); });


and only got a "hide" in the console.
0 Kudos
TracySchloss
Frequent Contributor
Rene, you're right about trying aspect and Ken you're right that it wanted 'hide' and not 'onHide'.  It's working!  I've updated my jsFiddle.    That may turn out to be a good generic solution for me.  As the requests for 'can you make it do this' grow larger, I always struggle to find a place to put everything.
0 Kudos