Repository navigation
Style.java - #13484
Style.java#13484
Conversation
be10a00 to
cc338db
Compare
3dac5d4 to
041ad82
Compare
LukasPaczos
left a comment
There was a problem hiding this comment.
This looks great, thanks a lot for the huge lift @tobrun!
A couple of notes:
- It'd be great to check the code for missing nullability annotations.
- Can we guard all of the
add/removemethods on theStyleobject from being called before the style has been loaded? We can go as far as throwing an exception. Exposing theStyle#styleLoadedflag could be useful as well. - Since we are coupling the concept of adding images via the
Style, would it make sense to remove all of the images added with this style during the cleanup? Or should we rather separate those concepts? - Assuming there is no other way of handling the
detachedstate besides the flag, would there be a way of keeping this flag in the core, and having it set on all of the sources within the style during the cleanup? This would guard all of the sources/layers, not only those added in the runtime.
There was a problem hiding this comment.
Now that I think about it, it'd be great to expose a Drawable overload of this method and generate a bitmap out of it just before adding it to the map to possibly minimize the time we are keeping bitmaps in the Java memory.
There was a problem hiding this comment.
Let's ticket this as follow up work once the base version of this has landed
There was a problem hiding this comment.
I believe MapCallback can be reworked to use a provided MapboxMap object and avoid null checks.
There was a problem hiding this comment.
I wasn't able to workaround the nullability, MapCallback needs to be created when MapView is created and at that point MapboxMap isn't created yet. This is needed to hook up the onMapReadyCallbackList. Only way forward afaik is to decouple MapCallback into a couple of concrete classes that have different lifespan/scopes.
There was a problem hiding this comment.
I don't feel this is worth picking up now but we should ticket this out and pick up in near future. This is an internal refactor that won't impact the public API.
There was a problem hiding this comment.
I'm in favor of this. Maybe we can move it to the MapboxMap?
There was a problem hiding this comment.
This must addressed before merging this PR! Still need to look into this.
| * @param image the image to be added | ||
| * @return this | ||
| */ | ||
| public Builder withImage(String id, Bitmap image) { |
There was a problem hiding this comment.
We are missing withImages method.
There was a problem hiding this comment.
Atm we also don't support withLayers or withSources either but could make sense.
There was a problem hiding this comment.
Maybe postponing this into a follow up ticket as well? trying to cut some corners to merge this before our branch cut.
✅
I went with a different approach, style remains null until it has fully loaded (see #13484 (comment)).
This would be indeed a good idea, this would also allow us to call recycle on the bitmaps passed to the builder.
Yes, 💯 this needs to be added to the jni layer and not java. |
|
With 134a8bb4b4281020486b3ac5b7c98dae7931bb1a I'm removing the dependency of Style.java on NativeMapView (see #13484 (comment)). This however also results in adding MapView as dependency on MapboxMap, which I'm not happy about either. MapboxMap can't be used as it doesn't have access to the required listeners.. Alternative might be to introduce a new interface that is used in NativeMapView to at least decouple Style.java from NativeMapView but I'm torn... |
1159877 to
ac6f912
Compare
|
Revisited #13484 (comment), with ac6f912 |
c6e386f to
ab15eba
Compare
a8987d7 to
b8dc3ed
Compare
9f254c5 to
bdbac82
Compare
…ts for non existing style and multiple style loading, revisit code comments
…ntimeStyleTest when removing layer at, add javadoc to isFullyLoaded
bdbac82 to
9535604
Compare
…ll invocations, add test
LukasPaczos
left a comment
There was a problem hiding this comment.
I've looked through all of the demo activities and it seems like most of them could use a local Style field to avoid all of the null warnings from the IDE. This is not a high priority and can be tackled separately.
What I also noticed, is that setting a style via MapboxMapOptions is not really useful anymore as we are not restoring the style anyway. Can we drop that option as a part of this PR?
Otherwise, it looks great!
LukasPaczos
left a comment
There was a problem hiding this comment.
I think we're done here, thanks for the awesome work @tobrun! 🎉
This PR introduces the concept of Style.java to mimic style.hpp from core. All style related methods are moved to the style class vs mapboxmap. OnMapReady will now be invoked when the map surface is created. Styles are composed together using a builder class and allow for a more flexible build up of your style.
For example the following code snippet allows you to only define a background and symbol layer with a geojson source (this without loading another style as mapbox-streets).
Generates the following output:
Todo:
Tailwork after merge: