SfMap only allows adding of new dynamic markers, removing markers causes errors.

Is it not possible to dynamically remove markers from the SfMap component like you can add them? Seems kind of pointless to not support this feature if not.

I have an ObservableCollection of MarkerData that works fine. When I add to that collection it works fine and renders properly. When I try to remove an element or clear the collection I get errors. I'm using 19.1.0.59. 


crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
   at System.Collections.Generic.List`1[[System.Object, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].get_Item(Int32 index)
   at Syncfusion.Blazor.Maps.Internal.MarkerRender.<>c__DisplayClass11_0.<RenderSecondaryElements>b__0(RenderTreeBuilder builder)
   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
   at Syncfusion.Blazor.Maps.Internal.MarkerRenderer.BuildRenderTree(RenderTreeBuilder __builder)
   at Microsoft.AspNetCore.Components.ComponentBase.<.ctor>b__6_0(RenderTreeBuilder builder)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()

5 Replies 1 reply marked as answer

SB Swetha Babu Syncfusion Team May 5, 2021 01:47 PM UTC

Hi Dylan, 
 
Thank you for contacting Syncfusion support. 
 
We are not able to reproduce the reported issue. We are able to remove the marker one by one using the “RemoveAt()” method in ObservableCollection and remove all the markers at a time by using the “Clear()” method. However, we have created the Blazor web assembly application with the latest version(v19.1.0.59) to demonstrate the same and it can be downloaded from the below link. 
 
 
In the above application, we have rendered the OSM map with dynamically adding the marker and two buttons named “Remove Marker” and Remove all Marker”. If we click on the “Remove Marker” button, the marker gets removed one by one and if we click on the “Remove all Marker” button, all the markers get removed. Please let us know if the above application meets your requirement. If you are still facing the reported issue, please modify the above application to reproduce the reported issue and share the same to us. It will be helpful for us to analyze further and assist you better. 
 
Regards, 
Swetha Babu


TT tttrickyyy replied to Swetha Babu May 12, 2021 07:18 PM UTC

Hi Dylan, 
 
Thank you for contacting Syncfusion support. 
 
We are not able to reproduce the reported issue. We are able to remove the marker one by one using the “RemoveAt()” method in ObservableCollection and remove all the markers at a time by using the “Clear()” method. However, we have created the Blazor web assembly application with the latest version(v19.1.0.59) to demonstrate the same and it can be downloaded from the below link. 
 
 
In the above application, we have rendered the OSM map with dynamically adding the marker and two buttons named “Remove Marker” and Remove all Marker”. If we click on the “Remove Marker” button, the marker gets removed one by one and if we click on the “Remove all Marker” button, all the markers get removed. Please let us know if the above application meets your requirement. If you are still facing the reported issue, please modify the above application to reproduce the reported issue and share the same to us. It will be helpful for us to analyze further and assist you better. 
 
Regards, 
Swetha Babu

Your example does not work if you are templating the markers. See this as reference:
               <MarkerTemplate>
                        @{

                            var data = context as MarkerData;
                            <div>@data.latitude </div>
                        }
                    </MarkerTemplate>

After you click on any of the remove buttons, you receive the error index out of range. Please help!



DL Dylan Lyon May 12, 2021 07:56 PM UTC

Thank you tttrickyyy, I had gotten distracted by some other things and was going to mention the same thing. The code that syncfusion provided above works great but it does not seem to work with custom templates for markers like you say. 


SB Swetha Babu Syncfusion Team May 13, 2021 05:54 PM UTC

Hi Dylan, 
 
Thank you for your update. 
 
We are able to reproduce the reported issue in the Maps component. We have considered this as a defect and logged a defect report for the same. We will include the fix for the reported issue in our weekly patch release which is expected to be available by the start of June, 2021. However, please find the below feedback link to keep track of the reported issue. 
 
 
Regards, 
Swetha Babu


SB Swetha Babu Syncfusion Team June 1, 2021 10:14 AM UTC

Hi Dylan, 
 
Thank you for your patience. 
 
We have included the fix for the reported issue - "Adding markers dynamically and removing causes error" in our weekly NuGet release(v19.1.0.66). Please upgrade the "Syncfusion.Blazor.Maps" package to the latest version to resolve the reported issue. 
 
Please let us know if you need any further assistance. 
 
Regards, 
Swetha Babu

Marked as answer
Loader.
Up arrow icon