felt / qgis-plugin

20 stars 5 forks source link

Use more complex logic for layer/group ordering #88

Closed nyalldawson closed 1 week ago

nyalldawson commented 2 weeks ago

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.

nyalldawson commented 2 weeks ago

@ChrisLoer ready for testing :smile:

ChrisLoer commented 2 weeks ago

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 commented 2 weeks ago

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 commented 1 week ago

@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)

github-actions[bot] commented 1 week ago

Plugin ready!

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

(Built from commit 4ca5df6ed8875b193960035b4b06b2b0d2cbccae)

ChrisLoer commented 1 week ago

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 commented 1 week ago

@ChrisLoer Ok, ready for another round of testing!

ChrisLoer commented 1 week ago

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