48 lines
1.7 KiB
Dart
48 lines
1.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:latlong2/latlong.dart';
|
|
import 'package:flutter_map/flutter_map.dart';
|
|
import 'package:oc_front/pages/abstract_page.dart';
|
|
|
|
class MapFactory implements AbstractFactory {
|
|
@override GlobalKey getKey() { return key; }
|
|
@override void clear() { }
|
|
static GlobalKey<MapPageWidgetState> key = GlobalKey<MapPageWidgetState>();
|
|
@override bool searchFill() { return false; }
|
|
@override Widget factory(GoRouterState state, List<String> args) { return MapPageWidget(); }
|
|
@override void search(BuildContext context, bool special) { }
|
|
}
|
|
|
|
class MapPageWidget extends StatefulWidget {
|
|
MapPageWidget(): super(key: MapFactory.key);
|
|
@override MapPageWidgetState createState() => MapPageWidgetState();
|
|
static void search(BuildContext context) { }
|
|
static Widget factory() { return MapPageWidget(); }
|
|
}
|
|
class MapPageWidgetState extends State<MapPageWidget> {
|
|
double currentZoom = 2.0;
|
|
LatLng currentCenter = const LatLng(51.5, -0.09);
|
|
static final MapController _mapController = MapController();
|
|
void _zoom() {
|
|
currentZoom = currentZoom - 1;
|
|
_mapController.move(currentCenter, currentZoom);
|
|
}
|
|
|
|
@override Widget build(BuildContext context) {
|
|
return Expanded(
|
|
child : FlutterMap(
|
|
mapController: _mapController,
|
|
options: MapOptions(
|
|
initialCenter: currentCenter,
|
|
initialZoom: currentZoom,
|
|
),
|
|
children: [
|
|
TileLayer(
|
|
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
|
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
|
|
)
|
|
],
|
|
)
|
|
);
|
|
}
|
|
} |