rungwiroon / BlazorGoogleMaps

Blazor interop for GoogleMap library
MIT License
309 stars 99 forks source link

obj is undefined when trying to call FromLatLngToPoint on projection in OnAfterMapInit() #297

Closed cruiserkernan closed 7 months ago

cruiserkernan commented 7 months ago

Description

Encountering a TypeError in the browser console when attempting to call FromLatLngToPoint on a projection object in the OnAfterMapInit() method. The error suggests that obj is undefined in objectManager.js in the context of this function call.

Reproduction Code

private async Task OnAfterMapInit()
{
    var projection = await map1.InteropObject.GetProjection();
    var testPointFromLatLng = await projection.FromLatLngToPoint(new LatLngLiteral()
    {
        Lat = 59.612529,
        Lng = 16.567550
    });

    if (testPointFromLatLng is null)
    {
        // This should not happen
    }
}

Console Error

TypeError: Cannot read properties of undefined (reading 'fromLatLngToPoint')
    at Object.invoke (objectManager.js:536:40)
    at blazor.server.js:1:3501
    ...

Source Code Context

In the source code, the error occurs at:

else if (functionToInvoke == "fromLatLngToPoint") {
    try {
        var point = obj[functionToInvoke](args2[0]);
        return point;
    } catch (e) {
        console.log(e);
    }
}

Additional Observations

Expected Behavior

The method FromLatLngToPoint should be called without any errors, and obj in objectManager.js should not be undefined.

valentasm1 commented 7 months ago

If you add some delay it all works. I assume it is just need some timeout to load smth.