-
-
Notifications
You must be signed in to change notification settings - Fork 863
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved screen point /
LatLng
example pages
Moved `NetworkTileProvider` info log to `TileLayer` to only print once
- Loading branch information
1 parent
c54e02e
commit c81176b
Showing
7 changed files
with
190 additions
and
184 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
This file was deleted.
Oops, something went wrong.
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,107 @@ | ||
import 'dart:math'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_map/flutter_map.dart'; | ||
import 'package:flutter_map_example/widgets/drawer.dart'; | ||
import 'package:latlong2/latlong.dart'; | ||
|
||
class ScreenPointToLatLngPage extends StatefulWidget { | ||
static const String route = '/screen_point_to_latlng'; | ||
|
||
const ScreenPointToLatLngPage({Key? key}) : super(key: key); | ||
|
||
@override | ||
PointToLatlngPage createState() { | ||
return PointToLatlngPage(); | ||
} | ||
} | ||
|
||
class PointToLatlngPage extends State<ScreenPointToLatLngPage> { | ||
static const double pointSize = 65; | ||
static const double pointY = 250; | ||
|
||
final mapController = MapController(); | ||
|
||
LatLng? latLng; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
WidgetsBinding.instance.addPostFrameCallback((_) => updatePoint(context)); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(title: const Text('Screen Point 🡒 Lat/Lng')), | ||
drawer: buildDrawer(context, ScreenPointToLatLngPage.route), | ||
body: Stack( | ||
children: [ | ||
FlutterMap( | ||
mapController: mapController, | ||
options: MapOptions( | ||
onPositionChanged: (_, __) => updatePoint(context), | ||
initialCenter: const LatLng(51.5, -0.09), | ||
initialZoom: 5, | ||
minZoom: 3, | ||
), | ||
children: [ | ||
TileLayer( | ||
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', | ||
userAgentPackageName: 'dev.fleaflet.flutter_map.example', | ||
), | ||
if (latLng != null) | ||
MarkerLayer( | ||
markers: [ | ||
Marker( | ||
width: pointSize, | ||
height: pointSize, | ||
point: latLng!, | ||
builder: (ctx) => const Icon( | ||
Icons.circle, | ||
size: 10, | ||
color: Colors.black, | ||
), | ||
) | ||
], | ||
), | ||
], | ||
), | ||
Positioned( | ||
top: pointY - pointSize / 2, | ||
left: _getPointX(context) - pointSize / 2, | ||
child: const IgnorePointer( | ||
child: Icon( | ||
Icons.center_focus_strong_outlined, | ||
size: pointSize, | ||
color: Colors.black, | ||
), | ||
), | ||
), | ||
Positioned( | ||
top: pointY + pointSize / 2 + 6, | ||
left: 0, | ||
right: 0, | ||
child: IgnorePointer( | ||
child: Text( | ||
'(${latLng?.latitude.toStringAsFixed(3)},${latLng?.longitude.toStringAsFixed(3)})', | ||
textAlign: TextAlign.center, | ||
style: const TextStyle( | ||
color: Colors.black, | ||
fontWeight: FontWeight.bold, | ||
fontSize: 16, | ||
), | ||
), | ||
), | ||
) | ||
], | ||
), | ||
); | ||
} | ||
|
||
void updatePoint(BuildContext context) => setState(() => latLng = | ||
mapController.camera.pointToLatLng(Point(_getPointX(context), pointY))); | ||
|
||
double _getPointX(BuildContext context) => | ||
MediaQuery.sizeOf(context).width / 2; | ||
} |
Oops, something went wrong.