forked from fleaflet/flutter_map
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added MapController.pointToLatLng() to get LatLng of given screen point
Ref fleaflet#496, ref fleaflet#607, ref fleaflet#981, ref fleaflet#1010
- Loading branch information
1 parent
f6e2b23
commit 9a920b5
Showing
5 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_map/flutter_map.dart'; | ||
import 'package:latlong2/latlong.dart'; | ||
|
||
import '../widgets/drawer.dart'; | ||
|
||
class PointToLatLngPage extends StatefulWidget { | ||
static const String route = 'point_to_latlng'; | ||
|
||
@override | ||
PointToLatlngPage createState() { | ||
return PointToLatlngPage(); | ||
} | ||
} | ||
|
||
class PointToLatlngPage extends State<PointToLatLngPage> { | ||
late final MapController mapController; | ||
final pointX = 100.0; | ||
final pointY = 100.0; | ||
final pointSize = 20.0; | ||
late final mapEventSubscription; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
mapController = MapController(); | ||
|
||
mapEventSubscription = mapController.mapEventStream.listen(onMapEvent); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(title: Text('PointToLatlng')), | ||
drawer: buildDrawer(context, PointToLatLngPage.route), | ||
body: Stack( | ||
children: [ | ||
FlutterMap( | ||
mapController: mapController, | ||
options: MapOptions( | ||
center: LatLng(51.5, -0.09), | ||
zoom: 5.0, | ||
maxZoom: 5.0, | ||
minZoom: 3.0, | ||
), | ||
layers: [ | ||
TileLayerOptions( | ||
urlTemplate: | ||
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', | ||
subdomains: ['a', 'b', 'c']), | ||
], | ||
), | ||
Positioned( | ||
top: pointY, | ||
left: pointX, | ||
child: Container( | ||
color: Colors.red, width: pointSize, height: pointSize)) | ||
], | ||
), | ||
); | ||
} | ||
|
||
void onMapEvent(MapEvent mapEvent) { | ||
if (mapEvent is MapEventMove) { | ||
final latLng = mapController.pointToLatLng(CustomPoint(pointX, pointY)); | ||
|
||
print('top left of square is hovering $latLng'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters