rungwiroon / BlazorGoogleMaps

Blazor interop for GoogleMap library
MIT License
319 stars 102 forks source link

OnAfterInit not being called #253

Closed MrYossu closed 1 year ago

MrYossu commented 1 year ago

I have a map component as follows...

<GoogleMap @ref="@_map" Options="@_mapOptions" OnAfterInit="AfterMapInit" />

...and the following in my code-behind...

  private GoogleMap _map = null!;
  private MapOptions _mapOptions = null!;

  protected override async Task OnInitializedAsync() {
    _mapOptions = new MapOptions {
      Zoom = 13,
      MapTypeId = MapTypeId.Roadmap
    };
    // Other stuff here
  }

  private async Task AfterMapInit() {
    Console.WriteLine($"AfterMapInit - {Transactions.Count} transaction(s)");
    // Code to populate the map with markers
  }

When I load the page with the map on, I can see that the AfterMapInit method is not being called, so the map is not being set up. I haven't included the code in AfterMapInit as it's not relevant, as the method never gets called.

Any idea why it's not being called? Obviously I don't get a map. Thanks

valentasm1 commented 1 year ago

This one works https://github.com/rungwiroon/BlazorGoogleMaps/blob/master/ServerSideDemo/Pages/MapLegendPage.razor.cs

MrYossu commented 1 year ago

I know that one works, but that doesn't help me. Mine doesn't work!

Please don't close issues as soon as you've answered them. Maybe you think it's done with, but if my code isn't working, then it's not. Your demo works fine, but that doesn't help me fix my code, which was copied from your demo.

Please can you explain under what circumstances AfterMapInit doesn't get fired.

Thanks

valentasm1 commented 1 year ago

I dont understand how to help. Probably there are some issue with your code misconfiguration. If there is issue with library i could try to help, but need to reproduce first.

valentasm1 commented 1 year ago

You could try run demo at your computer and find differencies.

MrYossu commented 1 year ago

Well, having spent ages trying to build a repro, my original code now works! No idea what I've changed, but it's working, so this can be closed.

Thanks

valentasm1 commented 1 year ago

Happy that you resolved.