-
Notifications
You must be signed in to change notification settings - Fork 9
/
feature_collection.dart
81 lines (72 loc) · 2.77 KB
/
feature_collection.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
import 'package:flutter/material.dart';
import 'package:fst_app_flutter/models/from_postgres/map/geo_json_types/feature.dart';
import 'package:fst_app_flutter/models/from_postgres/map/geo_json_types/geo_json_object.dart';
import 'package:fst_app_flutter/models/from_postgres/map/geo_json_types/geo_json_type.dart';
import 'package:fst_app_flutter/models/from_postgres/map/geometry_types/geometry_type.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:fst_app_flutter/models/enums/department.dart';
// TODO: document FeatureCollection @richtwin567
class FeatureCollection extends GeoJsonObject {
List<Feature> features;
FeatureCollection({@required this.features})
: assert(features != null),
super(GeoJsonType.featureCollection);
@override
String toGeoJsonFile() {
return {
'\"type\"': '\"${type.toShortString()}\"',
'\"features\"': features.map((e) => e.toGeoJsonFile()).toList()
}.toString();
}
@override
Map<String, Object> toGeoJson() {
return {
'type': type.toShortString(),
'features': features.map((e) => e.toGeoJson()).toList()
};
}
Set<Marker> exportPointsToGoogleMaps() {
return features
.where((feature) => feature.geometry.type == GeoJsonGeometryType.point)
.map((e) => Marker(
onDragEnd: (value) {},
markerId: MarkerId('${e.id}'),
infoWindow: InfoWindow(
snippet:
'Alternative name: ${e.properties.altName}\nDescription: ${e.properties.description}',
title: e.properties.title),
draggable: false,
position: e.geometry.extractLatLng()[0],
alpha: 0.8))
.toSet();
}
Set<Polygon> exportPolygonsToGoogleMaps() {
return features
.where(
(feature) => feature.geometry.type == GeoJsonGeometryType.polygon)
.map((e) => Polygon(
polygonId: PolygonId('${e.id}'),
fillColor:
e.properties.associatedWith.departmentColour.withAlpha(70),
strokeWidth: 1,
strokeColor:
e.properties.associatedWith.departmentColour.withAlpha(70),
points: e.geometry.extractLatLng()))
.toSet();
}
Set<Polyline> exportLineStringsToGoogleMaps() {
return features
.where((feature) =>
feature.geometry.type == GeoJsonGeometryType.lineString)
.map((e) => Polyline(
polylineId: PolylineId('${e.id}'),
color: e.properties.associatedWith.departmentColour.withAlpha(90),
jointType: JointType.round,
endCap: Cap.roundCap,
startCap: Cap.roundCap,
width: 30,
points: e.geometry.extractLatLng(),
))
.toSet();
}
}