Show selected point on map

This commit is contained in:
Reimar 2024-08-27 09:15:21 +02:00
parent 2d039a04da
commit 13b7ab187a
Signed by: Reimar
GPG Key ID: 93549FA07F0AE268

View File

@ -47,6 +47,11 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
List<Favorite> _favorites = []; List<Favorite> _favorites = [];
LatLng? _selectedPoint;
void _showLocation(TapPosition _, LatLng point) {
setState(() => _selectedPoint = point);
}
@override @override
void didChangeDependencies() { void didChangeDependencies() {
@ -63,7 +68,6 @@ class _MyHomePageState extends State<MyHomePage> {
_favorites = favorites.map((favorite) => Favorite(favorite['id'], favorite['user_id'], favorite['lat'], favorite['lng'], favorite['name'], favorite['description'])).toList(); _favorites = favorites.map((favorite) => Favorite(favorite['id'], favorite['user_id'], favorite['lat'], favorite['lng'], favorite['name'], favorite['description'])).toList();
}); });
}); });
} }
@override @override
@ -74,7 +78,11 @@ class _MyHomePageState extends State<MyHomePage> {
key: _scaffoldKey, key: _scaffoldKey,
//drawer: navigationMenu, //drawer: navigationMenu,
body: FlutterMap( body: FlutterMap(
options: const MapOptions(initialCenter: LatLng(55.9397, 9.5156), initialZoom: 7.0), options: MapOptions(
initialCenter: const LatLng(55.9397, 9.5156),
initialZoom: 7.0,
onTap: _showLocation,
),
children: [ children: [
openStreetMapTileLayer, openStreetMapTileLayer,
..._favorites.map((favorite) => ..._favorites.map((favorite) =>
@ -91,7 +99,25 @@ class _MyHomePageState extends State<MyHomePage> {
] ]
), ),
) )
]) ]),
),
...(
_selectedPoint != null ? [
MarkerLayer(markers: [
Marker(
point: _selectedPoint!,
width: 30,
height: 50,
alignment: Alignment.center,
child: const Stack(
children: [
Icon(Icons.location_pin, size: 30, color: Colors.red),
Icon(Icons.location_on_outlined, size: 30, color: Colors.black),
]
),
)
]),
] : []
), ),
], ],
), ),