-
Notifications
You must be signed in to change notification settings - Fork 509
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
Style switching no longer invokes onStyleLoadedCallback on ios #771
Comments
I will investigate. But as I see so far a new instance of MapboxMapController is created every time |
@felix-ht I have just tried on latest master and |
huh i will try to reproduce - for now i switched back to a branch without the issue |
If you have a commit in mind I can quickly switch to it and test. In my app there is a button to switch style that round-rotates over street, outdoor and satelite, so quite easy for me to check. |
@AAverin so i did a git bisect and for me Feature/intermediate fixes is the one that breaks the style switching. The styles still do switch fine, but on style loaded no longer gets invoked. As I add my vector data in that callback - it doesn't get added to the new style until i invoke the add vector data function by some other means. |
@felix-ht I have logs in my onStyleLoaded callback and when I switch styles I see a new entry logged. |
@AAverin This patch fixes the issue for me: diff --git a/ios/Classes/MapboxMapController.swift b/ios/Classes/MapboxMapController.swift
index 05d0e0c..4c31d6d 100644
--- a/ios/Classes/MapboxMapController.swift
+++ b/ios/Classes/MapboxMapController.swift
@@ -11,6 +11,7 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
private var mapView: MGLMapView
private var isMapReady = false
private var isStyleReady = false
+ private var isStyleReadyNotified = false
private var mapReadyResult: FlutterResult?
private var initialTilt: CGFloat?
@@ -94,7 +95,8 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
result(nil)
//Style could happen to been ready before the map was ready due to the order of methods invoked
//We should invoke onStyleLoaded
- if isStyleReady {
+ if isStyleReady && !isStyleReadyNotified {
+ isStyleReadyNotified = true
if let channel = channel {
channel.invokeMethod("map#onStyleLoaded", arguments: nil)
}
@@ -849,6 +851,7 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
* MGLMapViewDelegate
*/
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
+ isStyleReadyNotified = false
isMapReady = true
updateMyLocationEnabled()
@@ -883,8 +886,8 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
//If map is ready and map#waitForMap was called, we invoke onStyleLoaded callback directly
//If not, we will have to call it when map#waitForMap is done
- if let mapReadyResult = mapReadyResult {
- mapReadyResult(nil)
+ if !isStyleReadyNotified {
+ isStyleReadyNotified = true
if let channel = channel {
channel.invokeMethod("map#onStyleLoaded", arguments: nil)
} For me onPlatformViewCreated and thus map#waitForMap only get called once. A style switch does not invoke it again. So mapReadyResult never gets set again and on style loaded does not get invoked after a style switch. On a more general note assuming that the swift code runs in a single thread (on flutters ui thread) - your fix shouldn’t do anything as all of the code is synchronous so its actually impossible for Here is also a minimal example to reproduce this: https://github.com/flutter-mapbox-gl/maps/tree/style-switch-example A snackbar is supposed to be shown whenever onStyleLoaded is called |
Interesting, I'll try to investigate tomorrow. Thanks for the example. |
@felix-ht Debugging, it seems to relate to timing. |
The reason for the bug seems to be in On the other hand I also tried completely removing my extra calls for onStyleLoaded reverting my PR, but then on the real phone I don't see onStyleLoaded called reliably anymore. Again, this could be related to delays in network and/or amount of futures one waits for building the map. |
#775 merged, closing |
If i change the style on an active map the
onStyleLoadedCallback
does not get called again. (Rebuild a MapboxMap with a different styleString)I assume that the cause of this is #690 @AAverin
The text was updated successfully, but these errors were encountered: