Skip to content

Commit

Permalink
Cherry-pick upstream#808
Browse files Browse the repository at this point in the history
https: //github.com/flutter-mapbox-gl/maps/pull/808
Co-Authored-By: Felix Horvat <24698503+felix-ht@users.noreply.github.com>
  • Loading branch information
m0nac0 and felix-ht committed May 19, 2022
1 parent 9c69b7e commit b09a43c
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions ios/Classes/MapboxMapController.swift
Expand Up @@ -10,7 +10,7 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma

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

Expand Down Expand Up @@ -107,9 +107,10 @@ 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, !onStyleLoadedCalled {
// only call map#onStyleLoaded here if isMapReady has happend and isFirstStyleLoad is true
if isFirstStyleLoad {
isFirstStyleLoad = false

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

Expand Down Expand Up @@ -1095,16 +1095,14 @@ 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 !onStyleLoadedCalled {
// On first launch we only call map#onStyleLoaded if map#waitForMap has already been called
if !isFirstStyleLoad || mapReadyResult != nil {
isFirstStyleLoad = false

if let channel = channel {
onStyleLoadedCalled = true
channel.invokeMethod("map#onStyleLoaded", arguments: nil)
}
}

isStyleReady = true
}

func mapView(_ mapView: MGLMapView, shouldChangeFrom _: MGLMapCamera,
Expand Down

0 comments on commit b09a43c

Please sign in to comment.