This repository was archived by the owner on Jun 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 188
Expand file tree
/
Copy pathpolygon.dart
More file actions
91 lines (78 loc) · 2.21 KB
/
polygon.dart
File metadata and controls
91 lines (78 loc) · 2.21 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
import 'dart:ui';
import 'package:cirrus_map_view/figure_joint_type.dart';
import 'package:cirrus_map_view/location.dart';
class Polygon {
final String id;
List<Location> points;
List<Hole> holes;
final double strokeWidth;
final Color fillColor;
final Color strokeColor;
///Only supported in Android. iOS don't have this for some reason.
///https://developers.google.com/android/reference/com/google/android/gms/maps/model/JointType
final FigureJointType jointType;
static const Color _defaultColor = const Color(-769226);
static const double _defaultWidth = 10.0;
static const FigureJointType _defaultJointType = FigureJointType.def;
static const List<Hole> _defaultHoles = <Hole>[];
Polygon(
this.id,
this.points, {
this.fillColor: _defaultColor,
this.strokeColor: _defaultColor,
this.strokeWidth: _defaultWidth,
this.jointType: _defaultJointType,
this.holes: _defaultHoles,
});
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Polygon && runtimeType == other.runtimeType && id == other.id;
@override
int get hashCode => id.hashCode;
Map<String, dynamic> toMap() {
return {
"id": id,
"points": Location.listToMap(points),
"holes": Hole.listToMap(holes),
"strokeWidth": strokeWidth,
"jointType": jointType.value,
"fillColor": {
"r": fillColor.red,
"g": fillColor.green,
"b": fillColor.blue,
"a": fillColor.alpha
},
"strokeColor": {
"r": strokeColor.red,
"g": strokeColor.green,
"b": strokeColor.blue,
"a": strokeColor.alpha
},
};
}
}
class Hole {
List<Location> points = [];
Hole(this.points);
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Hole &&
runtimeType == other.runtimeType &&
points == other.points;
@override
int get hashCode => points.hashCode;
static listToMap(List<Hole> holes) {
List<Map<String, dynamic>> result = [];
for (var element in holes) {
result.add(element.toMap());
}
return result;
}
Map<String, dynamic> toMap() {
return {
"points": Location.listToMap(points),
};
}
}