diff --git a/example/lib/full_map.dart b/example/lib/full_map.dart index f1bf6a7be..f34449aac 100644 --- a/example/lib/full_map.dart +++ b/example/lib/full_map.dart @@ -32,11 +32,12 @@ class FullMapState extends State { Widget build(BuildContext context) { return new Scaffold( body: MapboxMap( - accessToken: MapsDemo.ACCESS_TOKEN, - onMapCreated: _onMapCreated, - initialCameraPosition: - const CameraPosition(target: LatLng(0.0, 0.0)), - ) - ); + accessToken: MapsDemo.ACCESS_TOKEN, + onMapCreated: _onMapCreated, + initialCameraPosition: const CameraPosition(target: LatLng(0.0, 0.0)), + onStyleLoadedCallback: onStyleLoadedCallback, + )); } + + void onStyleLoadedCallback() {} } diff --git a/mapbox_gl_web/lib/src/mapbox_map_controller.dart b/mapbox_gl_web/lib/src/mapbox_map_controller.dart index 4930247ff..9eea56ce0 100644 --- a/mapbox_gl_web/lib/src/mapbox_map_controller.dart +++ b/mapbox_gl_web/lib/src/mapbox_map_controller.dart @@ -341,6 +341,19 @@ class MapboxMapController extends MapboxGlPlatform _map.on('movestart', _onCameraMoveStarted); _map.on('move', _onCameraMove); _map.on('moveend', _onCameraIdle); + _map.on('resize', _onMapResize); + } + + void _onMapResize(Event e) { + Timer(Duration(microseconds: 10), () { + var container = _map.getContainer(); + var canvas = _map.getCanvas(); + var widthMismatch = canvas.clientWidth != container.clientWidth; + var heightMismatch = canvas.clientHeight != container.clientHeight; + if (widthMismatch || heightMismatch) { + _map.resize(); + } + }); } void _onMapClick(e) {