oc-front/lib/pages/map.dart

47 lines
1.7 KiB
Dart
Raw Normal View History

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 {
2024-11-08 13:59:22 +01:00
@override GlobalKey getKey() { return key; }
static GlobalKey<MapPageWidgetState> key = GlobalKey<MapPageWidgetState>();
@override bool searchFill() { return false; }
@override Widget factory(GoRouterState state, List<String> args) { return MapPageWidget(); }
2024-11-08 13:59:22 +01:00
@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',
)
],
)
);
}
}