GraphicsLayer click event to obtain multiple graphics

911
4
02-03-2014 03:26 PM
KarenRobine
Occasional Contributor II
I've added a click event to a GraphicsLayer that has graphics from X/Y locations unrelated to Feature Layers. However, I've noticed that it's only showing a single graphic at a time. I basically need to select multiple graphics within an extent. The QueryTask forces me to point to a URL of a Feature Layer. But I don't have a Feature Layer; I only have Graphics. What gives? How can I select multiple graphics from a single Graphicslayer when the user clicks on a map? Feel like I'm missing something simple here.
0 Kudos
4 Replies
KaitlynnDavis
Occasional Contributor
Have you taken a look at this sample? It shows you how to initialize a drawing toolbar that's capable of selecting graphics within a user-defined extent (see the code's "findPointsinExtent" function)

https://developers.arcgis.com/javascript/jssamples/graphics_extent_query.html
0 Kudos
KarenRobine
Occasional Contributor II
Yes. I saw that after I posted:

        var results = [];
        dojo.forEach(map.graphics.graphics,function(graphic){
          if (extent.contains(graphic.geometry)) {
            graphic.setSymbol(highlightSymbol);
            results.push(graphic.getContent());
          }
          //else if point was previously highlighted, reset its symbology
          else if (graphic.symbol == highlightSymbol) {
            graphic.setSymbol(defaultSymbol);
          }
        });

The only problem is that it loops through all of the graphics on the map. Could be slow as I may end up with thousands of graphics. But maybe the only possible solution?
0 Kudos
KaitlynnDavis
Occasional Contributor
It's very quick with several dozen graphics, but I've never used this selection method for more than that, so I can't say if it will be ok with several thousand. Maybe you could look into implementing graduated symbols for your graphics? https://developers.arcgis.com/javascript/jssamples/renderer_graduated_polygon.html
0 Kudos
BrandonIves
New Contributor
I've added a click event to a GraphicsLayer that has graphics from X/Y locations unrelated to Feature Layers. However, I've noticed that it's only showing a single graphic at a time. I basically need to select multiple graphics within an extent. The QueryTask forces me to point to a URL of a Feature Layer. But I don't have a Feature Layer; I only have Graphics. What gives? How can I select multiple graphics from a single Graphicslayer when the user clicks on a map? Feel like I'm missing something simple here.




Take a look at this one too:

https://developers.arcgis.com/javascript/jssamples/graphics_multiple_layers.html
0 Kudos