Populating an info window for one layer with content from a different layer

913
7
07-24-2013 06:59 AM
BrettGreenfield__DNR_
Occasional Contributor II
I'm working on a simple map with two layers representing the same features.  One is a point layer that only displays when the user is zoomed out beyond a certain scale, and the other is a polygon layer that only displays when zoomed in far enough.  The polygon layer has all the attributes that I'd like to display in the info window, but I'd like users to be able to see this information when clicking on the point layer, and I'm not sure how to accomplish this.  I tried removing the min/max scale from the polygon layer, and that does work, but since some of the polygons are rather small (especially when zoomed out), it's difficult to move the mouse cursor directly over them when zoomed out.

Is there another way I can accomplish this?
0 Kudos
7 Replies
DerekNelson
New Contributor II
Howdy,
Have you tried a "spatial join" under analysis toolbar? this should allow you to basically add the attribute data from one to the other based on spatial location and that way when someone clicks info on a point it will show the attribute data for corresponding polygon...http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00080000000q000000...should help you with the process
0 Kudos
SteveCole
Frequent Contributor
You don't really describe the origin of the point version but....

The easiest option might be to convert the polygons to points using ArcToolbox. This way all the attributes are carried over to the point features. In your web map, you simply set up an infoWindow for the points and then another for the polygon layers. Using the scale based visibility for the two layers, everything should work fairly easily.

If the points are the centroid locations of the polygons, I guess once a user clicks on a point, you can use that shape and query the polygon features to retrieve the actual attribute content (buffer the point's extent slightly, though).

A third option (but a maintenance PITA) would be to attach the feature IDs of the polygons to its point representation. Once again, when a user clicks on the point representation, you retrieve the feature ID of the polygon version and then perform the query based on the feature ID.

I think the 1st option would be the easiest to implement.

Steve
0 Kudos
BrettGreenfield__DNR_
Occasional Contributor II
Sorry, yeah, the points are centroids of the polygons.  They were only created to make the features more noticeable when zoomed out.

While I agree your first option would be easiest, since I have to go through another person to update our services (and I've already bugged her enough about this particular project!) I was hoping I could do through the JS.  It sounds like your second option would work for that...I think I have an idea of how it might work.
0 Kudos
ChristopherBlinn1
Occasional Contributor III
I'm working on a simple map with two layers representing the same features.  One is a point layer that only displays when the user is zoomed out beyond a certain scale, and the other is a polygon layer that only displays when zoomed in far enough.  The polygon layer has all the attributes that I'd like to display in the info window, but I'd like users to be able to see this information when clicking on the point layer, and I'm not sure how to accomplish this.  I tried removing the min/max scale from the polygon layer, and that does work, but since some of the polygons are rather small (especially when zoomed out), it's difficult to move the mouse cursor directly over them when zoomed out.

Is there another way I can accomplish this?


Brett,

There are a couple approaches you can take to accomplish this.

First, if you have access to the data, you could do a spatial join in ArcMap and create a point layer with the attributes of the polygon layer.  This is the simplest approach, but of course relies on your access to the data and GIS services.

Second, you could perform a query on the polyon layer during the click event.  The click event would fire the query and send the event coordinates to the geometry parameter of the query.  Look at this blog post which provides some sample code for creating a tolerance on your clicked point.  The trick will be querying the polygon layer rather than the point layer.  Your click point tolerance will create a small area which intersects the polygon (visible or not), returning results from the polygon layer, but your user won't know that since they are clicking a "point".

Hope this helps!

Best,
Chris B.
0 Kudos
TyroneLigon
Occasional Contributor
How about rolling your own point layer? Create a graphics layer and add it to the map. When the polygon layer finishes loading:

  • Run a function to loop through each polygon feature

  • Grab the polygon's geometry and create a point from the centroid

  • Create an attribute object from the polygon's attributes

  • Create a point graphic by using the centroid, a symbol, and the attribute object you just created

  • Add the point graphic to the graphics layer


All my development is on an intranet so I don't have any code to provide, but this shouldn't be too difficult to do (famous last words).
0 Kudos
JasonZou
Occasional Contributor III
I would echo Steve's second option. It's more flexible, and not bother to make duplicate attributes in two feature classes.

Jason Z.
0 Kudos
JacksonGilman1
New Contributor III
Untested, but possible concept:

define(['dojo/on', 'dojo/_base/lang', 'esri/tasks/query'], function (on, lang, Query) {
    /**
     * @param {esri.Map} map
     * @param {esri.layers.FeatureLayer} pointLayer
     * @param {esri.layers.FeatureLayer} polyLayer
     * @return removable handle
     */
    function tiePointLayerToPolygons(map, pointLayer, polyLayer) {
        /**
         * Callback for clicks on point layer.
         * @param {MouseEvent} evt
         * @param {esri.Graphic} evt.graphic - the graphic which was clicked.
         */
        var query = function (evt) {
            var iw = map.infoWindow,
                pt = evt.graphic.geometry;
            
            // return if no window
            if (!iw) {
                return;
            }

            polyLayer.queryFeatures(lang.mixin(new Query(), {
                    geometry: pt,
                    spatialRelationship: Query.SPATIAL_REL_CONTAINS

                })).then(function (featureSet) {
                    // assuming info window is popup...if not this will need tweaking
                    iw.setFeatures(featureSet.features);
                    // show infow window at the clicked point
                    iw.show(pt);
                });
        };
        
        // listen to clicks on point layer.
        return on(pointLayer, 'click', query);
    }

    return tiePointLayerToPolygons;
    
});
0 Kudos