-
Notifications
You must be signed in to change notification settings - Fork 319
Resets route arrow related layers when initialization is done. #6466
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
65a459d to
1dc7741
Compare
abhishek1508
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.
We should follow up with an example showing how to do this in our examples repository app module as well as test it in one of the QA activities.
| private const val LOG_CATEGORY = "MapboxRouteArrowView" | ||
| } | ||
|
|
||
| fun initializeLayers(style: Style) { |
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 am assuming we don't need to invoke this function and that it will be invoked internally via render call. If my understanding is correct then we should make it private.
If not, then is the desired use to always call initializeLayers first before calling render(style: Style, expectedValue: Expected<InvalidPointError, ArrowAddedValue>)
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.
If this is meant to be public it would also need appropriate documentation.
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.
The function is an explicit call to initialize the layers if a developer chooses to use it. If a developer wants change the options then they should instantiate a MapboxRouteArrowView with those options and call initializeLayers.
In a more typical usage of MapboxRouteArrowView it's not necessary to call initializeLayers. I'll add the kdoc.
| style.removeStyleLayer(RouteLayerConstants.TOP_LEVEL_ROUTE_LINE_LAYER_ID) | ||
| style.removeStyleLayer(RouteLayerConstants.BOTTOM_LEVEL_ROUTE_LINE_LAYER_ID) | ||
| style.removeStyleLayer(RouteLayerConstants.LAYER_GROUP_1_TRAIL_CASING) | ||
| style.removeStyleLayer(RouteLayerConstants.LAYER_GROUP_1_TRAIL) | ||
| style.removeStyleLayer(RouteLayerConstants.LAYER_GROUP_1_CASING) | ||
| style.removeStyleLayer(RouteLayerConstants.LAYER_GROUP_1_MAIN) | ||
| style.removeStyleLayer(RouteLayerConstants.LAYER_GROUP_1_TRAFFIC) | ||
| style.removeStyleLayer(RouteLayerConstants.LAYER_GROUP_2_TRAIL_CASING) | ||
| style.removeStyleLayer(RouteLayerConstants.LAYER_GROUP_2_TRAIL) | ||
| style.removeStyleLayer(RouteLayerConstants.LAYER_GROUP_2_CASING) | ||
| style.removeStyleLayer(RouteLayerConstants.LAYER_GROUP_2_MAIN) | ||
| style.removeStyleLayer(RouteLayerConstants.LAYER_GROUP_2_TRAFFIC) | ||
| style.removeStyleLayer(RouteLayerConstants.LAYER_GROUP_3_TRAIL_CASING) | ||
| style.removeStyleLayer(RouteLayerConstants.LAYER_GROUP_3_TRAIL) | ||
| style.removeStyleLayer(RouteLayerConstants.LAYER_GROUP_3_CASING) | ||
| style.removeStyleLayer(RouteLayerConstants.LAYER_GROUP_3_MAIN) | ||
| style.removeStyleLayer(RouteLayerConstants.LAYER_GROUP_3_TRAFFIC) | ||
| style.removeStyleLayer(RouteLayerConstants.LAYER_GROUP_1_RESTRICTED) | ||
| style.removeStyleLayer(RouteLayerConstants.LAYER_GROUP_2_RESTRICTED) | ||
| style.removeStyleLayer(RouteLayerConstants.LAYER_GROUP_3_RESTRICTED) | ||
| style.removeStyleLayer(RouteLayerConstants.WAYPOINT_LAYER_ID) |
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.
We have nicely created fields that aresetOf different layerIds like MapboxRouteLineView.trailCasingLayerIds and others. We can move these fields as internal to RouteLayerContants and reuse them both in MapboxRouteLineView as well as in the above function call using forEach
fun removeLayers(style: Style) {
RouteLayerConstants.trailCasingLayerIds.forEach {
style.removeStyleImage(it)
}
....
....
}
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.
Those collections have a specific function totally unrelated to the code removing the layers.
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.
@abhishek1508 idea leads in a good direction though - is there a way to build a single collection that we can iterate over both when adding and removing layers? Otherwise it's easy to make a mistake when a new layer is added to the list, we'd have to remember to write a removal unit test as well, there's no automation that would detect the mistake for us.
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.
Here's an idea. According to Map Style Specification, Layers have an optional metadata property which can hold any arbitrary data. Why not leverage that and add a "layer-group": "arrows" property which we could use to quickly identify which layers needs to be removed together?
57c2d89 to
a73b2a7
Compare
Codecov Report
@@ Coverage Diff @@
## main #6466 +/- ##
============================================
- Coverage 72.51% 72.50% -0.02%
+ Complexity 5540 5532 -8
============================================
Files 777 774 -3
Lines 30038 29960 -78
Branches 3546 3540 -6
============================================
- Hits 21782 21722 -60
+ Misses 6832 6815 -17
+ Partials 1424 1423 -1
|
|
Is the proposed behavior that if I create the first instance of route line components and start drawing I don't need to do anything, but if a create a second instance that has different options, then I have to call Have we tried actually comparing the map layers' state with the options? Why don't we re-apply the options on each draw call and ignore |
I"m not exactly sure what you mean by this. The options are for the layers, the colors, the arrow head drawable etc. Normally the only interaction with the class is by calling the render methods which will check if the layers are present and if not initialize them. I don't want to remove and re-add the layers on each render call. That would mean recreating the layers on each route progress update. I"m trying to be mindful of this ticket here: #5806 and not degrade the performance. I"ll look for other options but can you elaborate on what you had in mind? |
I had the same question and that's why I asked the above. Currently we do not invoke I am not aware of a different solution, but just speaking from customer perspective. |
a73b2a7 to
a24f72d
Compare
There are certainly ways we could try optimizing this. For example, we don't need to recreate layers when they already exist, we only need to re-apply the options that have changed or are different when comparing the options and the layer instance. Also, since options are only provided in a constructor, we could always update or create the layers on the first |
|
I did some testing and made the options mutable. They can be updated at any time and the changes applied to the layers. |
|
The points from #6466 (comment) still stand - we require developers to interact with standalone instances of the views differently depending if they are the first one or not. For example val instance1 = MapboxRouteArrowView(options1)
instance1.render(update)
val instance2 = MapboxRouteArrowView(options2)
instance2.render(update)the |
|
If there's a method to update the options why would a developer have more than one instance of |
Let's re-add the sources and layers on the first render call in this case, that sounds like it should work. |
5dd70fd to
95c28d8
Compare
95c28d8 to
45ab922
Compare
|
@LukasPaczos I believe this has the changes we last talked about. |
deb392a to
d19614f
Compare
…oved so that new options will take effect.
55718f6 to
fea8962
Compare
…oved so that new options will take effect. (#6466) Co-authored-by: Seth Bourget <seth@cafesilencio.net>
…oved so that new options will take effect. (#6466) Co-authored-by: Seth Bourget <seth@cafesilencio.net>
…oved so that new options will take effect. (#6466) Co-authored-by: Seth Bourget <seth@cafesilencio.net>
…oved so that new options will take effect. (#6466) Co-authored-by: Seth Bourget <seth@cafesilencio.net>
…oved so that new options will take effect. (#6466) Co-authored-by: Seth Bourget <seth@cafesilencio.net>
…oved so that new options will take effect. (#6466) Co-authored-by: Seth Bourget <seth@cafesilencio.net>
Description
When layers are initialized via the
MapboxRouteArrowViewandMapboxRouteLineViewthe layers are reset and removed so that they can be reinitialized with the options that may have change so that the layer configuration can change. Previously once the layers were initialized in the map style there was no way to adjust them.Screenshots or Gifs