aconnolly

Issue with Popup and multiple graphics (features)

Discussion created by aconnolly on May 22, 2012
Latest reply on May 29, 2012 by map12
Hello,

I'm creating and adding a pop up to my map that displays a graphic's attributes or the individual attributes for a set of graphics using the left/right arrows. I'm basing my work off this sample:

http://help.arcgis.com/en/webapi/javascript/arcgis/demos/find/find_popup.html

I've got this *mostly* working. For a single symbol on the map, the pop up works well. But when I have multiple symbols at one location the initial click on the symbol brings up an empty pop up window, with one right-arrow. It looks like the pop up doesn't load the very first graphic's attributes, nor does it know how many graphics were loaded.

When I add the graphics to the map I store an array of attribute objects when I'm dealing with multiple points at one location and then add one graphic to the map. I know then to look for an attribute array when I listen for the layer's onClick event. Next, I create a new graphic for each attribute in the array and send the graphics array to the setFeatures method.

Why does the popup not load the first graphic's attributes? If I have 5 records at one location the pop up opens with no attribute data and provides me with a right-arrow. Clicking the right arrow will show me the second attribute object and the title then correctly reads (2 of 5) and also gives me a left-arrow. Clicking the left arrow will display the first attribute object that should have been displayed on the original click.

Here is my click event handler and yes I know I'm creating a graphics array and adding that to the popup rather than the results of a task. setFeatures takes a Graphic[] so it shouldn't matter how it gets those graphics, right?

Any thoughts?


    dojo.connect(crimeGraphicsLayer, "onClick", function(evt){
           
           // create lits of graphics from attribute array
           var graphics = [];

           if (evt.graphic.attributes.length != undefined && evt.graphic.attributes.length > 0)
           {
                for(var i=0;i < evt.graphic.attributes.length; i++)
                {   
                    graphics.push(new esri.Graphic(evt.graphic.geometry, evt.graphic.symbol, evt.graphic.attributes[i], popupTemplate));
                }
           }
           else
           {    
                graphics.push(evt.graphic);
           }
           
           map.infoWindow.show(graphics[0].geometry);
           map.infoWindow.setFeatures(graphics);
    });



Thanks,
- Aaron

Outcomes