-
Notifications
You must be signed in to change notification settings - Fork 826
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
Reduce number of overlapping admin borders #1107
Reduce number of overlapping admin borders #1107
Conversation
This reduces the number of overlapping admin borders by rendering them in order from high to low admin_level, and by giving all admin borders a white background while using comp-op: darken. Admin borders are currently grouped into three groups: level 1-4, level 5-8, and level 9+. This changes only prevents overlap of admin borders within a group (including overlap of borders of the same level). To prevent overlap of borders within groups, it would be necessary to merge the groups, which would lead to performance loss, and is therefore not included in this PR. This partially solves gravitystorm#344.
This prevents overlapping admin borders of different layers. For performance reasons, the admin border layers are split into three groups for low, middle and high zoom levels. For each zoomlevel, all borders come from a single attachment, to handle overlapping borders correctly.
Updated PR - it now also prevents overlap between groups. |
Note that this solution is quite different from the proposed solution in #344, which proposed solving it by a carefully crafted SQL statement. That appeared not so simple (see here), while the current solution, which is basically rendering the spaces between the dashes in white so that underlying borders get painted over, seems to work fine. The |
Do you have any before/after screenshots by hand? I'm really curious about the result. I've made some tests in the past (for HOT rendering), but I never get to the point I really controlled the magic of |
Basically, in my case at least, I think there are two drawbacks:
Plus, but this one is acceptable to my eyes given that we have other benefits, we can't mix dash-array patterns. |
Thanks! It's really great on this example. Let me try this anyway locally with the data I'm used to work with :) |
My solution avoids these drawbacks, as every new boundary is painted on top of (and erasing) the previous boundaries. Make sure that all admin boundaries are in the same attachment. For it to work, it does require that high admin_level boundaries are not wider than low admin_level boundaries, but most styles would require that anyway. |
So I think I'm missing a point in the logic here. Here is what I understand you are doing:
So what I don't get is how do you prevent one line segment drawn below a white background to appear? I mean if you have two boundaries drawn one of top of the other, but the paths don't start at the same point, so the dash-array is out of sync, so some "white background" (i.e. space between path segments) is drawn on top of the segment of the path underneath? What I understand of the comp-op algorithm is that if that when a path (or any other shape) is being to be paint, only the elements that are darker that the underneath already paints elements will be actually paint. (Not sure my question is clear though ;) ) |
The comp-op property applies to attachments, not to individual objects. So first all boundaries get drawn to the admin border attachment one by one without taking comp-op into account (resulting in a purple-white dashed line of the last drawn admin border), and only then the admin border attachment gets merged (with comp-op) with the earlier drawn attachments. So your interpretation is darken(admin-border-2, darken(admin-border-1, background)), while what happens is darken(renderontop(admin-border-2, admin-border-1), background). Not sure if my answer is clear enough either :). |
Maybe interaction between #admin-1-4 and #admin-5-whatever? Does the fuzzy rendering remain if you remove the attachments for admin levels 5 and higher from the code? |
Yes, I've already filtered out those levels. The rendering goes as expected only when I filter out admin_level=4. |
As the line gets rendered (partially) dashed, it seems that the border for level 4 gets rendered on top (so after) the border for level 2? Seems that the 'ORDER BY admin_level DESC' is not taken into account? |
Mamma mia, I was editing |
Good to have an independent verification of my code/method at least :). |
It works but I am not sure why - how background/line-color blocks previously rendered borders but is not displayed? |
It seems that labels for borders are displaying now only the most important one (what may be a good or bad change) and are now really rare (what I think is a change for worse). |
As I said, comp-op works per attachment, not per object. So we generate an attachment containing a set of purple-white dashed lines (of which only the top ones are visible), and with
Border labels come from admin-text, which I did not touch. Are you sure about this? |
It turns out that differences in this case are caused by my TileMill setup (most likely - related to my dataset). |
I think that this method does not work if the borders are rendered on a dark area. In that case, comp-op: darken will not allow anything to be drawn because the border color is lighter than the landuse color. |
Good catch. Do you think there is a different comp-op that works better? |
I experimented a bit with this, and I don't think there's much we can do about this. The admin borders are not visible on landuse darker than #606060 or so. For the current style it's not a problem, whether the possibility to extend the style to other colours is a problem is for @gravitystorm to decide. I would suggest to merge this anyway, as without this PR, the borders are essentially unreadable (it's impossible to distinguish the different admin_levels), and such dark landuse is rare, also in other styles. |
I also would suggest merging - it is vastly better than the current situation. @math1985 |
Just want to say that (as far as I understand it, not being cognizant in cartocss), this sounds like a really elegant solution to one of my biggest pet peeves. |
Reduce number of overlapping admin borders
This fails the "too much magic" test! I'd definitely like some explanation to go in the code, otherwise it's very easy to overlook the comp-op lines or understand how the whole thing works. |
@gravitystorm Thanks for merging! I will add some documentation. |
This resolves gravitystorm#1131.
This prevents overlapping admin borders by rendering them in order from high to low admin_level, and by giving all admin borders a white background while using comp-op: darken.
Admin borders are currently grouped into three groups: level 0-4, level 5-8, and level 9+. Overlap between these groups is avoided, without compromising performance, by creating one attachment for admin_levels 0-4 for low zoom levels, one for admin_levels 0-8 for mid zoom levels, and one for all admin_levels for all zoom levels.
This solves #344.