-
-
Notifications
You must be signed in to change notification settings - Fork 893
feat: add inverted fill option to PolygonLayer
#2046
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
Conversation
New file: * `advanced_polygons.dart`: Example dedicated to polygons with advanced features. Impacted files: * `main.dart`: added the new `AdvancedPolygonsPage` page * `menu_drawer.dart`: added the new `AdvancedPolygonsPage` page * `painter.dart`: managed the `justHoles` case; refactored a bit `borderPaint` * `polygon.dart`: added the `bool justHoles` field * `polygon_layer.dart`: special case for `justHoles` * `projected_polygon.dart`: special case for `justHoles`
|
LGTM |
|
Thanks :). I've made a couple changes, namely creating a new constructor for the polygons instead of a property, which allows us to enforce some usage patterns, and renamed it to "inverted". Two questions, do we always want the hitting to be inverted? Surely sometimes they want to detect not hitting a hole still? Also, it's now impossible to have multiple holes with different |
Renamed "just holes" to "inverted"
I'm OK with that.
As already mentioned, it's a bit strange to set this property to a polygon, as it impacts the whole map (e.g. the alpha background). All of that depends on typical use-cases:
|
|
I would say we should support both those use-cases - as we did before. That becomes a really difficult solution I guess. A solution is to allow an entire I'm also not 100% sure still why we couldn't make the current usage pattern work, also for the |
Ok.
Just adding intermediary longitude points would do the trick, as the next point of a poly is the closest (the problem is when you try to jump directly from -180 to 180).
No problem with intermediary longitude points. That wouldn't support the "hit an inverted polygon/hole" feature, though. |
|
Fun fact: with my 1980's background the "inverted" polygon feature looks a bit like what was then called "video reverse". But it wasn't easy to find that term on the web now because I rather found tutorials on how to play a video backwards - which wasn't a topic back then. |
|
Yeah, so I guess we introduce a new property (Yep, I can imagine "reverse video" being difficult to search for :D) |
|
I have realised that |
|
@JaffaKetchup The more I think about it, the more I do believe we should put the "inverted" info at the PolygonLayer level, with a new |
Agreed.
I'm not quite following what you mean here? If you mean moving the inverted option all the way to In regards to allowing the hit testing to be inverted, I've opened #2050. It also gives some other options, and applies to all the feature layers. |
I'll show you a screenshot when I'm ready.
I'm not sure we need the hit testing to be inverted, or at least I cannot imagine a typical use-case. |
|
@JaffaKetchup This is what I'm coding right now:
|
Impacted files: * `inverted_polygons.dart`: moved the "inverted" effect to PolygonLayer; additional border and fill display tests * `painter.dart`: moved the "inverted" effect to PolygonLayer * `polygon.dart`: rolled back the "inverted" side-effects * `polygon_layer.dart`: new `Color? invertedFill` field; rolled back the "inverted" side-effects * `projected_polygon.dart`: rolled back the "inverted" side-effects
|
@JaffaKetchup I think I've nailed it (latest push). |
JaffaKetchup
left a comment
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.
This has really complicated things huh :D. Thanks for spending even more time on this again.
Unfortunately I think this is the sort of thing really difficult to test and iron out all of the edge cases.
Here's one (inverting the existing example page) - the intersection of two overlapping polygons should be transparent (as both the polygons are), but the inverted color is shown instead:
When hovering, another transparent polygon is added. Again, it should be transparent through to the map. Instead, the aforementioned intersection becomes transparent, and the other area becomes the inverted fill. I guess the blending or winding is wrong again - there's no issue with transparent over filled, just transparent over transparent or intersecting.
PolygonLayer
|
@JaffaKetchup I guess the code needs some fixing. We're now dealing with features not simple to apprehend: intersecting polygons on an inverse layer. Not an "of course we should display the map that way" situation. I'm not sure I understand correctly all the issues, but I think what you'd want would be:
Or something like that. Another solution would be to say that the inverted polygon layer isn't compatible (temporarily?) with all features, e.g. intersecting polygons or holes. |
|
Yeah, I think what you've said there is what I would be aiming for, but we want holes in inverted polygons to appear black (as they currently are in this PR). It should be the same behaviour as could be created before (by creating the big polygon with several holes). One thing to consider is overlaps and outlines, and overlaps and holes. Take the following picture: What do we do with the hole area here, which overlaps the polygon underneath? What do we do with the outlines? |
|
@JaffaKetchup Again, that's going too far, I cannot picture what we want in the end. I suggest we switch from theoretical mode ("what alpha polygons (with partially outside holes) intersecting each other are supposed to look like on an inverted alpha polygon layer?") (no idea) to engineer mode ("alpha inverted polygon layers would be a nice feature - displaying full polygons makes sense, displaying polygons with realistic holes makes sense too, but beyond that there are probably no use-cases and anyway the output wouldn't be implicitly understandable) (which is probably in contradiction with the use of a map) |
|
Ok, sorry, not 100% sure what you mean! I fully agree that the new approach is much better than doing it per-
I'm not suggesting necessarily doing anything beyond. In my mind, inverted means everything outside of any polygon should be the specified color. Alternatively, it could mean literally painting the opposite of what we're currently doing. |
Added logging for inverted filling when on web Added documentation to `PolygonLayer.invertedFill` Adjusted other logging Minor refactoring
|
Just given it a test, and made |
…e reasons) Applied review suggestions
|
I've completed the testing, it seems to work fine. There does unfortunately appear to be a performance penalty with And before merging, I'll also add a bounty. |
Fixed console warning logging
@JaffaKetchup I'm not sure what you mean with "repetitive variable re-assignment" holePaths = Path.combine(
PathOperation.union,
holePaths,
Path()..addPolygon(offsets, true),
);
|
josxha
left a comment
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'm currently not able to test the behavior but the code changes look alright to me. @monsieurtanuki thanks for your pull request!
|
Thank you @JaffaKetchup @josxha for your reviews and comments! |
Yeah, this is kinda what I meant. It creates a new
Just experimented with this, it makes no significant difference whatsoever - maybe 1ms in the stress test on the raster thread, so almost nothing in the real world. Also tried minimizing the number of combine operations by adding multiple polys to one path first, but of course, that gives the wrong result (since each poly cuts into each other).
This is what we do for
I've done this. |
JaffaKetchup
left a comment
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.
LGTM at last! Before we merge, I'll write a bounty spec and assign this.
I won't include the feature for PolylineLayer and CircleLayer - I'll leave this open for the future, since it wasn't possible before. If I have time, I'll try to implement it based on this.
PolygonLayerPolygonLayer
|
@JaffaKetchup We may not need the "Inverted Polygons" / "Advanced polygons" example page anymore, now that you've updated the standard "Polygon Layer" page. |
|
Ah, good point, forgot to remove it. I'll do it at some point. I've setup the bounty on Polar, but it turns out they're sunsetting bounties soon (which is a bit annoying), so they need to mark this one as complete manually due to a bug or something. Hopefully it won't take too long. |
Removed leftover inverted polygons example from #2046
|
We've paid the bounty through GitHub Sponsors instead :). You should get the entire $170 USD (we paid $10.20 in fees). |
Thank you so much! |
|
Just a note: We might need to change the default of |
Whatever works. As long as it works, the performances are good and it's easy to maintain ;) |










What
bool justHolesfield for polygon:PolygonLayerto have fill color aroundPolygons #2034Fixes #2034. Potentially eligible for bounty.
Screenshots
Files
New file:
advanced_polygons.dart: Example dedicated to polygons with advanced features.Impacted files:
main.dart: added the newAdvancedPolygonsPagepagemenu_drawer.dart: added the newAdvancedPolygonsPagepagepainter.dart: managed thejustHolescase; refactored a bitborderPaintpolygon.dart: added thebool justHolesfieldpolygon_layer.dart: special case forjustHolesprojected_polygon.dart: special case for `justHoles