Description
What is the bug?
The LayerHitResult.coordinate
seems to be in the wrong location (compared to the accurate MapOptions.onTap
) when the map rotation is not 0.
Initially reported and initial MRE created at https://discord.com/channels/951867686378409984/1372837133546684437.
How can we reproduce it?
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(title: 'Flutter Demo', home: MyHomePage());
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final LayerHitNotifier _polygonHitNotifier = ValueNotifier(null);
LatLng? onTap;
LatLng? notifier;
@override
Widget build(BuildContext context) {
return Scaffold(
body: FlutterMap(
options: MapOptions(
initialCenter: const LatLng(30.940609, 40.236738),
initialZoom: 8,
onTap: (tapPosition, point) {
setState(() {
onTap = point;
notifier = _polygonHitNotifier.value?.coordinate;
});
},
),
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
),
PolygonLayer(
hitNotifier: _polygonHitNotifier,
polygons: [
Polygon(
points: const [LatLng(30, 40), LatLng(31, 40), LatLng(32, 41)],
color: Colors.blue,
),
],
),
MarkerLayer(
markers: [
if (onTap != null)
Marker(
alignment: Alignment.topCenter,
height: 32,
width: 32,
point: onTap!,
child: const Icon(
Icons.location_on,
color: Colors.purple,
size: 32,
),
),
if (notifier != null)
Marker(
alignment: Alignment.topCenter,
height: 24,
width: 24,
point: notifier!,
child: const Icon(
Icons.location_on,
color: Colors.red,
),
),
],
),
],
),
);
}
}
Do you have a potential solution?
No response