OnMouse Events disable OnClick event for FeatureLayers

6101
5
07-22-2010 10:43 AM
LukeRogers
New Contributor III
Start with the sample application here:

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/fl_hover.html

Add the following code at the bottom of the init function:

dojo.connect(southCarolinaCounties, "onClick", function(evt) {
                                                                window.location = "http://www.esri.com"
                                                });

Notice that the onClick event does not respond to mouse clicks. Now comment out the southCarolinaCounties "onMouseOver" event and notice that now the onClick event works.

I have tested this with a few of the onMouse events and all seem to disable the onClick event. How can I have both an onMouseOver and an onClick event for a feature layer?
0 Kudos
5 Replies
LukeRogers
New Contributor III
I found a workaround. Replace the dojo.connect(southCarolinaCounties, "onMouseOver", function(evt) {}); with the following complete function. Basically just hooking up an onClick event to the graphic created by the southCarlinaCounties.onMouseOver
event:

dojo.connect(southCarolinaCounties, "onMouseOver", function(evt) {
map.graphics.clear();
evt.graphic.setInfoTemplate(infoTemplate);
var content = evt.graphic.getContent();
map.infoWindow.setContent(content);
var title = evt.graphic.getTitle();
map.infoWindow.setTitle(title);
var highlightGraphic = new
esri.Graphic(evt.graphic.geometry,highlightSymbol);
map.graphics.add(highlightGraphic);

map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoin
t));
dojo.connect(map.graphics, "onClick", function(evt) {
  window.location = "http://www.esri.com";
});
});

I figured I should be able to hook the event up to the specific graphic
(highlightGraphic) but that didn't work. Anyway, another piece to the puzzle.
0 Kudos
LukeRogers
New Contributor III
...the response from ESRI Support:

I have been working on the issue and after further analysis, it appears that the behavior encountered with 'onClick' event when the FeatureLayer implements both 'onMouseOver' and an 'onClick' events simultaneously, seems to be a bug. I have logged it in with development for further research and clarification. You can reference this bug using #NIM059323 [The 'onClick' event does not fire if the FeatureLayer implements both 'onMouseOver' and an 'onClick' events simultaneously. ]
0 Kudos
__Rich_
Occasional Contributor III
I can't see that this is a bug, unless I'm missing something?!

See my response here

The highlightGraphic is being added on top of the southCarolinaCounties layer thus masking it, so it is the highlightGraphic that will get the click, unless you expect the click to penetrate through to any 'lower' layers?

For me this is totally expected behaviour, for it to work any other way would be very odd!
0 Kudos
LukeRogers
New Contributor III
I can't see that this is a bug, unless I'm missing something?!

See my response here

The highlightGraphic is being added on top of the southCarolinaCounties layer thus masking it, so it is the highlightGraphic that will get the click, unless you expect the click to penetrate through to any 'lower' layers?

For me this is totally expected behaviour, for it to work any other way would be very odd!


...and this is exactly where ESRI Tech Support landed too. In hindsight that makes sense. The onClick event can only be handled by the top graphic, whatever that is, and it is handled at the map.graphics layer level and not on specific graphic features.

Here's the latest from ESRI to close out this thread:

The 'onClick' event does fire if the FeatureLayer implements both 'onMouseOver' and an 'onClick' events simultaneously. I have attached the modified application in the email in order to demonstrate the behavior.

The issue was earlier encountered due to the application workflow as explained below. (The events do work correctly.)

The problem with the original test case is that a graphic is added to the map each time when the mouse is hovered over a feature. This graphic is used to highlight the feature. Thus, when users click on the highlighted graphic you'll need to listen for the map.graphics onclick event instead.

You may note that, if the highlighted graphic is not added to the map, the events will work correctly.
0 Kudos
JonathanCruz1
New Contributor II

Thanks for your post Luke! By removing my highlighted graphic, I can execute both the "click" & "mouse-over" events on a single point graphic.

0 Kudos