Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1255
GeographicMap ZoomToGeographic doesnt work in OnAfterRenderAsync
posted

If I try to execute ZoomToGeopgraphic in the OnAfterRenderAsync event I always get the error " Unhandled exception rendering component: cannot invoke method until main component is ready."

The only way I have been able to initialize the zoom rect is to run it in the ImageTilesReady event which seems redundant as there is no reason to render the tiles until after the zoom is set.

  • 34790
    Verified Answer
    Offline posted

    Hello Richard,

    I have been investigating into the behavior you are seeing, and this error happens when the Javascript is still being loaded to the page in Blazor’s back-end processes. In order to get around this, I would recommend that you mark the OnAfterRenderAsync as an “async” method and await the EnsureReady method on the GeographicMap reference. The code below demonstrates this:

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
       await GeoMapRef.EnsureReady();
       GeoMapRef.ZoomToGeographic(new Rect(100, -40, new Size(50, 25)));        
    }

    This ensures that the Javascript is finished being loaded to the page, at which time the GeographicMap component will be “ready” to have actions performed on it.

    Please let me know if you have any other questions or concerns on this matter.