arnaudleclerc / AzureMapsControl.Components

Razor Components for azure-maps-control
MIT License
34 stars 12 forks source link

Uncaught TypeError: Cannot read properties of undefined (reading '_getLayerIds') #81

Open Alexbits opened 1 year ago

Alexbits commented 1 year ago

Switching between styles is impossible after adding controls to the map on the /Layers/LineLayerOnReady samples page. It looks like there is a problem with data sources/layers when map controls are added.

To reproduce, add the following to the AzureMap control:

 Controls="new Components.Controls.Control[]
          {
            new Components.Controls.ZoomControl(new Components.Controls.ZoomControlOptions { Style = AzureMapsControl.Components.Controls.ControlStyle.Dark }, AzureMapsControl.Components.Controls.ControlPosition.TopLeft),
            new Components.Controls.PitchControl(new Components.Controls.PitchControlOptions { Style = AzureMapsControl.Components.Controls.ControlStyle.Dark }, AzureMapsControl.Components.Controls.ControlPosition.TopRight),
            new Components.Controls.CompassControl(new Components.Controls.CompassControlOptions { Style = AzureMapsControl.Components.Controls.ControlStyle.Dark }, AzureMapsControl.Components.Controls.ControlPosition.BottomLeft),
            new Components.Controls.StyleControl(new Components.Controls.StyleControlOptions { Style = AzureMapsControl.Components.Controls.ControlStyle.Dark, MapStyles = MapStyle.All() }, AzureMapsControl.Components.Controls.ControlPosition.BottomRight)
          }"
image
Alexbits commented 1 year ago

Adding a layer via overload with before: string.Empty parameter fixes the issue.

await args.Map.AddLayerAsync(lineLayer, string.Empty);

It looks like the following public async ValueTask AddLayerAsync<T>(T layer) where T : Layer => await AddLayerAsync(layer, null); in the Map.cs should be changed to public async ValueTask AddLayerAsync<T>(T layer) where T : Layer => await AddLayerAsync(layer, string.Empty);

When before is null in the call below, it creates an issue.


    await _jsRuntime.InvokeVoidAsync(Constants.JsConstants.Methods.Core.AddLayer.ToCoreNamespace(),
                layer.Id,
                before,
                layer.Type.ToString(),
                layer.GetLayerOptions(),
                layer.EventActivationFlags.EnabledEvents,
                DotNetObjectReference.Create(_layerEventInvokeHelper));