Possible to Mouse-Over and Display Two Different Layers?

704
5
11-18-2017 01:40 PM
RandyMorris
New Contributor II

I have a map that has a neighborhoods layer. When I mouse-over, the neighborhood outline lights up and data is displayed in a side-window popup. I would like to add a census tracts layer to the map. Would it be possible to display the outlines of both layers simultaneously on mouse-over, and show data from the census layer in a second div in the side-window? 

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus

Randy,

  The top layer is going to be the only layer that will interact with mouse events so the easy answer is no. But you could do some Query to get the census layer attributes that intersect with the neighborhood polygon when the neighborhood polygon changes.

0 Kudos
deleted-user-1_r2dgYuILKY
Occasional Contributor III

Hi Robert, I'm working with Randy on this project. We definitely don't want to intersect the data. We just want to show visually where they overlap, and display attributes from both layers. Would it be possible to merge them into a multi-part polygon and retain both boundaries?

0 Kudos
ThomasSolow
Occasional Contributor III

This is definitely possible, though you may not be able to use layer events, I'm not sure.

The approach I would take is to make sure both of your layers have a fullExtent set on them.  This property is part of the feature service. If this is set, you can set this up manually pretty easily, ie: on mouse move, check for intersection with neither, both, or one of the fullExtents on your data sets and then highlight them accordingly and fill in information in the side popup.

In terms of merging two extents, you can do this using the geometry engine union function in order to merge two polygons or two extents however you like (I would guess two extents should normally be merged into a polygon, unless one totally contains the other).

Here's simple example showing how to test for intersection with a feature layer's fullExtent on mouse-move and draw the fullExtent if the mouse is inside.   JS Bin - Collaborative JavaScript Debugging 

It should be pretty simple to extend this so it works on however many layers you need and it merges the extents of all layers being intersected using geometryEngine.union. In terms of how you handle the side popup, I don't really know what that would involve, whether there's a pre-existing tool you're using or if it's something you've built yourselves.

0 Kudos
SteveCole
Frequent Contributor

The mouse over event also gives you a map point object so you could query your census layer while inside the neighborhood mouse over event for the pertinent information and then add it to your side panel along with the neighborhood information.

RandyMorris
New Contributor II

Thanks to everyone who has responded so far.  We'll be sure to let you know what our final result is if we can get it to where we want it.