forked from fleaflet/flutter_map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmany_circles.dart
94 lines (85 loc) · 2.7 KB
/
many_circles.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
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_example/widgets/drawer.dart';
import 'package:latlong2/latlong.dart';
const maxCirclesCount = 20000;
/// On this page, [maxCirclesCount] circles are randomly generated
/// across europe, and then you can limit them with a slider
///
/// This way, you can test how map performs under a lot of circles
class ManyCirclesPage extends StatefulWidget {
static const String route = '/many_circles';
const ManyCirclesPage({Key? key}) : super(key: key);
@override
_ManyCirclesPageState createState() => _ManyCirclesPageState();
}
class _ManyCirclesPageState extends State<ManyCirclesPage> {
double doubleInRange(Random source, num start, num end) =>
source.nextDouble() * (end - start) + start;
List<CircleMarker> allCircles = [];
int _sliderVal = maxCirclesCount ~/ 10;
@override
void initState() {
super.initState();
Future.microtask(() {
final r = Random();
for (var x = 0; x < maxCirclesCount; x++) {
allCircles.add(
CircleMarker(
point: LatLng(
doubleInRange(r, 37, 55),
doubleInRange(r, -9, 30),
),
color: Colors.red,
radius: 5,
),
);
}
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('A lot of circles')),
drawer: buildDrawer(context, ManyCirclesPage.route),
body: Column(
children: [
Slider(
min: 0,
max: maxCirclesCount.toDouble(),
divisions: maxCirclesCount ~/ 500,
label: 'Circles',
value: _sliderVal.toDouble(),
onChanged: (newVal) {
_sliderVal = newVal.toInt();
setState(() {});
},
),
Text('$_sliderVal circles'),
Flexible(
child: FlutterMap(
options: const MapOptions(
initialCenter: LatLng(50, 20),
initialZoom: 5,
interactionOptions: InteractionOptions(
flags: InteractiveFlag.all - InteractiveFlag.rotate,
),
),
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
CircleLayer(
circles: allCircles.sublist(
0, min(allCircles.length, _sliderVal))),
],
),
),
],
),
);
}
}