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] Control layer and feature ordering in MapLibre/Mapbox #394

Open
jiacona opened this issue Jan 9, 2025 · 2 comments
Open
Labels
enhancement New feature or request

Comments

@jiacona
Copy link

jiacona commented Jan 9, 2025

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.

@jiacona jiacona added the enhancement New feature or request label Jan 9, 2025
@JamesLMilner
Copy link
Owner

@jiacona firstly, thanks for the kind words, I appreciate the sentiment and to hear you have been enjoying using Terra Draw!

These are both interesting ideas and can totally see why they would be valuable! They actually partially remind me of an older issue, #63, which was just specifically about keeping Terra Draw layers on top. However making this more configurable might be a nicer longer term goal.

At the moment I am about 80% of the way to just releasing a version 1 of Terra Draw which uses separate modules for the adapters, so TerraDrawMapLibreGLAdapter will be in it's own package. One of the nice things (at least I think!) with Terra Draw w designed so that you can create your own adapters with custom requirements fairly easily. However I can see why features like this would be useful for a wider audience. After I have got version 1 out, I will think a bit more about this and if/how the best way to make it a reality.

One last thing, mostly for my own curiosity, what are you working on? :)

@jiacona
Copy link
Author

jiacona commented Jan 10, 2025

Interesting, #63 would have actually given me the opposite behaviour of what I need, which is why making it configurable seems valuable!

I did think about trying to build a custom adapter/mode, but would have had to customise 3 different things (Mapbox adapter, Polygon, and Select modes). It seemed like I would need to copy most of the behaviour out of the existing ones to make that work.

I'm working on https://www.blocktype.co.uk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants