<?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: Dynamically adding/removing GraphicOverlays in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/dynamically-adding-removing-graphicoverlays/m-p/1258893#M11687</link>
    <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/256344"&gt;@MatveiStefarov&lt;/a&gt;&amp;nbsp;for your quick response and detailed reply!&lt;/P&gt;</description>
    <pubDate>Thu, 16 Feb 2023 15:17:45 GMT</pubDate>
    <dc:creator>BrianLoehr</dc:creator>
    <dc:date>2023-02-16T15:17:45Z</dc:date>
    <item>
      <title>Dynamically adding/removing GraphicOverlays</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/dynamically-adding-removing-graphicoverlays/m-p/1258762#M11685</link>
      <description>&lt;P&gt;I'm using Esri.ArcGISRuntime.Maui v200.0.0. Admittedly I am new to using Esri so maybe there is a more obvious solution: I am wanting to dynamically add&amp;nbsp; and remove site pins on the map. First attempt was to reuse the initial set of Graphic objects and just build a new GraphicsOverlay and only add the Graphics desired. Then null out the GraphicsOverlays collection and add a new one. This resulted in the Object Already Owned exception.&lt;/P&gt;&lt;P&gt;Second attempt is to create a new GraphicsOverlay along with a new Graphic object for each item and add it to the GraphicsOverlays collection. Removing a GraphicOverlay is as simple as identifying the particular GraphicOverlay and removing it from the GraphicOverlays collection. In this manner I can add and remove as many as desired.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The question is - is this a viable way to perform the action I desire? Will there be significant memory or performance issues if adding 100's or 1000's of objects?&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// code from view model (using MVVM)

private static SimpleMarkerSymbol _pinSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Diamond, Color.OrangeRed, 12);

private static readonly MapPoint[] _sitePoints = new[]
        {
            new MapPoint(-97.7805, 30.4027, SpatialReferences.Wgs84),
            new MapPoint(-97.8005, 30.4227, SpatialReferences.Wgs84),
            new MapPoint(-97.8205, 30.4427, SpatialReferences.Wgs84),
            new MapPoint(-97.8100, 30.4227, SpatialReferences.Wgs84),
            new MapPoint(-97.7900, 30.4027, SpatialReferences.Wgs84)
        };

private void AddPin()
{
    if (GraphicsOverlays == null)
        return;

    if (GraphicsOverlays.Count == 5)
        return;

    // how many pins right now?
    var pinCount = GraphicsOverlays.Count;
    var newPinIndex = pinCount;

    var pinOverlay = new GraphicsOverlay();
    var newGraphic = new Graphic(_sitePoints[newPinIndex], _pinSymbol);
    pinOverlay.Graphics.Add(newGraphic);
    GraphicsOverlays.Add(pinOverlay);
}

private Task RemoveLatestPinLocation()
{
    if (GraphicsOverlays == null)
        return Task.CompletedTask;

    int count = GraphicsOverlays.Count;
    if (count == 0)
        return Task.CompletedTask;

    // update overlay
    var removePinIndex = count - 1;
    var overlayToRemove = GraphicsOverlays.ElementAt(removePinIndex);
    if (overlayToRemove == null)
        return Task.CompletedTask;

    GraphicsOverlays.Remove(overlayToRemove);

    return Task.CompletedTask;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 01:24:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/dynamically-adding-removing-graphicoverlays/m-p/1258762#M11685</guid>
      <dc:creator>BrianLoehr</dc:creator>
      <dc:date>2023-02-16T01:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically adding/removing GraphicOverlays</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/dynamically-adding-removing-graphicoverlays/m-p/1258815#M11686</link>
      <description>&lt;P&gt;Graphic is an interactive object -- adding it to an overlay does not merely make a copy.&amp;nbsp; You can keep changing a Graphic after it's added to an overlay, and it will reflect changes to geometry and attributes.&amp;nbsp; A Graphic can only belong to one Overlay at a time.&amp;nbsp; If you want to move it from one overlay to another, remove it from the first overlay before adding to the second -- this avoids the "object already owned" exception.&lt;/P&gt;&lt;P&gt;GraphicsOverlays are similar.&amp;nbsp; They belong to one GeoView at a time, and you can keep interacting with an overlay (e.g. adding/removing Graphics) after it's been added to a GeoView.&amp;nbsp; Remove it first if you want to move to a different GeoView.&lt;/P&gt;&lt;P&gt;In general, reusing Graphics is probably not worth the effort until you get into hundreds of updates &lt;EM&gt;per second&lt;/EM&gt;.&amp;nbsp; You can create new ones on demand.&amp;nbsp;&amp;nbsp;However I do recommend using a Renderer on the overlay instead of assigning symbols to individual graphics.&lt;/P&gt;&lt;P&gt;GraphicsOverlays are heavier objects, but you shouldn't need too many of them.&amp;nbsp; One overlay can hold unlimited number of Graphics, and you can keep adding/updating/removing Graphics as needed.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 09:56:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/dynamically-adding-removing-graphicoverlays/m-p/1258815#M11686</guid>
      <dc:creator>MatveiStefarov</dc:creator>
      <dc:date>2023-02-16T09:56:23Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically adding/removing GraphicOverlays</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/dynamically-adding-removing-graphicoverlays/m-p/1258893#M11687</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/256344"&gt;@MatveiStefarov&lt;/a&gt;&amp;nbsp;for your quick response and detailed reply!&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 15:17:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/dynamically-adding-removing-graphicoverlays/m-p/1258893#M11687</guid>
      <dc:creator>BrianLoehr</dc:creator>
      <dc:date>2023-02-16T15:17:45Z</dc:date>
    </item>
  </channel>
</rss>

