diff --git a/lib/pages/map.dart b/lib/pages/map.dart index a4f1c8c..cd57c81 100644 --- a/lib/pages/map.dart +++ b/lib/pages/map.dart @@ -3,9 +3,8 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_map/flutter_map.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'; void main() async { @@ -19,35 +18,15 @@ class MapScreen extends StatefulWidget { State createState() => _MapScreenState(); } -class _MapScreenState extends State with TickerProviderStateMixin { - late List _stations = []; - late final List markers; - late final SuperclusterImmutableController _superclusterController; - late final AnimatedMapController _animatedMapController; +class _MapScreenState extends State { + List _stations = []; + List _markers = []; @override void initState() { super.initState(); - _superclusterController = SuperclusterImmutableController(); - _animatedMapController = AnimatedMapController(vsync: this); - markers = []; - - 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), - ), - ); - } + _getStations(); } Future _getStations() async { @@ -55,8 +34,23 @@ class _MapScreenState extends State with TickerProviderStateMixin { await rootBundle.loadString("assets/data/stations.json"); final data = await json.decode(stationFile); + List 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(() { _stations = data["records"]; + _markers = markers; }); } @@ -78,61 +72,14 @@ class _MapScreenState extends State with TickerProviderStateMixin { floatingActionButton: FloatingActionButton( onPressed: () => {print("deez")}, child: const Icon(Icons.add)), body: FlutterMap( - mapController: _animatedMapController.mapController, - options: MapOptions( - // center: LatLng((maxLatLng.latitude + minLatLng.latitude) / 2, - // (maxLatLng.longitude + minLatLng.longitude) / 2), - zoom: 6, - maxZoom: 15, - ), - nonRotatedChildren: [ - Builder( - builder: (context) => - Text(FlutterMapState.maybeOf(context)!.zoom.toString()), - ) - ], - children: [ + options: + MapOptions(center: const LatLng(13.736717, 100.523186), zoom: 2.0), + children: [ TileLayer( - urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', - subdomains: const ['a', 'b', 'c'], - ), - 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), - ), - ), - ); - }, + urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', + userAgentPackageName: 'net.winscloud,net', ), + MarkerLayer(markers: _markers) ], ), );