Difficulty coordinating Hover and Click events

2207
6
Jump to solution
03-15-2013 08:39 AM
CharlesGeiger
New Contributor III
I have three map services of my university campus: The first is a tiled map service with buildings, roads, parking lots, etc. for background.  The second is added as a dynamicMapServiceLayer, with 6 layers controlled by checkboxes in the HTML (the layers show information relevant to ADA accommodations).  The user can turn on layer(s) via the checkboxes and then click on any feature's symbol (except 2 layers have no attributes) to get a Popup InfoWindow about that feature.

The third map service has one layer, a repeat of the buildings layer, added as a graphicsLayer with complete transparency. The user hovers over features to see the building name in the Popup InfoWindow.

My problem is that the behavior reacting to mouse hover and click actions is inconsistent and unpredictable, especially when attempting to click on symbols within buildings such as elevators and restrooms.  I am sure someone will say "it's behaving the way you programmed it," but I would appreciate any ideas for making it behave consistently.

The code is over 250 lines, but here is a link: http://mapmaker.millersville.edu/MUmaps/ADAversion2/

Thank you for any help.
0 Kudos
1 Solution

Accepted Solutions
JohnGravois
Frequent Contributor
you have an event wired up to display popups when people mouse over the buildings, now you just need to add another one to listen for when the mouse leaves

dojo.connect(featureBldgLayer, "onMouseOut", function(evtBldg) {     dijit.popup.close(); });

View solution in original post

0 Kudos
6 Replies
JohnGravois
Frequent Contributor
i think the problem you're having is caused by the hierarchy of events.

1.  clicking on the map fires an identify task
2.  clicking on client side graphics (like the invisible building graphics) shows a popup without making another server call (because of event wiring for map.graphics)
3.  hovering over a building graphic also displays its popup.

the reason why you can't fire an identify to populate the popup for a restroom when you click on one inside a building is because the graphic mouse event takes priority over the map click event.

heres my recommendation for solving this problem..

load each layer people need to interact with as an ON_DEMAND or SNAPSHOT featureLayer).  This way you can let our API ensure that all relevant features (there aren't really a lot of them) are downloaded as client graphics automatically (you don't even have to worry about writing out a QueryTask.

The benefit of this approach is that you can get control over the order in which the graphics are drawn in the map (by the order you add them in programmatically) to ensure that the point features draw "on top" of the building polygon features.

This way clicking on the points will return information about the points, and you can skip the identify task entirely...
0 Kudos
CharlesGeiger
New Contributor III
Thanks, jgravois.  I have spent the last couple of days trying to get my graphicsLayer to work as a featureLayer, with no success. I am not able to imitate the samples very well because I have a different spatial reference and I am not sure how to overlay my map service with the arcgis online data.  I have also looked at other forums for ideas.  The samples I have seen have raised a couple of questions:

1. It appears that featureLayer perfers a feature service (which I do not have the ability to create yet), but can use a map service.  Please correct me if this isn't right.

2. I haven't seen a sample with a ArcGISTiledMapServiceLayer loaded before the featureLayer, so I am worried about some kind of conflict between the two.  I need the tiled layer, though, because of custom zoom levels.

I would really like to read some kind of extended description about capabilities and strategies with feature layers, but haven't found anything.
0 Kudos
JohnGravois
Frequent Contributor
please don't hesitate to post a simplified sample, i'd be happy to take a look.

1. It appears that featureLayer perfers a feature service (which I do not have the ability to create yet), but can use a map service. Please correct me if this isn't right.


they are identical, with the exception that feature services give you the opportunity to expose feature editing in your app (which you aren't currently doing).

2. I haven't seen a sample with a ArcGISTiledMapServiceLayer loaded before the featureLayer, so I am worried about some kind of conflict between the two. I need the tiled layer, though, because of custom zoom levels.


its standard practice to load a tiled map service first.  (if the feature layer uses a different coordinate system it will preproject on the fly).  check out this sample.  (it loads our world streetmap as the tiled map service layer using the new technique of specifying the name of the basemap directly in the map constructor.

I would really like to read some kind of extended description about capabilities and strategies with feature layers, but haven't found anything.


check out this article
0 Kudos
CharlesGeiger
New Contributor III
It has been a long time between posts, but this has taken quite a bit of time to work out.  Your advice did get me the functionality I needed.  I am having one small problem, minor enough that I will probably use the project as-is if there is no answer for it.  Here is the test webpage:
  http://mapmaker.millersville.edu/mumaps/ADAversion3/index.html

One decision I made, which I would appreciate any comments on, was to give each featureLayer a separate "evt" identification (evtBldg, evt0, evt1, etc), not because of any functional problem but just because it seemed to me that conflicts could arise.

Anyway, the issue that I am having is that the hover tooltip does not disappear when the mouse moves off of the building feature.  The code to do so is there, and it was working before I got all of the other featureLayers implemented, but now it doesn't.

Once I get a reply to this question, I will mark this thread as answered.

By the way, for future reference, once the new version becomes the permanent version, the web address will be:
  http://mapmaker.millersville.edu/MUmaps/MU_ADACompliance/
0 Kudos
JohnGravois
Frequent Contributor
you have an event wired up to display popups when people mouse over the buildings, now you just need to add another one to listen for when the mouse leaves

dojo.connect(featureBldgLayer, "onMouseOut", function(evtBldg) {     dijit.popup.close(); });
0 Kudos
CharlesGeiger
New Contributor III
Perfect!  Thank you so much! I had had a more generic popup close function, from the sample, but it wasn't tied to the particular evt for that featureLayer  This fixed it perfectly.
0 Kudos