<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Question regarding GraphicsLayer.Graphics.Contains in ArcGIS API for Silverlight Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/question-regarding-graphicslayer-graphics-contains/m-p/218353#M5467</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for your answer Dominique!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Unfortunately I can't use your solution since I can't guarantee that this field will be included.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have been testing my add-in against one of your sample services:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer"&gt;http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This service doesn't include any objectIds, and I can't be sure that our clients services will be either. Hardcoding parameters in any way is something I'd like to avoid as much as possible. Is there any other way? Would looping through the attributes, comparing each one be a possible solution? Seems a bit inefficient.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there any failsafe solution to approach this?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 28 Jun 2013 10:26:08 GMT</pubDate>
    <dc:creator>JohanCarlsson</dc:creator>
    <dc:date>2013-06-28T10:26:08Z</dc:date>
    <item>
      <title>Question regarding GraphicsLayer.Graphics.Contains</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/question-regarding-graphicslayer-graphics-contains/m-p/218351#M5465</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've created an add-in to query FeatureLayers and ArcGISDynamicMapServiceLayers.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Querying the different kinds of layers works great, but I've run into a problem and I can't seem to find a solution.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When the user queries a layer based on certain criteria, I bind the returned FeatureSet to a datagrid. The user can then select which rows they want to display in the map by marking them in the datagrid and then clicking a button that adds them to the map (in a layer that is named the same as the queried sub layer) and zooms to the result. Clicking a Graphic object in the datagrid when it is displayed in the map also changes symbology.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I add each Graphic to the layer, I first check if the layer already contains the graphic:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GraphicsLayer layer = LayerExists(layerName); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!layer.Graphics.Contains(g)) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer.Graphics.Add(g);&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The function LayerExists checks if the selected layer name already exists, if it does, it is returned. If it doesn't exist, it is created.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If I try to add the same Graphic twice (without closing the window that the&amp;nbsp; tool opens), layer.Contains(g) works fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;However, if I close the window, open it up again, perform the same query and try to add the same Graphic object, it adds a duplicate to that layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried solving this by comparing geometries:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bool layerContainsGraphic = false; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach (Graphic graphicInLayer in layer.Graphics) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (graphicToAdd.Geometry == graphicInLayer.Geometry) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layerContainsGraphic = true; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!layerContainsGraphic) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer.Graphics.Add(graphicToAdd);&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;but I still encounter the same problem, layerContainsGraphic is never true. The geometries never match, even though they are identical; same WKID, same extent etc. I then tried using GetHashCode, and the geometries return different hash codes. Why is that?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also tried comparing attribute collections, but it yields the same result as above.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry for the wall of text, please tell me if something in my explanation is unclear and I'll try to be clearer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Johan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Jun 2013 07:07:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/question-regarding-graphicslayer-graphics-contains/m-p/218351#M5465</guid>
      <dc:creator>JohanCarlsson</dc:creator>
      <dc:date>2013-06-28T07:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: Question regarding GraphicsLayer.Graphics.Contains</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/question-regarding-graphicslayer-graphics-contains/m-p/218352#M5466</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Running a new query returns new instances of the features so a test on layer.Graphics.Contains doesn't detect the duplicates.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can base your test on the objectID. By supposing the OBJECID of your feature layer is "ObjectId" you could try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var id = g.Attributes["ObjectId"];
if (!layer.Graphics.Any(graphic =&amp;gt; graphic.Attributes["ObjectId"] == id)) ......&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:39:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/question-regarding-graphicslayer-graphics-contains/m-p/218352#M5466</guid>
      <dc:creator>DominiqueBroux</dc:creator>
      <dc:date>2021-12-11T10:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: Question regarding GraphicsLayer.Graphics.Contains</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/question-regarding-graphicslayer-graphics-contains/m-p/218353#M5467</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for your answer Dominique!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Unfortunately I can't use your solution since I can't guarantee that this field will be included.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have been testing my add-in against one of your sample services:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer"&gt;http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This service doesn't include any objectIds, and I can't be sure that our clients services will be either. Hardcoding parameters in any way is something I'd like to avoid as much as possible. Is there any other way? Would looping through the attributes, comparing each one be a possible solution? Seems a bit inefficient.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there any failsafe solution to approach this?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Jun 2013 10:26:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/question-regarding-graphicslayer-graphics-contains/m-p/218353#M5467</guid>
      <dc:creator>JohanCarlsson</dc:creator>
      <dc:date>2013-06-28T10:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Question regarding GraphicsLayer.Graphics.Contains</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/question-regarding-graphicslayer-graphics-contains/m-p/218354#M5468</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0?f=pjson" rel="nofollow" target="_blank"&gt;layers &lt;/A&gt;&lt;SPAN&gt;you pointed out do have an ObjectId but called 'FID'.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You could loop on the layer fields, look for a field of type OID and then use this field as Identifier.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It's not 100% guarantee but...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Jun 2013 11:05:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/question-regarding-graphicslayer-graphics-contains/m-p/218354#M5468</guid>
      <dc:creator>DominiqueBroux</dc:creator>
      <dc:date>2013-06-28T11:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: Question regarding GraphicsLayer.Graphics.Contains</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/question-regarding-graphicslayer-graphics-contains/m-p/218355#M5469</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The &lt;A href="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0?f=pjson"&gt;layers &lt;/A&gt;you pointed out do have an ObjectId but called 'FID'.&lt;BR /&gt;You could loop on the layer fields, look for a field of type OID and then use this field as Identifier.&lt;BR /&gt;&lt;BR /&gt;It's not 100% guarantee but...&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you, this works so far!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Jun 2013 12:41:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/question-regarding-graphicslayer-graphics-contains/m-p/218355#M5469</guid>
      <dc:creator>JohanCarlsson</dc:creator>
      <dc:date>2013-06-28T12:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: Question regarding GraphicsLayer.Graphics.Contains</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/question-regarding-graphicslayer-graphics-contains/m-p/218356#M5470</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;For anyone else that is wondering, I grabbed the ObjectIdFieldName from the FeatureSet returned from the query and checked if any graphic on the currently selected layer matched this attribute.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;int uniqueId = Convert.ToInt32(graphicToAdd.Attributes[StaticVariables.ObjectIdFieldName]);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private static bool LayerContainsObject(GraphicsLayer layer, int uniqueId)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach (Graphic g in layer)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (Convert.ToInt32(g.Attributes[StaticVariables.ObjectIdFieldName]) == uniqueId)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:39:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/question-regarding-graphicslayer-graphics-contains/m-p/218356#M5470</guid>
      <dc:creator>JohanCarlsson</dc:creator>
      <dc:date>2021-12-11T10:39:58Z</dc:date>
    </item>
  </channel>
</rss>

