more stuff
This commit is contained in:
parent
6cfa24f1e3
commit
ffa0c0ff34
|
@ -3,9 +3,8 @@ import 'dart:convert';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
import 'package:flutter_map/flutter_map.dart';
|
||||||
import 'package:flutter_map/plugin_api.dart';
|
import 'package:flutter_map/plugin_api.dart';
|
||||||
import 'package:flutter_map_animations/flutter_map_animations.dart';
|
|
||||||
import 'package:flutter_map_supercluster/flutter_map_supercluster.dart';
|
|
||||||
import 'package:latlong2/latlong.dart';
|
import 'package:latlong2/latlong.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
|
@ -19,35 +18,15 @@ class MapScreen extends StatefulWidget {
|
||||||
State<MapScreen> createState() => _MapScreenState();
|
State<MapScreen> createState() => _MapScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MapScreenState extends State<MapScreen> with TickerProviderStateMixin {
|
class _MapScreenState extends State<MapScreen> {
|
||||||
late List _stations = [];
|
List _stations = [];
|
||||||
late final List<Marker> markers;
|
List<Marker> _markers = [];
|
||||||
late final SuperclusterImmutableController _superclusterController;
|
|
||||||
late final AnimatedMapController _animatedMapController;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_superclusterController = SuperclusterImmutableController();
|
|
||||||
_animatedMapController = AnimatedMapController(vsync: this);
|
|
||||||
|
|
||||||
markers = [];
|
_getStations();
|
||||||
|
|
||||||
for (var i = 0; i < _stations.length; i++) {
|
|
||||||
final latLng =
|
|
||||||
LatLng(double.parse(_stations[i][4]), double.parse(_stations[i][5]));
|
|
||||||
|
|
||||||
markers.add(
|
|
||||||
Marker(
|
|
||||||
anchorPos: AnchorPos.align(AnchorAlign.top),
|
|
||||||
rotateAlignment: AnchorAlign.top.rotationAlignment,
|
|
||||||
height: 30,
|
|
||||||
width: 30,
|
|
||||||
point: latLng,
|
|
||||||
builder: (ctx) => const Icon(Icons.pin_drop),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _getStations() async {
|
Future<void> _getStations() async {
|
||||||
|
@ -55,8 +34,23 @@ class _MapScreenState extends State<MapScreen> with TickerProviderStateMixin {
|
||||||
await rootBundle.loadString("assets/data/stations.json");
|
await rootBundle.loadString("assets/data/stations.json");
|
||||||
final data = await json.decode(stationFile);
|
final data = await json.decode(stationFile);
|
||||||
|
|
||||||
|
List<Marker> markers = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < _stations.length; i++) {
|
||||||
|
markers.add(
|
||||||
|
Marker(
|
||||||
|
height: 30,
|
||||||
|
width: 30,
|
||||||
|
point: LatLng(double.tryParse(_stations[i][4].toString()) ?? 0,
|
||||||
|
double.tryParse(_stations[i][5].toString()) ?? 0),
|
||||||
|
builder: (ctx) => const Icon(Icons.pin_drop),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_stations = data["records"];
|
_stations = data["records"];
|
||||||
|
_markers = markers;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,61 +72,14 @@ class _MapScreenState extends State<MapScreen> with TickerProviderStateMixin {
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed: () => {print("deez")}, child: const Icon(Icons.add)),
|
onPressed: () => {print("deez")}, child: const Icon(Icons.add)),
|
||||||
body: FlutterMap(
|
body: FlutterMap(
|
||||||
mapController: _animatedMapController.mapController,
|
options:
|
||||||
options: MapOptions(
|
MapOptions(center: const LatLng(13.736717, 100.523186), zoom: 2.0),
|
||||||
// center: LatLng((maxLatLng.latitude + minLatLng.latitude) / 2,
|
children: [
|
||||||
// (maxLatLng.longitude + minLatLng.longitude) / 2),
|
|
||||||
zoom: 6,
|
|
||||||
maxZoom: 15,
|
|
||||||
),
|
|
||||||
nonRotatedChildren: [
|
|
||||||
Builder(
|
|
||||||
builder: (context) =>
|
|
||||||
Text(FlutterMapState.maybeOf(context)!.zoom.toString()),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
children: <Widget>[
|
|
||||||
TileLayer(
|
TileLayer(
|
||||||
urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||||
subdomains: const ['a', 'b', 'c'],
|
userAgentPackageName: 'net.winscloud,net',
|
||||||
),
|
|
||||||
SuperclusterLayer.immutable(
|
|
||||||
initialMarkers: markers,
|
|
||||||
indexBuilder: IndexBuilders.computeWithOriginalMarkers,
|
|
||||||
controller: _superclusterController,
|
|
||||||
moveMap: (center, zoom) => _animatedMapController.animateTo(
|
|
||||||
dest: center,
|
|
||||||
zoom: zoom,
|
|
||||||
),
|
|
||||||
calculateAggregatedClusterData: true,
|
|
||||||
clusterWidgetSize: const Size(40, 40),
|
|
||||||
anchor: AnchorPos.align(AnchorAlign.center),
|
|
||||||
popupOptions: PopupOptions(
|
|
||||||
selectedMarkerBuilder: (context, marker) => const Icon(
|
|
||||||
Icons.pin_drop,
|
|
||||||
color: Colors.red,
|
|
||||||
),
|
|
||||||
popupDisplayOptions: PopupDisplayOptions(
|
|
||||||
builder: (BuildContext context, Marker marker) => Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: Text(marker.point.toString()),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
builder: (context, position, markerCount, extraClusterData) {
|
|
||||||
return Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.circular(20.0),
|
|
||||||
color: Colors.blue),
|
|
||||||
child: Center(
|
|
||||||
child: Text(
|
|
||||||
markerCount.toString(),
|
|
||||||
style: const TextStyle(color: Colors.white),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
|
MarkerLayer(markers: _markers)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue