-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Conversation
be10a00
to
cc338db
Compare
3dac5d4
to
041ad82
Compare
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 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/remove
methods on theStyle
object from being called before the style has been loaded? We can go as far as throwing an exception. Exposing theStyle#styleLoaded
flag 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
detached
state 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.
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
Outdated
Show resolved
Hide resolved
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
Outdated
Show resolved
Hide resolved
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
Show resolved
Hide resolved
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
// TODO add SDF support! | ||
public Builder withImage(String name, Bitmap image) { |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's ticket this as follow up work once the base version of this has landed
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
Show resolved
Hide resolved
@@ -1139,7 +1062,6 @@ public void cancelAllVelocityAnimations() { | |||
OnCameraIsChangingListener, OnCameraDidChangeListener { | |||
|
|||
private final List<OnMapReadyCallback> onMapReadyCallbackList = new ArrayList<>(); | |||
private boolean initialLoad = true; | |||
|
|||
MapCallback() { |
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 believe MapCallback
can be reworked to use a provided MapboxMap
object and avoid null checks.
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
Outdated
Show resolved
Hide resolved
@@ -1337,6 +1345,11 @@ public void run() { | |||
}); | |||
} | |||
|
|||
// TODO remove dependency of Style on NativeMapView |
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 in favor of this. Maybe we can move it to the MapboxMap
?
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are missing withImages
method.
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.
Atm we also don't support withLayers or withSources either but could make sense.
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.
Maybe postponing this into a follow up ticket as well? trying to cut some corners to merge this before our branch cut.
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.
Sounds good.
✅
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
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
Outdated
Show resolved
Hide resolved
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
Outdated
Show resolved
Hide resolved
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
Show resolved
Hide resolved
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
Outdated
Show resolved
Hide resolved
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
Show resolved
Hide resolved
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
Outdated
Show resolved
Hide resolved
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
Show resolved
Hide resolved
.../MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java
Outdated
Show resolved
Hide resolved
platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt
Show resolved
Hide resolved
...estApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java
Outdated
Show resolved
Hide resolved
...ndroid/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
Show resolved
Hide resolved
...ndroid/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
Show resolved
Hide resolved
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
Outdated
Show resolved
Hide resolved
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
Show resolved
Hide resolved
9f254c5
to
bdbac82
Compare
...ndroid/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
Outdated
Show resolved
Hide resolved
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
Show resolved
Hide resolved
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
Outdated
Show resolved
Hide resolved
…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
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'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!
...estApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/PrintActivity.java
Outdated
Show resolved
Hide resolved
.../src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.java
Outdated
Show resolved
Hide resolved
...tApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.java
Outdated
Show resolved
Hide resolved
...estApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LocalGlyphActivity.java
Show resolved
Hide resolved
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 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: