Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable getting and setting Center and Zoom properties after initialization #29

Open
AlexKven opened this issue May 26, 2020 · 3 comments

Comments

@AlexKven
Copy link

AlexKven commented May 26, 2020

The current Center and Zoom properties don't have any effect after the control is initialized. I am working on a project where I need this feature, and I was able to change Map to have the Center and Zoom properties stay updated to the status of the map. If this is something you would want merged into this repository, then assign this issue to me and I can put my code into a proper pull request.

@chucker
Copy link
Contributor

chucker commented May 26, 2020

I was able to change Map to have the Center and Zoom properties stay updated to the status of the map.

Are changes to the properties reflected immediately? We might want to make some await UpdateMapAsync() method to avoid property setters from having too much performance impact.

@AlexKven
Copy link
Author

I think it updates immediately if it is in Blazor client (the async bit is in case it's running on the server, and the JS needs to be sent over the SignalR connection).

Currently what I have is this:

public LatLng Center
{
    get => _Center;
    set
    {
        _Center = value;
        if (_isInitialized)
            RunTaskInBackground(async () => await LeafletInterops.PanTo(
                _jsRuntime, Id, value.ToPointF(), false, 0, 0, false));
    }
}

...and RunTaskInBackground is this:

private async void RunTaskInBackground(Func<Task> task)
{
    try
    {
        await task();
    }
    catch (Exception) { }
}

I don't think performance is an issue. I may want to add an actual exception handler for this (maybe the map could allow the user to provide a custom exception handler).

As for getting the properties, no async method is necessary because I subscribe to changes in the Leaflet map. When the property changes, I update the backing field of the Center and Zoom properties, so they are already updated to the map's actual center and zoom (same with the Bounds property in the other issue).

AlexKven pushed a commit to AlexKven/BlazorLeaflet that referenced this issue Jun 3, 2020
…leak.

Mehigh17#29 Enables the Center and Zoom properties to set these properties on the map in the background.
Mehigh17#30 Adds a Bounds property to the map that is automatically kept up to date with the map bounds.
Mehigh17#32 Fixes a memory leak related to creating layers.
@Mehigh17 Mehigh17 linked a pull request Jun 6, 2020 that will close this issue
AlexKven pushed a commit to AlexKven/BlazorLeaflet that referenced this issue Jun 10, 2020
AlexKven pushed a commit to AlexKven/BlazorLeaflet that referenced this issue Jun 11, 2020
@chucker
Copy link
Contributor

chucker commented Jul 10, 2020

(This is now PR #37).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants