fix(globe): GeoJSON layers rendered twice near antimeridian#6970
fix(globe): GeoJSON layers rendered twice near antimeridian#6970pabueco wants to merge 1 commit intomaplibre:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6970 +/- ##
=======================================
Coverage 92.46% 92.47%
=======================================
Files 288 288
Lines 23856 23879 +23
Branches 5063 5073 +10
=======================================
+ Hits 22058 22081 +23
Misses 1798 1798 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
We are working geojson-vt fixes right now, please let me know if there are things that might be better of moved there. |
|
@HarelM That's what I thought about as well at first, and it did generally work, but I couldn't get around the following (rendering) issue: So in export function wrapGlobe(features, options) {
const result = [];
const left = clip(features, 1, 0, 1, 0, -1, 2, options);
if (left) result.push(...left);
const right = clip(features, 1, 1, 2, 0, -1, 2, options);
if (right) result.push(...shiftFeatureCoords(right, -1));
return result;
}This eliminates the double draw, but it introduces this line at the antimeridian for line layers. I guess this happens because we now have two features and they both receive their own outline.
But it's not just outlines, even if we just have a fill layer, we still get this very slight overlap at the antimeridian:
I could image this being solved when rendering, but I don't know how. Maybe you have an idea? |
|
Yeah, I see what you mean. CC: @mwilsnd, maybe he can take a look from a graphics perspective on this. |
|
I guess the geojson-vt solution is simpler, because it doesn't involve stencils and it seems more correct, because it actually adjusts the underlying data instead of just eliminating the symptoms when rendering. I mainly went with the current fix, because it worked in maplibre directly and didn't involve another dependency. Handling the switch between globe and mercator could be done by adding a Yes, with both solutions we get the vertical lines (either via overdraw of fill layers or the stroke on line layers). In the first stencil based solution they 'move' based on the set |
|
@pabueco Not sure if you are aware but we onboarded geojson-vt to Maplibre and are actively developing on it. So we welcome any improvements! |
|
geojson-vt was on-borded and introduced into maplibre. |
|
With 5.21.0 I see no overlap with the reproduction above... not related but the globe fading is quite nice lol |



This is an attempt to fix issue #6248
Note: While it seems to fix the issue for me I'm not sure how viable that approach/fix actually is.
The root cause for the bug outlined in the issue seems to be related to
geojson-vtwrapping at the antimeridian and the fact that globe projection has no world copies. I first attempted to adjust the wrap function ingeojson-vtto clip the features that cross the antimeridian, but that resulted in a overlap/line at the antimeridian, which I couldn't get rid of.The approach that worked was leaving the
geojson-vtwrapping as is and instead adjusting the stencil mode for tiles at/near the antimeridian to only draw on a pixel once per layer.This removed the overdraw entirely (before and after):
The code used in this example is a slightly adjusted codepen linked in the issue.
As you can see the last thing that remains are the vertical lines at the edge of the previous overdraw. I feel like this should be fixable in a similar way but using the same fix in
draw_line.tsdid not help.However what did help was, changing the
buffervalue passed togeojson-vtto256(default is128). Either in theworkerOptionshere or when adding the geojson source to the map:With this we get the exact result we're looking for:
Here is the benchmark result for
LayerFill(I assumed this is the only relevant test case).