Skip to content
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

Feature/intermediate fixes #690

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions ios/Classes/MapboxMapController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma

private var mapView: MGLMapView
private var isMapReady = false
private var isStyleReady = false
private var mapReadyResult: FlutterResult?

private var initialTilt: CGFloat?
Expand Down Expand Up @@ -91,6 +92,13 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
case "map#waitForMap":
if isMapReady {
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 let channel = channel {
channel.invokeMethod("map#onStyleLoaded", arguments: nil)
}
}
} else {
mapReadyResult = result
}
Expand Down Expand Up @@ -873,10 +881,16 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
}
}

mapReadyResult?(nil)
if let channel = channel {
channel.invokeMethod("map#onStyleLoaded", arguments: nil)
//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 let channel = channel {
channel.invokeMethod("map#onStyleLoaded", arguments: nil)
}
}

isStyleReady = true
}

func mapView(_ mapView: MGLMapView, shouldChangeFrom oldCamera: MGLMapCamera, to newCamera: MGLMapCamera) -> Bool {
Expand Down