-
-
Notifications
You must be signed in to change notification settings - Fork 897
Expand file tree
/
Copy pathcamera_constraint_test.dart
More file actions
110 lines (89 loc) · 3.06 KB
/
camera_constraint_test.dart
File metadata and controls
110 lines (89 loc) · 3.06 KB
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
import 'dart:ui';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:latlong2/latlong.dart';
void main() {
group('CameraConstraint', () {
group('contain', () {
test('rotated', () {
final mapConstraint = CameraConstraint.contain(
bounds: LatLngBounds(
const LatLng(-90, -180),
const LatLng(90, 180),
),
);
final camera = MapCamera(
crs: const Epsg3857(),
center: const LatLng(-90, -180),
zoom: 1,
rotation: 45,
nonRotatedSize: const Size(200, 300),
);
final clamped = mapConstraint.constrain(camera)!;
expect(clamped.zoom, 1);
expect(clamped.center.latitude, closeTo(-48.562, 0.001));
expect(clamped.center.longitude, closeTo(-55.703, 0.001));
expect(clamped.constrained, isTrue);
});
});
group('containVertically', () {
test('western longitude', () {
const mapConstraint = CameraConstraint.containLatitude();
final camera = MapCamera(
crs: const Epsg3857(),
center: const LatLng(0, -179.9),
zoom: 1,
rotation: 0,
nonRotatedSize: const Size(200, 300),
);
final clamped = mapConstraint.constrain(camera)!;
expect(clamped.zoom, 1);
expect(clamped.center.latitude, closeTo(0, 0.001));
expect(clamped.center.longitude, closeTo(-179.9, 0.001));
expect(clamped.constrained, isFalse);
});
});
test('top right corner', () {
const mapConstraint = CameraConstraint.containLatitude();
final camera = MapCamera(
crs: const Epsg3857(),
center: const LatLng(-90, 179),
zoom: 1,
rotation: 0,
nonRotatedSize: const Size(200, 300),
);
final clamped = mapConstraint.constrain(camera)!;
expect(clamped.zoom, 1);
expect(clamped.center.latitude, closeTo(-59.534, 0.001));
expect(clamped.center.longitude, closeTo(179, 0.001));
expect(clamped.constrained, isTrue);
});
test('northern hemisphere', () {
const mapConstraint = CameraConstraint.containLatitude(0, 90);
final camera = MapCamera(
crs: const Epsg3857(),
center: const LatLng(-10, 179),
zoom: 2,
rotation: 0,
nonRotatedSize: const Size(200, 300),
);
final clamped = mapConstraint.constrain(camera)!;
expect(clamped.zoom, 2);
expect(clamped.center.latitude, closeTo(46.558, 0.001));
expect(clamped.center.longitude, closeTo(179, 0.001));
expect(clamped.constrained, isTrue);
});
test('can not translate camera within bounds', () {
const mapConstraint = CameraConstraint.containLatitude(0, 90);
final camera = MapCamera(
crs: const Epsg3857(),
center: const LatLng(60, 179),
zoom: 1,
rotation: 0,
nonRotatedSize: const Size(200, 300),
);
final clamped = mapConstraint.constrain(camera);
expect(clamped, isNull);
});
});
}