turbines loading affect animation and add Mutiple times

Eduardo Gomez Romero 1,355 Reputation points
2024-11-27T21:24:51.3066667+00:00

So, the little bug that I have is that the turbines take a long time, hance the map take time to load

and the turbines get re-added, every time I come back to this page

 public ObservableCollection<TurbinePin> TurbinePins { get; set; } = [];

 public ObservableCollection<MapTypeButton> MapTypeButtons { get; set; } = [];

 public ChargingStationsMapPageViewModel(TurbinesService turbinesService, IServiceProvider serviceProvider)
 {
     MapDialogButtons();
     _turbineServices = turbinesService;

     _serviceProvider = serviceProvider;
 }

 private void MapDialogButtons()
 {
     MapTypeButtons.Add(new MapTypeButton
     {
         Caption = "Default",
         ImageName = FontAwesome.Road,
         Selected = true,
         MapNumber = 1
     });
     MapTypeButtons.Add(new MapTypeButton
     {
         Caption = "Satellite",
         MapNumber = 2,
         ImageName = FontAwesome.StreetView,
     });
 }

 private async Task LoadTurbinePins()
 {
     TurbinePins.Clear();

     await _turbineServices.InitializeAsync();
     var turbinePins =
         await _turbineServices.GetTurbinePinsForUI(PinMarkerClickedCommand);

     foreach (var pin in turbinePins)
     {
         TurbinePins.Add(pin);
     }
     Loaded = true;
 }
 [RelayCommand]
 private async Task AppearingAsync(Map map)
 {
     MapView ??= map;
     await LoadTurbinePins();
 }




Also, the app takes some time to show the pins, So I don't know if I should call then service in the shell or the app.cs

https://1drv.ms/u/s!AuPWj2VdUNuhv-pSHEimcy0DhVcKzQ?e=5RGO1C

Also, when I navigate thru tabs, I can see the last tab (on phones) for 2 seconds

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2024-11-28T03:04:18.17+00:00

    Hello,

    So, the little bug that I have is that the turbines take a long time, hance the map take time to load

    This is not a bug, but expected behavior.

    Since you load the data in the OnAppearing method of the page, it will be reloaded from the network request on every page load.

    LoadTurbinePins is a very expensive method, which contains service initialization and two collection traversals.

    You should try to reduce the number of executions of this method. For example, you can write data to a local file, and if the local file already exists, read the data from the local file. If the user does not update the data, there is no need to initiate a network request again.

    You can refer to the documentation provided by .net on how to serialize objects to json files and deserialize from json files to objects.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.