Skip to content

[Feature Request] Control layer and feature ordering in MapLibre/Mapbox #394

@jiacona

Description

@jiacona

First of all, thanks so much for all your work on this library. I've been using it quite heavily at the moment and it has been working great.

Is your feature request related to a problem? Please describe.

I'm using TerraDraw as part of a map based site layout app and needed to be able to control layer and feature ordering.

I need to order different objects that can be added to the map as well as lines and polygons drawn by TerraDraw. In my scenario, I needed polygons to come first, then lines, then our other layers, regardless of when they are drawn.

Within the TerraDraw polygon layer, I am using functional styling to be able to draw different types of polygons. These polygon types also needed to be drawn in a deterministic order.

Describe your proposed idea for the solution to this problem

I am using MapLibre, so the proposed solution only applies to that adapter.

Layer ordering

Deterministic layer order can be achieved by using the beforeId param to anchor a layer in relative order to another known layer. Exposing this parameter as a mode style would enable controlling where in the layer hierarchy objects are drawn.

Feature ordering

Within a layer, features can be ordered by supplying a sortKey as a functional mode style parameter. The same criteria used to determine different feature styling can be used to set a sortKey.

Additional context

I am currently using a forked version of TerraDraw where I exposed both beforeId and sortKey. You can have a look at my minimal implementation here 60aecdb. If this type of feature is something you think could be more generally useful I'd be happy to put in some time to make it PRable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions