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

Feature request: Turn off background loading when layer is toggled off #275

Open
svikas opened this issue Jan 31, 2020 · 3 comments
Open

Comments

@svikas
Copy link

svikas commented Jan 31, 2020

I've been able to load custom vector layers via TileJson successfully but an issue I'm finding is that there are constant loads in the background despite my turning the layer off. I think it'd be great to have an option to stop loading in the background, especially when dealing with feature dense layers.

Please let me know if:

  1. This is even a reasonable issue to raise
  2. There is some kind of a workaround via a QGIS setting.
  3. If I could make a PR for this feature.

Thanks for the great plugin!

@mnboos
Copy link
Collaborator

mnboos commented Feb 3, 2020

Hi and thanks for the request!

In my opinion it's reasonable and could even be considered a bug. However, I don't know if there is a QGIS api to check whether a layer is enabled or not.

@svikas
Copy link
Author

svikas commented Feb 3, 2020

Hi @mnboos, thanks for the reply!

You can get all activate layers in a list by doing this:

canvas = iface.mapCanvas()
active_layers = canvas.layers()

From there you can check for existence of the layer in the list.

Alternatively, from the docs I see this signal from MapCanvas:
void QgsMapCanvas::selectionChanged but I haven't been able to validate that it works as expected just yet. (EDIT: This only works for feature selection, not layer selection)

@svikas
Copy link
Author

svikas commented Feb 3, 2020

I looked into it and if you wanted to register a function to be called every time the visibility changes for a layer you could either:
i. QgsProject.instance().layerTreeRoot().visibilityChanged.connect(function_name)
ii. Take the LayerTreeNode associated with the layers written by Vector Tile Reader and use the visibilityChanged signal directly on it and keep track of whether the layer is visible or not. (more preferable as you are listening to fewer events).

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

No branches or pull requests

2 participants