1+ import 'dart:async' ;
2+
13import 'package:flutter/material.dart' ;
24import 'package:maplibre_gl/maplibre_gl.dart' ;
35
46import 'page.dart' ;
57
8+ const _nullIsland = CameraPosition (target: LatLng (0 , 0 ), zoom: 4.0 );
9+
610class FullMapPage extends ExamplePage {
7- const FullMapPage ({super .key})
8- : super (const Icon (Icons .map), 'Full screen map' );
11+ const FullMapPage ({super .key}) : super (const Icon (Icons .map), 'Full screen map' );
912
1013 @override
1114 Widget build (BuildContext context) {
@@ -21,41 +24,28 @@ class FullMap extends StatefulWidget {
2124}
2225
2326class FullMapState extends State <FullMap > {
24- MapLibreMapController ? mapController;
25- var isLight = true ;
26-
27- _onMapCreated (MapLibreMapController controller) {
28- mapController = controller;
29- }
30-
31- _onStyleLoadedCallback () {
32- ScaffoldMessenger .of (context).showSnackBar (
33- SnackBar (
34- content: const Text ("Style loaded :)" ),
35- backgroundColor: Theme .of (context).primaryColor,
36- duration: const Duration (seconds: 1 ),
37- ),
38- );
39- }
27+ final Completer <MapLibreMapController > mapController = Completer ();
28+ bool canInteractWithMap = false ;
4029
4130 @override
4231 Widget build (BuildContext context) {
4332 return Scaffold (
44- // TODO: commented out when cherry-picking https://github.com/flutter-mapbox-gl/maps/pull/775
45- // needs different dark and light styles in this repo
46- // floatingActionButton: Padding(
47- // padding: const EdgeInsets.all(32.0),
48- // child: FloatingActionButton(
49- // child: Icon(Icons.swap_horiz),
50- // onPressed: () => setState(
51- // () => isLight = !isLight,
52- // ),
53- // ),
54- // ),
55- body: MapLibreMap (
56- onMapCreated: _onMapCreated,
57- initialCameraPosition: const CameraPosition (target: LatLng (0.0 , 0.0 )),
58- onStyleLoadedCallback: _onStyleLoadedCallback,
59- ));
33+ floatingActionButtonLocation: FloatingActionButtonLocation .miniCenterFloat,
34+ floatingActionButton: canInteractWithMap
35+ ? FloatingActionButton (
36+ onPressed: _moveCameraToNullIsland,
37+ mini: true ,
38+ child: const Icon (Icons .restore),
39+ )
40+ : null ,
41+ body: MapLibreMap (
42+ onMapCreated: (controller) => mapController.complete (controller),
43+ initialCameraPosition: _nullIsland,
44+ onStyleLoadedCallback: () => setState (() => canInteractWithMap = true ),
45+ ),
46+ );
6047 }
48+
49+ void _moveCameraToNullIsland () =>
50+ mapController.future.then ((c) => c.animateCamera (CameraUpdate .newCameraPosition (_nullIsland)));
6151}
0 commit comments