Skip to content
Merged
Show file tree
Hide file tree
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
33 changes: 25 additions & 8 deletions example/lib/full_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,38 @@ class FullMap extends StatefulWidget {

class FullMapState extends State<FullMap> {
MapboxMapController? mapController;
var isLight = true;

void _onMapCreated(MapboxMapController controller) {
_onMapCreated(MapboxMapController controller) {
mapController = controller;
}

_onStyleLoadedCallback() {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("Style loaded :)"),
backgroundColor: Theme.of(context).primaryColor,
duration: Duration(seconds: 1),
));
}

@override
Widget build(BuildContext context) {
return new Scaffold(
floatingActionButton: Padding(
padding: const EdgeInsets.all(32.0),
child: FloatingActionButton(
child: Icon(Icons.swap_horiz),
onPressed: () => setState(
() => isLight = !isLight,
),
),
),
body: MapboxMap(
accessToken: MapsDemo.ACCESS_TOKEN,
onMapCreated: _onMapCreated,
initialCameraPosition: const CameraPosition(target: LatLng(0.0, 0.0)),
onStyleLoadedCallback: onStyleLoadedCallback,
));
styleString: isLight ? MapboxStyles.LIGHT : MapboxStyles.DARK,
accessToken: MapsDemo.ACCESS_TOKEN,
onMapCreated: _onMapCreated,
initialCameraPosition: const CameraPosition(target: LatLng(0.0, 0.0)),
onStyleLoadedCallback: _onStyleLoadedCallback,
));
}

void onStyleLoadedCallback() {}
}
13 changes: 10 additions & 3 deletions ios/Classes/MapboxMapController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -96,9 +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 {
if isStyleReady && !isStyleReadyNotified {
if let channel = channel {
channel.invokeMethod("map#onStyleLoaded", arguments: nil)
isStyleReadyNotified = true
}
}
} else {
Expand Down Expand Up @@ -929,6 +931,7 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
* MGLMapViewDelegate
*/
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
isStyleReadyNotified = false
isMapReady = true
updateMyLocationEnabled()

Expand Down Expand Up @@ -965,9 +968,13 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
//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)
if (!isStyleReadyNotified) {
if let channel = channel {
channel.invokeMethod("map#onStyleLoaded", arguments: nil)
isStyleReadyNotified = true
}
}

}

isStyleReady = true
Expand Down