Repository navigation
Completing deterministic labels and symbols effort - #1586
Conversation
* Slight performance improvement when drawing labels (faster sorting)
* Slight performance improvement when drawing labels: 1) Avoid sorting when not needed: 2) Reverse order of a sorted list instead of sorting again; 3) Use List-s instead of Set-s where possible.
* Slight performance improvement when drawing labels: 1) Avoid sorting when not needed: 2) Reverse order of a sorted list instead of sorting again; 3) Use List-s instead of Set-s where possible.
|
Sorry for the additional commits, it was just about including the PointTextContainer which was forgotten (but is largely related to this PR). |
| @Override | ||
| public boolean clashesWith(MapElementContainer other, Rotation rotation) { | ||
| if (super.clashesWith(other, rotation)) { | ||
| return true; |
There was a problem hiding this comment.
Isn't super.clashesWith needed anymore?
There was a problem hiding this comment.
Isn't
super.clashesWithneeded anymore?
No, super.clashesWith does not take rotation into account, so it is not relevant for labels. The important part of the super.clashesWith was put here, i.e. the Display.ALWAYS == this.display checks.
| undrawableElements.add(current); | ||
| private void processLabels(RenderContext renderContext) { | ||
| final List<MapElementContainer> labelsToDraw; | ||
| { |
There was a problem hiding this comment.
We can avoid this { so commit history is more clear with the changes.
There was a problem hiding this comment.
Those are scope-reducing braces, that make it clear that the purpose of the code inside is to set the variable. In our opinion it is better to have more error-resistant code than not to have it. No problem to remove those, are you sure?
| } | ||
|
|
||
| private Set<MapElementContainer> processLabels(RenderContext renderContext) { | ||
| /** TODO (2024): If this renderer is ever going to be used, please see how labels are handled in the {@link DatabaseRenderer}, and then implement here. */ |
There was a problem hiding this comment.
DirectRenderer is not used by Mapsforge.
It could be used by apps to get bitmap tiles from vector maps in their own custom map engines.
However, it has worse map rendering than Mapsforge map engine, especially with the label layer.
It would be better if all developers work and improve the Mapsforge map engine,
so that our resources are not separated and we all benefit from the improvements.
|
@Sublimis Is there still work to be done? |
…clashesWith() improvements! 2) Important PointTextContainer.clashesWith() improvements! 3) Important LayerUtil.collisionFreeOrdered() improvements! The above improvements together make the following : * Non-deterministic labels AND SYMBOLS are now history! * Prevents labels and symbols overlap when the overlapping items are both marked as "display always"! * Extra: Slight performance improvement when drawing labels: Avoid sorting when not needed; Reverse order of a sorted list instead of sorting again; Use List-s instead of Set-s where possible.
|
Mostly done, but these upcoming simple yet far-reaching changes (which we're quite proud of) might cause some head scratching, so now we're investing time into detailed explanations. 🙂 As soon as those are finished, we'll send a new commit. For example: The library will now not allow two labels or symbols that are both marked as Also: |
|
If you think there are improvements to the Motorider map theme, please write here: It is written by @MotoUKRider and we contribute it to the Mapsforge community. |
We do not want these, as it changes how "always" was designed (see here). Labels / symbols marked with If someone wants less labels / icons on the map can remove the "always". |
Can you please explain under what circumstances it is a good (or positive) thing to have two |
Its name indicates its meaning: "always: an element will always be displayed regardless of space". |
|
@Sublimis Thanks for the screenshots. They appear nice and clear, I don't have a strong opinion on this. But I don't know how the users will see this change in their maps. By the way the "always" is also used in oneway arrows. |
In other words, ugly overlap of two "always" items should has less priority over the "always" property? The logic is there, but maybe someone should communicate this to the theme creators and take their opinion into account. We think the "display always" property as currently defined (and abused) is too powerful. After all, we're talking about labels and symbols here, not rocket science... In any case, this is really just a minor change in the code, easily reverted (and un-reverted in the future if needed). |
Will do this now and get back to you! |
That's it, can you check the oneway arrows before and after the change? |
|
The "Fuel" icons do not overlap the City/Town labels on the current theme, so that behaviour seems unique to whatever application is producing those maps. In fact there was some talk about this back in August and I fixed/tamed it. |
|
One more thing to point out. The (*) Maybe you can notice how gas station symbols in the first (overlapping) screenshot above are nicely drawn from left to right 💯 🙂 |
|
It's more about the same elements with "always" rule. Please see the screenshots with fuel stations above: |
They do overlap, but they're below the City label, not above, is that what you meant? |
|
We can probably merge it and see it in action within the apps. Note: Mapsforge samples don't have layers menu, they display everything in the map theme. |
|
Here is the commit. |
|
@Sublimis Is this ready to merge? Maybe you can update the pull request description with the details of the new commits? |
…lementContainer.clashesWith() 2) Important improvements to PointTextContainer.clashesWith() 3) Improvements to LayerUtil.collisionFreeOrdered() The above improvements together make non-deterministic labels and symbols a history! * Prevent labels and symbols overlap when the overlapping items are both marked as "display always" * Additional: Slight performance improvement when drawing labels: Avoid sorting when not needed; Reverse order of a sorted list instead of sorting again; Use List-s instead of Set-s where possible.
…lementContainer.clashesWith() 2) Important improvements to PointTextContainer.clashesWith() 3) Improvements to LayerUtil.collisionFreeOrdered() The above improvements together make non-deterministic labels and symbols a history! * Prevent labels and symbols overlap when the overlapping items are both marked as "display always" * Additional: Slight performance improvement when drawing labels: Avoid sorting when not needed; Reverse order of a sorted list instead of sorting again; Use List-s instead of Set-s where possible.
A few more details will be added, sorry.
Will do. By the way, it appears that symbol clash check does not take rotation into account, maybe something that should be considered in the future. |
|
@devemux86 |
|
@Sublimis Thanks for these nice improvements! 👍 |
|
I'm thinking about whether we should make a new release, since so many improvements have been implemented. |
|
More work! The labels are still not 100% perfect 😅 Maybe a day or two, if everything goes well. Also, the hill shading improvements have been completed for some time now, and are basically waiting to be pushed (this is a big commit, but tested a lot by now, and works great). After that yes, all of this will probably justify a new release. |
|
No problem! It is better small pull requests step by step to understand the changes in history. Then hill shading can come modifying only its own files, so we have a clear implementation. 🙂 |
|
Those h.s. changes couldn't be made in small steps, as there are changes to interfaces etc., you'll see 🙂 But yes, it mostly touches its own files, except for some small changes to GraphicContext and GraphicFactory just to add the color feature. |
|
I'm sorry to reopen this old discussion, but I’m reaching out on behalf of the Locus Map app development team, specifically regarding the internal theme, which I manage. Unfortunately, this change has broken our internal theme due to a different behavior of the I may not fully understand the rationale behind this change, but if there are limitations with |
IIRC, there were some abuses of the "always" property in default rendering themes that caused unwanted overlapping of displayed items. No one ever mentioned using the property to merge icons, so that was probably not the original intention.
IMHO something like this should be the way to go if this functionality is to be implemented in Mapsforge, and |
Indeed this seems like a new function. Anyway, if you all read the discussion above, could we allow It is important that the existing Mapsforge / OpenAndroMaps / Freizeitkarte themes |
|
@Sublimis @devemux86 I understand that the new behaviour is already in use in some themes, but is there any chance this change could be reverted? Alternatively, what about introducing a new parameter, such as
That might help, but is it really the right solution? The current behaviour of By the way, what is the difference between |
In the current behavior
There were no issues with
Reading again into the description of Maybe someone could contact @ludwigb (Ludwig M Brinckmann) who wrote the original code in 2014. and ask whether they had creating icons in mind when conceiving If they didn't, then using this parameter to make multilayer icons feels like a hack IMHO, and we should go for either 2) or 3), or something else entirely. |
Can do. Please allow a few days. A question to @voldapet regarding multilayer icons: Is there some deeper reason why you are delegating this to Mapsforge instead of implementing it in your application? Even with the |
|
@Sublimis @devemux86
I'm not sure I can understand. A few years ago, we maintained our own fork of Mapforge within the app. However, this approach created complications for the community - particularly around theme compatibility and other inconsistencies—so we ultimately chose to align with the official Mapsforge library As for why we "merge" icons in Mapsforge, there are two main reasons:
|
|
Ok, thanks for the info. We've started working on this, PR will probably be ready by tomorrow at the latest. |
|
#1717 |








Important improvements to
MapElementContainer.compareTo()andMapElementContainer.clashesWith()Important improvements to
PointTextContainer.clashesWith()Improvements to
LayerUtil.collisionFreeOrdered()The above improvements together make non-deterministic labels and symbols a history!
Additional:
Prevent labels and symbols overlap when the overlapping items are both marked as "display always"
DirectRendereris now obsolete. Now that the labels are deterministic, it doesn't bring anything new to the table that isn't already covered by theDatabaseRenderer. It is thus converted into a simple "empty shell" subclass of theDatabaseRendererwith the same interface as before, so it won't break any apps that use it. (Being able to render tile by tile #1085)Slight performance improvement when drawing labels: Avoid sorting when not needed; Reverse order of a sorted list instead of sorting again; Use List-s instead of Set-s where possible.