Skip to content

Design proposal for better layer ordering #1491

Closed

Description

@pauldendulk

Below is a proposal originating from another thread. Other options can be discussed, but note, there are a lot of things to take into account.


    public interface ILayerCollection
    {
        void Clear(); // Removes all layers for all groups
        void Clear(int group); // Removes all layers in a group. No default here. If there is no group argument all layers will be cleared, see Clear()
        void AddToTop(ILayer layer, int group = 0);
        void AddToBottom(ILayer layer, int group = 0);
        void MoveToTop(ILayer layerToMove, int group = 0);
        void MoveToBottom(ILayer layerToMove, int group = 0);		
        void MoveUp(ILayer layerToMove, keepWithinGroup = false); // if it is the top layer in the group it will become the bottom layer in the group above, but not if keepWithinGroup is true
        void MoveDown(ILayer layerToMove, keepWithinGroup = false); // if it is the bottom layer in the group it will become the top layer in the group above, but not if keepWithinGroup is true
        void InsertAbove(ILayer referenceLayer, ILayer layerToInsert);
        void InsertBelow(ILayer referenceLayer, ILayer layerToInsert);
        ILayer Remove(ILayer layer); // Returns the removed layers so that it can be used for moving
    }

Originally posted by @pauldendulk in #598 (comment)

Activity

  1. pauldendulk commented on Feb 15, 2022

    @pauldendulk
    MemberAuthor

    Random thoughts:

    • When referring to a layer to be moved we could use the layer pointer, the layer name, the id within the layer list, a global id.
    • Perhaps we should discuss the internal structure first.
    • Another thing to keep in mind is how to persist this information.
  2. janusw commented on Feb 15, 2022

    @janusw
    Member

    So, there is already a Mapsui.Layers.LayerCollection which has very similar methods, right?

    public class LayerCollection : IEnumerable<ILayer>
    {
        public void Clear();
        public void Add(params ILayer[] layers);
        public void Move(int index, ILayer layer);
        public void Insert(int index, params ILayer[] layers);
        public bool Remove(params ILayer[] layers);
    }

    The interface is somewhat different from what you propose, but the functionality is basically the same, right?

    So, what exactly do you suggest? Replace this one by the new one? Expand it to include some convenience methods? Or just use it more consequently?

  3. charlenni commented on Feb 15, 2022

    @charlenni
    Member

    I think, that @pauldendulk proposal is an enhancement of the existing one. With this, you could create groups of layers. E.g. you have on a map the background, the map (tiles) itself and additional layers above the map. If you want layers to stay on top all others, then you have to group them and say, where a new layer should go. You could do this automagical or by hand. Up to now, it isn't possible to move Layers, because it is only a list. They appear in the order, someone added them. If you then add a map later, it is the topmost layer, which hides all others. To bring a special Layer to the top, you have to remove them and readd them again. Each time you do such things, the screen is redrawn. With 5 Layers, you have 6 times to redraw the screen (one clear list and five adds). So the functions to move around layers would be helpful.

  4. janusw commented on Feb 15, 2022

    @janusw
    Member

    I think, that @pauldendulk proposal is an enhancement of the existing one. With this, you could create groups of layers.

    Ah yeah, thanks for the comment. I see the group arguments now (obviously I wasn't looking very closely at the code sample). Makes total sense! 😃

  5. pauldendulk commented on Feb 15, 2022

    @pauldendulk
    MemberAuthor

    The main idea is to add grouping. The layers that are part of the Mapview could be in a group that is on top of the main group that the app developer is using.

  6. janusw commented on Feb 15, 2022

    @janusw
    Member

    The main idea is to add grouping.

    I absolutely agree that grouping is a very reasonable idea here. However, I'm not sure if the interface you suggest is suitable, see my comment in #1489 (comment):

    However, one disadvantage of the interface proposed in #1491 is that there is no way to restrict access to a specific group ...

    Let's say we put the 'user' layers into group 0 and the 'special/internal' layers of the MapView into group 1. Then, how do you prevent a user from adding a layer to group 1 (or group 2)?

    Maybe an alternative would be to use a top-level class LayerCollection that would contain one or several LayerGroup objects (ordered in a particular way), which in turn contain an ordered list of layers.

    Then you could have one group exposed publicly and keep the other one private ...

  7. pauldendulk commented on Oct 25, 2024

    @pauldendulk
    MemberAuthor

    This is implemented in this PR. Further modifications should be discussed in a new issue.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions