staticmap.dart
1.53 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
import 'core.dart';
class Path {
final String? color;
final String? enc;
Path({
this.color,
this.enc,
});
@override
String toString() {
return [
color != null ? 'color:$color' : null,
enc != null ? 'enc:$enc' : null,
].where((v) => v != null).join('|');
}
}
// TOOD should extends GoogleWebService
class StaticMap {
final String? polyEncode;
final List<Location> markers;
final String _apiKey;
final String? zoom;
final String size;
final String? center;
final bool scale;
final Path? path;
final String mapType;
StaticMap(
this._apiKey, {
this.polyEncode,
this.markers = const [],
this.zoom,
this.size = '580x267',
this.center,
this.scale = false,
this.path,
this.mapType = 'roadmap',
}) : assert(
size.contains('x'),
);
String getUrl() {
final params = <String, String>{};
if (path != null) {
params['path'] = path.toString();
}
if (markers.isNotEmpty) {
params['markers'] = markers.join('|');
}
final z = zoom;
if (z != null && z.isNotEmpty) {
params['zoom'] = z;
}
if (scale) {
params['scale'] = scale.toString();
}
final c = center;
if (c != null && c.isNotEmpty) {
params['center'] = c;
}
params.addAll({
'key': _apiKey,
'size': size,
'mapType': mapType,
});
return Uri(
scheme: 'https',
host: 'maps.googleapis.com',
path: 'maps/api/staticmap',
queryParameters: params,
).toString();
}
}