Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
22 changes: 10 additions & 12 deletions ios/Classes/MapboxMapController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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 onStyleLoadedCalled = false
private var mapReadyResult: FlutterResult?

private var initialTilt: CGFloat?
Expand Down Expand Up @@ -97,10 +97,10 @@ 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 && !isStyleReadyNotified {
if isStyleReady && !onStyleLoadedCalled {
if let channel = channel {
onStyleLoadedCalled = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we first invoke the callback and only the set the boolean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed that on purpose. As soon as this if is entered the callback will be sent here. So this could avoid calling onStyleLoaded more than once.

channel.invokeMethod("map#onStyleLoaded", arguments: nil)
isStyleReadyNotified = true
}
}
} else {
Expand Down Expand Up @@ -919,7 +919,7 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
* MGLMapViewDelegate
*/
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
isStyleReadyNotified = false
onStyleLoadedCalled = false
isMapReady = true
updateMyLocationEnabled()

Expand Down Expand Up @@ -953,17 +953,15 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
}
}

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

}

isStyleReady = true
Expand Down