Select to view content in your preferred language

How to add the ability to pulse/flash a feature class when hovering within a pre-configured distance

461
1
09-05-2018 03:57 AM
ScottHansen__MDP_
Frequent Contributor

I am looking for the ability to hover over a feature class and for that feature class to pulse or flicker.

I have a statewide layer consisting of transit station areas (half-mile buffer from transit station) and Census block groups. In the past I would have these layers loaded in my map and the user could turn all of them on or off. I configured the feature class to appear at a specific zoom extent, but this isn't a great user experience. For starters, anyone that lives in an urban may know that transit stops can be located close together and corresponding station area buffers and Census Block may overlap. A user may accidentally select several locations within close proximity.  I would like a user to be able to hover on a single station and immediately see a pulsing half-mile station area buffer as well as all of the Census block groups which intersect that buffer. Attached is an example of the 2 feature classes and how they appear on a static thematic map. Your help is greatly appreciated.

0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Emeritus

Scott,

   This is a bit of a complex workflow. To start I strongly discourage using hover events in most applications, the amount of processing that has to happen on each mouse move can make the app cumbersome and lag depending on the number and complexity of the features that are being used for the hover. The best solution is almost always a mouse click instead.

If you load your transit station areas to the map with a SimpleFillSymbol and a nearly transparent fill then you can add a mouseover event to this FeatureLayer that would select the transit station area polygon using the FeatureLayer.selectFeatures method. Now with the selection symbol for that feature set to something with a solid fill you would see the transit station area and at the same time you can use the features graphic from the mouseover event to do a query on the census block map service and return the intersecting blocks and add them to the map as graphics.

What can be cumbersome is the mouseout portion to unselect the transit station area and remove the block graphics. I always use a setTimeout on the mouseout to be sure the user did not just accidentally move the mouse out and right back into the same transit station area polygon. That brings up another point. in the mouseover handler you need to check if the transit station area polygon is the same as the one currently selected (if there is one selected) and if it is exit the handler. 

0 Kudos