Content-Length: 332292 | pFad | http://github.com/fleaflet/flutter_map/pull/2025/commits/961ab9f3c204804c19a1fa1f19dd289b12f0e059

D9 fix: invoke map interaction callbacks with coordinates in primary world by monsieurtanuki · Pull Request #2025 · fleaflet/flutter_map · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: invoke map interaction callbacks with coordinates in primary world #2025

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: multi-world onTap
Impacted files:
* `camera.dart`: now looking for the best world before unprojecting a pixel
* `multi_worlds.dart`: added an `onTap` event to create on the fly markers
  • Loading branch information
monsieurtanuki committed Jan 30, 2025
commit 961ab9f3c204804c19a1fa1f19dd289b12f0e059
24 changes: 22 additions & 2 deletions example/lib/pages/multi_worlds.dart
Original file line number Diff line number Diff line change
@@ -17,6 +17,24 @@ class MultiWorldsPage extends StatefulWidget {
class _MultiWorldsPageState extends State<MultiWorldsPage> {
final LayerHitNotifier<String> _hitNotifier = ValueNotifier(null);

final _customMarkers = <Marker>[];

Marker _buildPin(LatLng point) => Marker(
point: point,
width: 60,
height: 60,
child: GestureDetector(
onTap: () => ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Tapped existing marker'),
duration: Duration(seconds: 1),
showCloseIcon: true,
),
),
child: const Icon(Icons.location_pin, color: Colors.red),
),
);

@override
Widget build(BuildContext context) {
return Scaffold(
@@ -25,10 +43,11 @@ class _MultiWorldsPageState extends State<MultiWorldsPage> {
body: Stack(
children: [
FlutterMap(
options: const MapOptions(
initialCenter: LatLng(51.5, -0.09),
options: MapOptions(
initialCenter: const LatLng(51.5, -0.09),
initialZoom: 0,
initialRotation: 0,
onTap: (_, p) => setState(() => _customMarkers.add(_buildPin(p))),
),
children: [
openStreetMapTileLayer,
@@ -105,6 +124,7 @@ class _MultiWorldsPageState extends State<MultiWorldsPage> {
child: const Icon(Icons.backpack_outlined),
),
),
..._customMarkers,
],
),
],
18 changes: 14 additions & 4 deletions lib/src/map/camera/camera.dart
Original file line number Diff line number Diff line change
@@ -240,12 +240,12 @@ class MapCamera {
crs.offsetToLatLng(point, zoom ?? this.zoom);

//github.com/ Returns the width of the world at the current zoom, or 0 if irrelevant.
double getWorldWidthAtZoom() {
double getWorldWidthAtZoom([double? zoom]) {
if (!crs.replicatesWorldLongitude) {
return 0;
}
final offset0 = projectAtZoom(const LatLng(0, 0));
final offset180 = projectAtZoom(const LatLng(0, 180));
final offset0 = projectAtZoom(const LatLng(0, 0), zoom ?? this.zoom);
final offset180 = projectAtZoom(const LatLng(0, 180), zoom ?? this.zoom);
return 2 * (offset180.dx - offset0.dx).abs();
}

@@ -357,7 +357,17 @@ class MapCamera {
(offset - nonRotatedSize.center(Offset.zero)).rotate(rotationRad);

final newCenterPt = focalStartPt + point;
return unprojectAtZoom(newCenterPt, zoom ?? this.zoom);
final worldWidth = getWorldWidthAtZoom(zoom ?? this.zoom);
double bestX = newCenterPt.dx;
if (worldWidth != 0) {
while (bestX > worldWidth) {
bestX -= worldWidth;
}
while (bestX < 0) {
bestX += worldWidth;
}
}
return unprojectAtZoom(Offset(bestX, newCenterPt.dy), zoom ?? this.zoom);
}

//github.com/ Calculate the center point which would keep the same point of the map








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/fleaflet/flutter_map/pull/2025/commits/961ab9f3c204804c19a1fa1f19dd289b12f0e059

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy