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

Let user manually show/hide spinner #44

Open
nenadvicentic opened this issue Jul 25, 2019 · 2 comments
Open

Let user manually show/hide spinner #44

nenadvicentic opened this issue Jul 25, 2019 · 2 comments

Comments

@nenadvicentic
Copy link

nenadvicentic commented Jul 25, 2019

I have use case where I want to show spinner only during loading of application data on the map. I am not concerned with progress of tiles and other layers loading, since data on those layers is not crucial to the user.

I achieved this with a bit of hacking, using "private" methods _showIndicator and _hideIndicator and unregistering event listeners immediately after control is added to the map:

    // Initialization logic
    this._loadingControl = L.Control.loading({ separate: true, delayIndicator: 300 });
    this._map.addControl(this._loadingControl);
    // remove layer and basemap event listeners, we want only our logic to show spinner.
    this._loadingControl.onRemove(this._map); 
    private async loadMyData(filter) {
        this._loadingControl._showIndicator();

        try {
            // Data loading logic here
        } finally {
            this._loadingControl._hideIndicator();
        }
    }

It would be nice to have official support for this use case.

@ebrelsford
Copy link
Owner

Sure, I could be open to an option to disable the spinner on base tiles if someone wanted to create a pull request.

@nenadvicentic
Copy link
Author

nenadvicentic commented Jul 25, 2019

I can make a pull request (in a week or two), but can you elaborate a bit how it should be done?

  1. If option to disable the spinner reacting on layer events is true, you skip calling this._addLayerListeners(map); in onAdd function? Still calling this._addMapListeners(map);?

  2. How would showing/hidding be activated in that case? Still with using dataloading and dataload events on the map? For example map.fireEvent('dataloading')?

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

No branches or pull requests

2 participants