Select to view content in your preferred language

Comparing Graphics

1004
2
Jump to solution
10-25-2012 10:05 AM
KennyWebster
Deactivated User
Hey guys.

Currently working on a widget that allows users to perform queries on specific layers and have the results displayed on the map stored in graphics layer.

Part of the functionality that I need to give to the users is the ability to perform a query to REMOVE items from the above mentioned graphics layer.  I've accomplished this functionality by comparing the returned featureSet.features array with the graphicslayer.graphicsProvider array and using the geometry.toString method to perform the comparison.  However, this tends to be slow (these are fairly big strings) for larger queries.  Any suggestions on a better way to compare the graphics or a better way to get this functionality entirely?

private function removeSelected(queryResults:Array):void  {   for each (var iGr:Graphic in queryResults)   {    for each (var gr:Graphic in resultsGraphicsLayer.graphicProvider)    {     if (iGr.geometry.toString() == gr.geometry.toString())     {      resultsGraphicsLayer.remove(gr);     }    }   }   cursorManager.removeBusyCursor();  }
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DasaPaddock
Esri Regular Contributor
Try this:

private function removeSelected(queryResults:Array):void     {         for each (var iGr:Graphic in queryResults)         {             for each (var gr:Graphic in resultsGraphicsLayer.graphicProvider)             {                 if (ObjectUtil.compare(iGr.attributes, gr.attributes) == 0)                 {                     resultsGraphicsLayer.remove(gr);                     break;                 }             }         }         cursorManager.removeBusyCursor();     }


I've added a break; and am using ObjectUtil.compare() on the attributes assuming the attributes are being requested and are different enough from layer to layer. You could compare the geometries instead but it may be a little slower.

If you knew which features in the graphics layer were from which layers, you could just compare their object id fields.

See:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/utils/ObjectUtil.html

View solution in original post

0 Kudos
2 Replies
DasaPaddock
Esri Regular Contributor
Try this:

private function removeSelected(queryResults:Array):void     {         for each (var iGr:Graphic in queryResults)         {             for each (var gr:Graphic in resultsGraphicsLayer.graphicProvider)             {                 if (ObjectUtil.compare(iGr.attributes, gr.attributes) == 0)                 {                     resultsGraphicsLayer.remove(gr);                     break;                 }             }         }         cursorManager.removeBusyCursor();     }


I've added a break; and am using ObjectUtil.compare() on the attributes assuming the attributes are being requested and are different enough from layer to layer. You could compare the geometries instead but it may be a little slower.

If you knew which features in the graphics layer were from which layers, you could just compare their object id fields.

See:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/utils/ObjectUtil.html
0 Kudos
KennyWebster
Deactivated User
Try this:

private function removeSelected(queryResults:Array):void
    {
        for each (var iGr:Graphic in queryResults)
        {
            for each (var gr:Graphic in resultsGraphicsLayer.graphicProvider)
            {
                if (ObjectUtil.compare(iGr.attributes, gr.attributes) == 0)
                {
                    resultsGraphicsLayer.remove(gr);
                    break;
                }
            }
        }
        cursorManager.removeBusyCursor();
    }


I've added a break; and am using ObjectUtil.compare() on the attributes assuming the attributes are being requested and are different enough from layer to layer. You could compare the geometries instead but it may be a little slower.

If you knew which features in the graphics layer were from which layers, you could just compare their object id fields.

See:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/utils/ObjectUtil.html


I tried the objectUtil.compare but didn't seem to work all that well, there were some features here and there that seemed to not match up correctly.

Your second idea, worked well tho.  I hadn't been returning the objectid's in the queries since I didn't really need them.  Since when the user switches layers it automatically clears the graphicslayer that worked perfectly.  I just reconfigured the query to return the objectid and am now using that to compare.  Works perfectly and much quicker!

iGr.attributes.OBJECTID == gr.attributes.OBJECTID
0 Kudos