@@ -110,42 +110,67 @@ class CameraPosition {
110
110
'CameraPosition(bearing: $bearing , target: $target , tilt: $tilt , zoom: $zoom )' ;
111
111
}
112
112
113
+ /// Indicates which type of camera update this instance represents.
114
+ enum CameraUpdateType {
115
+ /// New position for camera
116
+ newCameraPosition,
117
+
118
+ /// New coordinates for camera
119
+ newLatLng,
120
+
121
+ /// New coordinates bounding box
122
+ newLatLngBounds,
123
+
124
+ /// New coordinate with zoom level
125
+ newLatLngZoom,
126
+
127
+ /// Move by a scroll delta
128
+ scrollBy,
129
+
130
+ /// Zoom by a relative change
131
+ zoomBy,
132
+
133
+ /// Zoom to an absolute level
134
+ zoomTo,
135
+
136
+ /// Zoom in
137
+ zoomIn,
138
+
139
+ /// Zoom out
140
+ zoomOut,
141
+ }
142
+
113
143
/// Defines a camera move, supporting absolute moves as well as moves relative
114
144
/// the current position.
115
- class CameraUpdate {
116
- const CameraUpdate ._(this ._json);
145
+ abstract class CameraUpdate {
146
+ const CameraUpdate ._(this .updateType);
147
+
148
+ /// Indicates which type of camera update this instance represents.
149
+ final CameraUpdateType updateType;
117
150
118
151
/// Returns a camera update that moves the camera to the specified position.
119
152
static CameraUpdate newCameraPosition (CameraPosition cameraPosition) {
120
- return CameraUpdate ._(
121
- < Object > ['newCameraPosition' , cameraPosition.toMap ()],
122
- );
153
+ return CameraUpdateNewCameraPosition (cameraPosition);
123
154
}
124
155
125
156
/// Returns a camera update that moves the camera target to the specified
126
157
/// geographical location.
127
158
static CameraUpdate newLatLng (LatLng latLng) {
128
- return CameraUpdate ._( < Object > [ 'newLatLng' , latLng. toJson ()] );
159
+ return CameraUpdateNewLatLng ( latLng);
129
160
}
130
161
131
162
/// Returns a camera update that transforms the camera so that the specified
132
163
/// geographical bounding box is centered in the map view at the greatest
133
164
/// possible zoom level. A non-zero [padding] insets the bounding box from the
134
165
/// map view's edges. The camera's new tilt and bearing will both be 0.0.
135
166
static CameraUpdate newLatLngBounds (LatLngBounds bounds, double padding) {
136
- return CameraUpdate ._(< Object > [
137
- 'newLatLngBounds' ,
138
- bounds.toJson (),
139
- padding,
140
- ]);
167
+ return CameraUpdateNewLatLngBounds (bounds, padding);
141
168
}
142
169
143
170
/// Returns a camera update that moves the camera target to the specified
144
171
/// geographical location and zoom level.
145
172
static CameraUpdate newLatLngZoom (LatLng latLng, double zoom) {
146
- return CameraUpdate ._(
147
- < Object > ['newLatLngZoom' , latLng.toJson (), zoom],
148
- );
173
+ return CameraUpdateNewLatLngZoom (latLng, zoom);
149
174
}
150
175
151
176
/// Returns a camera update that moves the camera target the specified screen
@@ -155,49 +180,154 @@ class CameraUpdate {
155
180
/// the camera's target to a geographical location that is 50 to the east and
156
181
/// 75 to the south of the current location, measured in screen coordinates.
157
182
static CameraUpdate scrollBy (double dx, double dy) {
158
- return CameraUpdate ._(
159
- < Object > ['scrollBy' , dx, dy],
160
- );
183
+ return CameraUpdateScrollBy (dx, dy);
161
184
}
162
185
163
186
/// Returns a camera update that modifies the camera zoom level by the
164
187
/// specified amount. The optional [focus] is a screen point whose underlying
165
188
/// geographical location should be invariant, if possible, by the movement.
166
189
static CameraUpdate zoomBy (double amount, [Offset ? focus]) {
167
- if (focus == null ) {
168
- return CameraUpdate ._(< Object > ['zoomBy' , amount]);
169
- } else {
170
- return CameraUpdate ._(< Object > [
171
- 'zoomBy' ,
172
- amount,
173
- < double > [focus.dx, focus.dy],
174
- ]);
175
- }
190
+ return CameraUpdateZoomBy (amount, focus);
176
191
}
177
192
178
193
/// Returns a camera update that zooms the camera in, bringing the camera
179
194
/// closer to the surface of the Earth.
180
195
///
181
196
/// Equivalent to the result of calling `zoomBy(1.0)` .
182
197
static CameraUpdate zoomIn () {
183
- return const CameraUpdate ._( < Object > [ 'zoomIn' ] );
198
+ return const CameraUpdateZoomIn ( );
184
199
}
185
200
186
201
/// Returns a camera update that zooms the camera out, bringing the camera
187
202
/// further away from the surface of the Earth.
188
203
///
189
204
/// Equivalent to the result of calling `zoomBy(-1.0)` .
190
205
static CameraUpdate zoomOut () {
191
- return const CameraUpdate ._( < Object > [ 'zoomOut' ] );
206
+ return const CameraUpdateZoomOut ( );
192
207
}
193
208
194
209
/// Returns a camera update that sets the camera zoom level.
195
210
static CameraUpdate zoomTo (double zoom) {
196
- return CameraUpdate ._( < Object > [ 'zoomTo' , zoom] );
211
+ return CameraUpdateZoomTo ( zoom);
197
212
}
198
213
199
- final Object _json;
200
-
201
214
/// Converts this object to something serializable in JSON.
202
- Object toJson () => _json;
215
+ Object toJson ();
216
+ }
217
+
218
+ /// Defines a camera move to a new position.
219
+ class CameraUpdateNewCameraPosition extends CameraUpdate {
220
+ /// Creates a camera move.
221
+ const CameraUpdateNewCameraPosition (this .cameraPosition)
222
+ : super ._(CameraUpdateType .newCameraPosition);
223
+
224
+ /// The new camera position.
225
+ final CameraPosition cameraPosition;
226
+ @override
227
+ Object toJson () => < Object > ['newCameraPosition' , cameraPosition.toMap ()];
228
+ }
229
+
230
+ /// Defines a camera move to a latitude and longitude.
231
+ class CameraUpdateNewLatLng extends CameraUpdate {
232
+ /// Creates a camera move to latitude and longitude.
233
+ const CameraUpdateNewLatLng (this .latLng)
234
+ : super ._(CameraUpdateType .newLatLng);
235
+
236
+ /// New latitude and longitude of the camera..
237
+ final LatLng latLng;
238
+ @override
239
+ Object toJson () => < Object > ['newLatLng' , latLng.toJson ()];
240
+ }
241
+
242
+ /// Defines a camera move to a new bounding latitude and longitude range.
243
+ class CameraUpdateNewLatLngBounds extends CameraUpdate {
244
+ /// Creates a camera move to a bounding range.
245
+ const CameraUpdateNewLatLngBounds (this .bounds, this .padding)
246
+ : super ._(CameraUpdateType .newLatLngBounds);
247
+
248
+ /// The northeast and southwest bounding coordinates.
249
+ final LatLngBounds bounds;
250
+
251
+ /// The amount of padding by which the view is inset.
252
+ final double padding;
253
+ @override
254
+ Object toJson () => < Object > ['newLatLngZoom' , bounds.toJson (), padding];
255
+ }
256
+
257
+ /// Defines a camera move to new coordinates with a zoom level.
258
+ class CameraUpdateNewLatLngZoom extends CameraUpdate {
259
+ /// Creates a camera move with coordinates and zoom level.
260
+ const CameraUpdateNewLatLngZoom (this .latLng, this .zoom)
261
+ : super ._(CameraUpdateType .newLatLngZoom);
262
+
263
+ /// New coordinates of the camera.
264
+ final LatLng latLng;
265
+
266
+ /// New zoom level of the camera.
267
+ final double zoom;
268
+ @override
269
+ Object toJson () => < Object > ['newLatLngZoom' , latLng.toJson (), zoom];
270
+ }
271
+
272
+ /// Defines a camera scroll by a certain delta.
273
+ class CameraUpdateScrollBy extends CameraUpdate {
274
+ /// Creates a camera scroll.
275
+ const CameraUpdateScrollBy (this .dx, this .dy)
276
+ : super ._(CameraUpdateType .scrollBy);
277
+
278
+ /// Scroll delta x.
279
+ final double dx;
280
+
281
+ /// Scroll delta y.
282
+ final double dy;
283
+ @override
284
+ Object toJson () => < Object > ['scrollBy' , dx, dy];
285
+ }
286
+
287
+ /// Defines a relative camera zoom.
288
+ class CameraUpdateZoomBy extends CameraUpdate {
289
+ /// Creates a relative camera zoom.
290
+ const CameraUpdateZoomBy (this .amount, [this .focus])
291
+ : super ._(CameraUpdateType .zoomBy);
292
+
293
+ /// Change in camera zoom amount.
294
+ final double amount;
295
+
296
+ /// Optional point around which the zoom is focused.
297
+ final Offset ? focus;
298
+ @override
299
+ Object toJson () => (focus == null )
300
+ ? < Object > ['zoomBy' , amount]
301
+ : < Object > [
302
+ 'zoomBy' ,
303
+ amount,
304
+ < double > [focus! .dx, focus! .dy]
305
+ ];
306
+ }
307
+
308
+ /// Defines a camera zoom in.
309
+ class CameraUpdateZoomIn extends CameraUpdate {
310
+ /// Zooms in the camera.
311
+ const CameraUpdateZoomIn () : super ._(CameraUpdateType .zoomIn);
312
+ @override
313
+ Object toJson () => < Object > ['zoomIn' ];
314
+ }
315
+
316
+ /// Defines a camera zoom out.
317
+ class CameraUpdateZoomOut extends CameraUpdate {
318
+ /// Zooms out the camera.
319
+ const CameraUpdateZoomOut () : super ._(CameraUpdateType .zoomOut);
320
+ @override
321
+ Object toJson () => < Object > ['zoomOut' ];
322
+ }
323
+
324
+ /// Defines a camera zoom to an absolute zoom.
325
+ class CameraUpdateZoomTo extends CameraUpdate {
326
+ /// Creates a zoom to an absolute zoom level.
327
+ const CameraUpdateZoomTo (this .zoom) : super ._(CameraUpdateType .zoomTo);
328
+
329
+ /// New zoom level of the camera.
330
+ final double zoom;
331
+ @override
332
+ Object toJson () => < Object > ['zoomTo' , zoom];
203
333
}
0 commit comments