-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Decluttering mode by style #13566
Decluttering mode by style #13566
Conversation
I named the property
I have also implemented support for decluttering in ol-mapbox-style. PR will follow, when this is accepted. |
Build errors (doc type links) fixed. |
📦 Preview the examples and docs from this branch here: https://deploy-preview-13566--ol-site.netlify.app/. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work on this, @cns-solutions-admin!
Instead of introducing a DeclutterMode
text enum, you could simply create a typedef with a union type. Something like:
/** @typedef {"none" | "obstacle" | "declutter"} DeclutterMode */
Eventually, we'll be changing all string enums in the library to union types.
To make sure that this new feature can be maintained, it would be important to add tests. In this case, two rendering tests (one for each new mode) would be appropriate.
Of course it would be nice to have this new option also for Text styles, but that does not need to be part of this pull request.
Finally, would you be able to squash the commits in a way that the pull request does not contain any merge commits? A single commit for the whole pull request would also work.
fadad3e
to
13e3a12
Compare
I succeeded in squashing everything into one commit. |
8108f1f
to
596f817
Compare
Thanks for your continued effort on this, @cns-solutions-admin.
We'll be removing these enums, see #12696. We do have the tooling in place ( |
The rendering test does not test the difference between |
cf9b60a
to
8b380aa
Compare
Based on your comments "you could..." and "eventually, ...", I assumed that it was better to use the enum for now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In ahocevar@bbd58ea, I tried to make the test more readable. And by doing so, I saw something I have no explanation for:
Why are the red circles on top of the c-orange
label?
new Feature({ | ||
geometry: new Point([center[0], center[1]]), | ||
text: 'center', | ||
zIndex: 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to set a zIndex
property on any of the features in this test - you're not using them in the style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You introduced a typo: "zindex" instead of "zIndex". Thus the red circles were not used for the orange labels, as those were on top of the red layer.
But this highlighted that I somehow did not commit the continue in the executor: the obstacles are used in the declutter executor to be added to the declutter tree, but rendered in the normal executor - so that they are behind the labels (in the test they were also rendered in the declutter executor thus being drawn on top of the label).
Fixed the executor and updated the test with your version + fix + additional blue circle/text to test
- that objects (red) cannot be obstacles for layers with a higher z index (blue)
- that the obstacles (red) are drawn behind layers with a higher z index (blue)
Allows to specify for each image style, whether the image should be decluttered, always drawn but still serving as obstacle, or drawn without being an obstacle for other images/texts. The layer must still have declutter = true set for this property to have any effect.
4874dc8
to
e1593ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the new behavior is what I would expect. I added two more comments regarding the tests. When these are addressed, I think this is ready for prime time.
}), | ||
]); | ||
// circles are always drawn, | ||
// texts are decluttered against each other and the layer 1 circles/texts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For readability, please refer to the color instead of the layer number everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments improved.
const sourceRed = new VectorSource(); | ||
sourceRed.addFeatures([ | ||
new Feature({ | ||
geometry: new Point([center[0] + 1000, center[1] + 1000 - 200]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous version with the overlapping red circles was better, to show that they do serve as obstacle, but are rendered even if they overlap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, reverted zoom, moved orange circles' text to left with xOffset to show at least one label.
// circles are always drawn, but serve as obstacles, | ||
// texts are decluttered against each other and the circles |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment is not applicable. declutterMode
declutter
here, so if you had more blue circles overlapping this one, they wouldn't be rendered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed when improving comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your effort on this, @cns-solutions-admin
This is weird. Locally the test works. |
I doubt that a difference in font rendering would cause this label to disappear, but I'll try in interactive mode to see what happens when zooming in/out a bit. |
This is really weird. The results are quite stable when zooming in/out locally. |
@cns-solutions-admin Maybe you could cherry-pick 134462c, so we can see if the tests pass then. Or you could grant maintainers access to this pull request's branch, then I could push that change here directly. |
Done. Seems that the font on my computer is a bit smaller/slimmer. |
Now it looks good. You have to update the reference image in your branch with the one from the CI, or give me access to this pull request's branch, or cherry-pick 9d17d92. |
CI image downloaded, committed and pushed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your continued effort on this, @cns-solutions-admin
Very nice collaboration here. |
As requested e.g. in #7475, this improves decluttering by being able to state per (image) style, how this style should be decluttered:
Decluttering still only happens, if the layer also has declutter = true.