forked from mapbox/mapbox-maps-flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation.dart
166 lines (145 loc) · 3.76 KB
/
animation.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import 'package:flutter/material.dart';
import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart';
import 'package:turf/helpers.dart';
import 'main.dart';
import 'page.dart';
class AnimationPage extends ExamplePage {
AnimationPage() : super(const Icon(Icons.map), 'High level animation');
@override
Widget build(BuildContext context) {
return const AnimationPageBody();
}
}
class AnimationPageBody extends StatefulWidget {
const AnimationPageBody();
@override
State<StatefulWidget> createState() => AnimationPageBodyState();
}
class AnimationPageBodyState extends State<AnimationPageBody> {
AnimationPageBodyState();
MapboxMap? mapboxMap;
_onMapCreated(MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
}
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
Widget _easeTo() {
return TextButton(
child: Text('easeTo'),
onPressed: () {
mapboxMap?.easeTo(
CameraOptions(
center: Point(
coordinates: Position(
-0.11968,
51.50325,
)).toJson(),
zoom: 15,
bearing: 0,
pitch: 3),
MapAnimationOptions(duration: 2000, startDelay: 0));
},
);
}
Widget _flyTo() {
return TextButton(
child: Text('flyTo'),
onPressed: () {
mapboxMap?.flyTo(
CameraOptions(
anchor: ScreenCoordinate(x: 0, y: 0),
zoom: 17,
bearing: 180,
pitch: 30),
MapAnimationOptions(duration: 2000, startDelay: 0));
},
);
}
Widget _moveBy() {
return TextButton(
child: Text('moveBy'),
onPressed: () {
mapboxMap?.moveBy(ScreenCoordinate(x: 500.0, y: 500.0),
MapAnimationOptions(duration: 2000, startDelay: 0));
},
);
}
Widget _rotateBy() {
return TextButton(
child: Text('rotateBy'),
onPressed: () {
mapboxMap?.rotateBy(
ScreenCoordinate(x: 0, y: 0),
ScreenCoordinate(x: 500.0, y: 500.0),
MapAnimationOptions(duration: 2000, startDelay: 0));
},
);
}
Widget _scaleBy() {
return TextButton(
child: Text('scaleBy'),
onPressed: () {
mapboxMap?.scaleBy(15.0, ScreenCoordinate(x: 10.0, y: 10.0),
MapAnimationOptions(duration: 2000, startDelay: 0));
},
);
}
Widget _pitchBy() {
return TextButton(
child: Text('pitchBy'),
onPressed: () {
mapboxMap?.pitchBy(
70.0, MapAnimationOptions(duration: 2000, startDelay: 0));
},
);
}
Widget _cancelCameraAnimation() {
return TextButton(
child: Text('cancelCameraAnimation'),
onPressed: () {
mapboxMap?.cancelCameraAnimation();
},
);
}
@override
Widget build(BuildContext context) {
final MapWidget mapWidget = MapWidget(
key: ValueKey("mapWidget"),
resourceOptions: ResourceOptions(accessToken: MapsDemo.ACCESS_TOKEN),
onMapCreated: _onMapCreated);
final List<Widget> listViewChildren = <Widget>[];
listViewChildren.addAll(
<Widget>[
_cancelCameraAnimation(),
_easeTo(),
_flyTo(),
_moveBy(),
_rotateBy(),
_scaleBy(),
_pitchBy(),
],
);
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Center(
child: SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height - 400,
child: mapWidget),
),
Expanded(
child: ListView(
children: listViewChildren,
),
)
],
);
}
}