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

Use more complex logic for layer/group ordering #88

Merged
merged 6 commits into from
Jun 27, 2024
Merged

Conversation

nyalldawson
Copy link
Collaborator

Create a simplified, one-level deep, representation of the QGIS project structure and then use this to determine the desired ordering of the Felt project. Always specify ordering keys for layers and groups.

Create a simplified, one-level deep, representation of the
QGIS project structure and then use this to determine the desired
ordering of the Felt project. Always specify ordering keys
for layers and groups.
@felt felt deleted a comment from github-actions bot Jun 19, 2024
@nyalldawson
Copy link
Collaborator Author

@ChrisLoer ready for testing 😄

@ChrisLoer
Copy link
Contributor

Thanks! Uh, we found another bug on our side which I'm still investigating. But as a small thing, I notice that XYZ tiles aren't getting an ordering attached to them, maybe because they don't have styling?

@ChrisLoer
Copy link
Contributor

Ugh OK so it's a timing issue on our side we need to fix, but there's a workaround I just tested in a slightly hacked version of the plugin.

The problem is that the ordering key on the layer group is getting overwritten by one of its child layers. The workaround is just to do a second call to create_layer_groups after creating all the layers and putting them in their groups. On the second call, provide the layer group ID you got from the first call, and it will update the existing group instead of creating a new one -- and the second time, the ordering_key will stick.

Up to you whether you'd rather do the workaround and be done with it or wait for us to get a fix in (which hopefully shouldn't take too long).

@nyalldawson
Copy link
Collaborator Author

@ChrisLoer

But as a small thing, I notice that XYZ tiles aren't getting an ordering attached to them, maybe because they don't have styling?

Ok, that's fixed now! (Also fixed xyz in a group not correctly being attached to that group)

Copy link

github-actions bot commented Jun 25, 2024

Plugin ready!

A test version of this PR is available for testing here.

(Built from commit 4ca5df6)

@ChrisLoer
Copy link
Contributor

The XYZ ordering is working now, but the group ordering still isn't working -- I looked at your commit and it looks like you're calling the layer order update after all the initial creation is done, but it's the layer group order update that needs to happen a second time. Here's the code I used when I hacked it in (I also had to make changes to create_layer_groups, you can probably figure out what they were):

            multi_step_feedback.step_finished()

        # do this a second time because the order gets overwritten!
        if all_group_names:
            # ensure group names match their order in the QGIS project
            ordering_keys = {
                group: self.project_structure.group_ordering_key(group)
                for group in all_group_names
            }
            reply = API_CLIENT.create_layer_groups(
                map_id=self.associated_map.id,
                layer_group_names=all_group_names,
                ordering_keys=ordering_keys,
                group_ids=group_ids
            )
            group_details = json.loads(reply.content().data().decode())
            group_ids = {
                group['name']: group['id'] for group in group_details
            }
        else:
            group_ids = {}

        return True

Of course the name "create_layer_groups" isn't really the best name the second time -- when you pass in an ID, you're updating instead of creating.

@nyalldawson
Copy link
Collaborator Author

@ChrisLoer Ok, ready for another round of testing!

@ChrisLoer
Copy link
Contributor

That's the stuff! Working correctly now, thanks for your patience working through these last bits.

@nyalldawson nyalldawson merged commit 4117a9b into main Jun 27, 2024
12 checks passed
@nyalldawson nyalldawson deleted the layer_order_2 branch June 27, 2024 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants