-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathcamera.dart
160 lines (138 loc) · 5.25 KB
/
camera.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
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of apple_maps_flutter;
/// The position of the map "camera", the view point from which the world is
/// shown in the map view. Aggregates the camera's [target] geographical
/// location, its [zoom] level, [pitch] angle, and [heading].
class CameraPosition {
const CameraPosition({
required this.target,
this.heading = 0.0,
this.pitch = 0.0,
this.zoom = 0,
});
/// The camera's bearing in degrees, measured clockwise from north.
///
/// A bearing of 0.0, the default, means the camera points north.
/// A bearing of 90.0 means the camera points east.
final double heading;
/// The geographical location that the camera is pointing at.
final LatLng target;
// In degrees where 0 is looking straight down. Pitch may be clamped to an appropriate value.
final double pitch;
/// The zoom level of the camera.
///
/// A zoom of 0.0, the default, means the screen width of the world is 256.
/// Adding 1.0 to the zoom level doubles the screen width of the map. So at
/// zoom level 3.0, the screen width of the world is 2³x256=2048.
///
/// Larger zoom levels thus means the camera is placed closer to the surface
/// of the Earth, revealing more detail in a narrower geographical region.
///
/// The supported zoom level range depends on the map data and device. Values
/// beyond the supported range are allowed, but on applying them to a map they
/// will be silently clamped to the supported range.
final double zoom;
dynamic _toMap() => <String, dynamic>{
'target': target._toJson(),
'heading': heading,
'pitch': pitch,
'zoom': zoom,
};
@visibleForTesting
static CameraPosition? fromMap(dynamic json) {
if (json == null) {
return null;
}
return CameraPosition(
heading: json['heading'],
target: LatLng._fromJson(json['target'])!,
pitch: json['pitch'],
zoom: json['zoom'],
);
}
@override
bool operator ==(dynamic other) {
if (identical(this, other)) return true;
if (runtimeType != other.runtimeType) return false;
final CameraPosition typedOther = other;
return heading == typedOther.heading &&
target == typedOther.target &&
pitch == typedOther.pitch &&
zoom == typedOther.zoom;
}
@override
int get hashCode => Object.hash(heading, target, pitch, zoom);
@override
String toString() =>
'CameraPosition(bearing: $heading, target: $target, tilt: $pitch, zoom: $zoom)';
}
/// Defines a camera move, supporting absolute moves as well as moves relative
/// the current position.
class CameraUpdate {
CameraUpdate._(this._json);
/// Returns a camera update that moves the camera to the specified position.
static CameraUpdate newCameraPosition(CameraPosition cameraPosition) {
return CameraUpdate._(
<dynamic>['newCameraPosition', cameraPosition._toMap()],
);
}
/// Returns a camera update that moves the camera target to the specified
/// geographical location.
static CameraUpdate newLatLng(LatLng latLng) {
return CameraUpdate._(<dynamic>['newLatLng', latLng._toJson()]);
}
/// Returns a camera update that moves the camera target to the specified
/// geographical location and zoom level.
static CameraUpdate newLatLngZoom(LatLng latLng, double zoom) {
return CameraUpdate._(
<dynamic>['newLatLngZoom', latLng._toJson(), zoom],
);
}
/// Returns a camera update that transforms the camera so that the specified
/// geographical bounding box is centered in the map view at the greatest
/// possible zoom level. A non-zero [padding] insets the bounding box from the
/// map view's edges. The camera's new tilt and bearing will both be 0.0.
static CameraUpdate newLatLngBounds(LatLngBounds bounds, double padding) {
return CameraUpdate._(<dynamic>[
'newLatLngBounds',
bounds._toJson(),
padding,
]);
}
/// Returns a camera update that modifies the camera zoom level by the
/// specified amount. The optional [focus] is a screen point whose underlying
/// geographical location should be invariant, if possible, by the movement.
static CameraUpdate zoomBy(double amount, [Offset? focus]) {
if (focus == null) {
return CameraUpdate._(<dynamic>['zoomBy', amount]);
} else {
return CameraUpdate._(<dynamic>[
'zoomBy',
amount,
<double>[focus.dx, focus.dy],
]);
}
}
/// Returns a camera update that zooms the camera in, bringing the camera
/// closer to the surface of the Earth.
///
/// Equivalent to the result of calling `zoomBy(1.0)`.
static CameraUpdate zoomIn() {
return CameraUpdate._(<dynamic>['zoomIn']);
}
/// Returns a camera update that zooms the camera out, bringing the camera
/// further away from the surface of the Earth.
///
/// Equivalent to the result of calling `zoomBy(-1.0)`.
static CameraUpdate zoomOut() {
return CameraUpdate._(<dynamic>['zoomOut']);
}
/// Returns a camera update that sets the camera zoom level.
static CameraUpdate zoomTo(double zoom) {
return CameraUpdate._(<dynamic>['zoomTo', zoom]);
}
final dynamic _json;
dynamic _toJson() => _json;
}