-
-
Notifications
You must be signed in to change notification settings - Fork 893
feat: add multi-world support to Polygons and Polylines & refactoring
#2033
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: * `multi_world_layer_helper.dart`: Helper for multi world: e.g. draw and hitTest on all world copies. Impacted files: * `internal_hit_detectable.dart`: new `MultiWorldLayerHelper` field * `label.dart`: implemented position computation for new value `PolygonLabelPlacement.centroidWithMultiWorld` * `multi_worlds.dart`: added a `PolygonLayer` and a `PolylineLayer` * `offsets.dart`: added a `double shift = 0` parameter for `getOffset` and `getOffsetXY` * `circle_layer/painter.dart`: refactored using new class `MultiWorldLayerHelper` * `polygon_layer/painter.dart`: implemented the multi world using new class `MultiWorldLayerHelper` * `polyline_layer/painter.dart`: implemented the multi world using new class `MultiWorldLayerHelper` * `polygon.dart`: new value for `PolygonLabelPlacement` - `centroidWithMultiWorld`, as a fix for side-effects around the -180 or 180 longitude
Deduplicated `.checkIfHitInTheWorlds` & `.drawInTheWorlds` Minor renaming
…MultiWorld` usage
Removed `HitTestRequiresCameraOrigin` Converted `HitDetectablePainter` to mixin
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, thanks once again!
Before I merge, it would be good to get your (@monsieurtanuki) opinion on the changes I've made.
- Converted your new helper object into a mixin, and renamed it, as using it doesn't necessarily force the layer to support multi worlds
- Removed the
HitTestRequiresCameraOriginmixin, as that functionality has been absorbed into your new object/mixin - Converted the existing
HitDetectablePainterinto a mixin - Removed the two different, but very similar, implementations of the method in your object that allowed iteration across the worlds, and merged them into one method - essentially before, where the second one had a callback returning
true, the callback should returnfalse, andfalse->null
I changed your object into a mixin as I thought it fit better with the inheritance system we had in place, and it would allow for the removal of "helper." prefixes, and allowed for better removal of the HitTestRequiresCameraOrigin mixin. It also meant we could enforce the setting of the canvas size/viewport rect.
Of course, it could be taken a step further if we merge some things together. elementHitTest now always repeats across the worlds, so we could take that out of each layer - for example. We'd then get one bigger mixin. Wdyt?
Polygons and Polylines & refactoring
|
Hi @JaffaKetchup! It looks like you understand my own code better than I do ;) Some comments I was not convinced by your @mustCallSuper
@mustBeOverridden
void paint(...which is indeed much safer. Probably due to the @override
final MapCamera camera;
@override
final LayerHitNotifier<R>? hitNotifier;The problematic part is your merging of both "do-it-in-all-worlds" methods. I understand the idea of refactoring them, but I'm afraid you're wrong in one case (e.g. once you hit a polygon you say you've hit something, and when you draw a polygon you still have to draw other polygons). bool workAcrossWorlds(WorldAction Function(double shift) work) {
if (work(0) == WorldAction.hit) {
return true;
}
if (worldWidth == 0) return false;
for (double shift = -worldWidth;; shift -= worldWidth) {
final isHit = work(shift);
if (isHit == WorldAction.invisible) break;
if (isHit == WorldAction.visible) continue;
return true;
}
for (double shift = worldWidth;; shift += worldWidth) {
final isHit = work(shift);
if (isHit == WorldAction.invisible) break;
if (isHit == WorldAction.visible) continue;
return true;
}
return false;
} |
…jectableFeatureLayerPainter` Internal refactoring of feature layers & hit detection
|
@monsieurtanuki Ok, I've made some more changes, lmk what you think. fd129c2 adds your enum idea, which I think makes sense. 8903fc1 is a little bit more! I can revert it if you think it's too much. In order to avoid declaring the 2 properties in the 3 layers, you have to introduce an intermediary class which mixes in both mixins. So I've done that. Then, I've also made it so that the hit testing in the |
|
Hi @JaffaKetchup! The new I wouldn't be that enthusiastic about the The naming of I'm not convinced removing parameter TL;DR I agree with fd129c2 and I would be careful with 8903fc1. |
…WorldProjectableFeatureLayerPainter`" This reverts commit 8903fc1.
|
Ok, makes sense. I've reverted the second PR and just made a couple small changes that have no real effect but are just nice. Thanks :) |
What
Polygons andPolylines support multi-world.Circles, and to imagine other layers like "painted Markers".CircleandPolylineScreenshots
Files
New file:
multi_world_layer_helper.dart: Helper for multi world: e.g. draw and hitTest on all world copies.Impacted files:
internal_hit_detectable.dart: newMultiWorldLayerHelperfieldlabel.dart: implemented position computation for new valuePolygonLabelPlacement.centroidWithMultiWorldmulti_worlds.dart: added aPolygonLayerand aPolylineLayeroffsets.dart: added adouble shift = 0parameter forgetOffsetandgetOffsetXYcircle_layer/painter.dart: refactored using new classMultiWorldLayerHelperpolygon_layer/painter.dart: implemented the multi world using new classMultiWorldLayerHelperpolyline_layer/painter.dart: implemented the multi world using new classMultiWorldLayerHelperpolygon.dart: new value forPolygonLabelPlacement-centroidWithMultiWorld, as a fix for side-effects around the -180 or 180 longitude