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

migrate latlng to use record type (feedback requested) #1750

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
13 changes: 6 additions & 7 deletions benchmark/crs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:math' as math;

import 'package:flutter_map/src/geo/crs.dart';
import 'package:latlong2/latlong.dart';
import 'package:logger/logger.dart';

class NoFilter extends LogFilter {
Expand Down Expand Up @@ -41,7 +40,7 @@ Future<void> main() async {
double x = 0;
double y = 0;
for (int i = 0; i < N; ++i) {
final latlng = LatLng((i % 90).toDouble(), (i % 180).toDouble());
final latlng = (lat: (i % 90).toDouble(), lon: (i % 180).toDouble());
final (cx, cy) = crs.latLngToXY(latlng, 1);
x += cx;
y += cy;
Expand All @@ -53,7 +52,7 @@ Future<void> main() async {
double x = 0;
double y = 0;
for (int i = 0; i < N; ++i) {
final latlng = LatLng((i % 90).toDouble(), (i % 180).toDouble());
final latlng = (lat: (i % 90).toDouble(), lon: (i % 180).toDouble());
final p = crs.latLngToPoint(latlng, 1);
x += p.x;
y += p.y;
Expand All @@ -71,7 +70,7 @@ Future<void> main() async {
double x = 0;
double y = 0;
for (int i = 0; i < N; ++i) {
final latlng = LatLng((i % 90).toDouble(), (i % 180).toDouble());
final latlng = (lat: (i % 90).toDouble(), lon: (i % 180).toDouble());
final (cx, cy) = crs.latLngToXY(latlng, 1);
x += cx;
y += cy;
Expand All @@ -83,7 +82,7 @@ Future<void> main() async {
double x = 0;
double y = 0;
for (int i = 0; i < N; ++i) {
final latlng = LatLng((i % 90).toDouble(), (i % 180).toDouble());
final latlng = (lat: (i % 90).toDouble(), lon: (i % 180).toDouble());
final point = crs.latLngToPoint(latlng, 1);
x += point.x;
y += point.y;
Expand All @@ -96,8 +95,8 @@ Future<void> main() async {
double y = 0;
for (int i = 0; i < N; ++i) {
final latlng = crs.pointToLatLng(math.Point<double>(x, y), 1);
x += latlng.longitude;
y += latlng.latitude;
x += latlng.lon;
y += latlng.lat;
}
return x + y;
}));
Expand Down
23 changes: 11 additions & 12 deletions example/lib/pages/animated_map_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_cancellable_tile_provider/flutter_map_cancellable_tile_provider.dart';
import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart';
import 'package:latlong2/latlong.dart';

class AnimatedMapControllerPage extends StatefulWidget {
static const String route = '/map_controller_animated';
Expand All @@ -20,9 +19,9 @@ class AnimatedMapControllerPageState extends State<AnimatedMapControllerPage>
static const _inProgressId = 'AnimatedMapController#MoveInProgress';
static const _finishedId = 'AnimatedMapController#MoveFinished';

static const _london = LatLng(51.5, -0.09);
static const _paris = LatLng(48.8566, 2.3522);
static const _dublin = LatLng(53.3498, -6.2603);
static const _london = (lat: 51.5, lon: -0.09);
static const _paris = (lat: 48.8566, lon: 2.3522);
static const _dublin = (lat: 53.3498, lon: -6.2603);

static const _markers = [
Marker(
Expand Down Expand Up @@ -51,10 +50,10 @@ class AnimatedMapControllerPageState extends State<AnimatedMapControllerPage>
// Create some tweens. These serve to split up the transition from one location to another.
// In our case, we want to split the transition be<tween> our current map center and the destination.
final camera = mapController.camera;
final latTween = Tween<double>(
begin: camera.center.latitude, end: destLocation.latitude);
final lngTween = Tween<double>(
begin: camera.center.longitude, end: destLocation.longitude);
final latTween =
Tween<double>(begin: camera.center.lat, end: destLocation.lat);
final lngTween =
Tween<double>(begin: camera.center.lon, end: destLocation.lon);
final zoomTween = Tween<double>(begin: camera.zoom, end: destZoom);

// Create a animation controller that has a duration and a TickerProvider.
Expand All @@ -70,7 +69,7 @@ class AnimatedMapControllerPageState extends State<AnimatedMapControllerPage>
// to detect an appropriate animated movement event which contains the
// target zoom/center.
final startIdWithTarget =
'$_startedId#${destLocation.latitude},${destLocation.longitude},$destZoom';
'$_startedId#${destLocation.lat},${destLocation.lon},$destZoom';
bool hasTriggeredMove = false;

controller.addListener(() {
Expand All @@ -84,7 +83,7 @@ class AnimatedMapControllerPageState extends State<AnimatedMapControllerPage>
}

hasTriggeredMove |= mapController.move(
LatLng(latTween.evaluate(animation), lngTween.evaluate(animation)),
(lat: latTween.evaluate(animation), lon: lngTween.evaluate(animation)),
zoomTween.evaluate(animation),
id: id,
);
Expand Down Expand Up @@ -172,7 +171,7 @@ class AnimatedMapControllerPageState extends State<AnimatedMapControllerPage>
child: FlutterMap(
mapController: mapController,
options: const MapOptions(
initialCenter: LatLng(51.5, -0.09),
initialCenter: (lat: 51.5, lon: 0.09),
initialZoom: 5,
maxZoom: 10,
minZoom: 3,
Expand Down Expand Up @@ -216,7 +215,7 @@ final _animatedMoveTileUpdateTransformer =
// whilst animating.
sink.add(
updateEvent.loadOnly(
loadCenterOverride: LatLng(lat, lon),
loadCenterOverride: (lat: lat, lon: lon),
loadZoomOverride: zoom,
),
);
Expand Down
7 changes: 3 additions & 4 deletions example/lib/pages/bundled_offline_map.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart';
import 'package:latlong2/latlong.dart';

class BundledOfflineMapPage extends StatelessWidget {
static const String route = '/bundled_offline_map';
Expand All @@ -15,13 +14,13 @@ class BundledOfflineMapPage extends StatelessWidget {
drawer: const MenuDrawer(route),
body: FlutterMap(
options: MapOptions(
initialCenter: const LatLng(56.704173, 11.543808),
initialCenter: const (lat: 56.704173, lon: 11.543808),
minZoom: 12,
maxZoom: 14,
cameraConstraint: CameraConstraint.containCenter(
bounds: LatLngBounds(
const LatLng(56.7378, 11.6644),
const LatLng(56.6877, 11.5089),
const (lat: 56.7378, lon: 11.6644),
const (lat: 56.6877, lon: 11.5089),
),
),
),
Expand Down
7 changes: 3 additions & 4 deletions example/lib/pages/cancellable_tile_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_cancellable_tile_provider/flutter_map_cancellable_tile_provider.dart';
import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart';
import 'package:flutter_map_example/widgets/notice_banner.dart';
import 'package:latlong2/latlong.dart';

class CancellableTileProviderPage extends StatefulWidget {
static const String route = '/cancellable_tile_provider_page';
Expand Down Expand Up @@ -47,12 +46,12 @@ class _CancellableTileProviderPageState
Expanded(
child: FlutterMap(
options: MapOptions(
initialCenter: const LatLng(51.5, -0.09),
initialCenter: const (lat: 51.5, lon: 0.09),
initialZoom: 5,
cameraConstraint: CameraConstraint.contain(
bounds: LatLngBounds(
const LatLng(-90, -180),
const LatLng(90, 180),
const (lat: -90, lon: 180),
const (lat: 90, lon: 180),
),
),
),
Expand Down
7 changes: 3 additions & 4 deletions example/lib/pages/circle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_example/misc/tile_providers.dart';
import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart';
import 'package:latlong2/latlong.dart';

class CirclePage extends StatelessWidget {
static const String route = '/circle';
Expand All @@ -16,23 +15,23 @@ class CirclePage extends StatelessWidget {
drawer: const MenuDrawer(route),
body: FlutterMap(
options: const MapOptions(
initialCenter: LatLng(51.5, -0.09),
initialCenter: (lat: 51.5, lon: 0.09),
initialZoom: 11,
),
children: [
openStreetMapTileLayer,
CircleLayer(
circles: [
CircleMarker(
point: const LatLng(51.5, -0.09),
point: const (lat: 51.5, lon: 0.09),
color: Colors.blue.withOpacity(0.7),
borderColor: Colors.black,
borderStrokeWidth: 2,
useRadiusInMeter: true,
radius: 2000, // 2000 meters
),
CircleMarker(
point: const LatLng(51.4937, -0.6638),
point: const (lat: 51.4937, lon: 0.6638),
// Dorney Lake is ~2km long
color: Colors.green.withOpacity(0.9),
borderColor: Colors.black,
Expand Down
2 changes: 1 addition & 1 deletion example/lib/pages/custom_crs/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Proj4Crs has multiple uses:
options: MapOptions(
// Set the default CRS
crs: epsg3413CRS,
center: LatLng(65.05166470332148, -19.171744826394896),
center: (lat: 65.05166470332148, lon: 19.171744826394896),
zoom: 3.0,
maxZoom: maxZoom,
),
Expand Down
5 changes: 2 additions & 3 deletions example/lib/pages/custom_crs/custom_crs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart';
import 'package:latlong2/latlong.dart';
import 'package:proj4dart/proj4dart.dart' as proj4;
import 'package:url_launcher/url_launcher.dart';

Expand Down Expand Up @@ -128,14 +127,14 @@ class CustomCrsPageState extends State<CustomCrsPage> {
options: MapOptions(
// Set the default CRS
crs: epsg3413CRS,
initialCenter: LatLng(point.x, point.y),
initialCenter: (lat: point.x, lon: point.y),
initialZoom: 3,
// Set maxZoom usually scales.length - 1 OR resolutions.length - 1
// but not greater
maxZoom: maxZoom,
onTap: (tapPosition, p) => setState(() {
initText = 'You clicked at';
point = proj4.Point(x: p.latitude, y: p.longitude);
point = proj4.Point(x: p.lat, y: p.lon);
}),
),
children: [
Expand Down
18 changes: 9 additions & 9 deletions example/lib/pages/epsg3413_crs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart';
import 'package:latlong2/latlong.dart';
import 'package:latlong2/latlong.dart' as latlong2;
import 'package:proj4dart/proj4dart.dart' as proj4;
import 'package:url_launcher/url_launcher.dart';

Expand All @@ -19,8 +19,8 @@ class EPSG3413Page extends StatefulWidget {
class EPSG3413PageState extends State<EPSG3413Page> {
late final Proj4Crs epsg3413CRS;

final distancePoleToLat80 =
const Distance().distance(const LatLng(90, 0), const LatLng(80, 0));
final distancePoleToLat80 = const latlong2.Distance()
.distance(const latlong2.LatLng(90, 0), const latlong2.LatLng(80, 0));

double? maxZoom;

Expand Down Expand Up @@ -73,15 +73,15 @@ class EPSG3413PageState extends State<EPSG3413Page> {
// These circles should have the same pixel radius on the map
final circles = [
const CircleMarker(
point: LatLng(90, 0),
point: (lat: 90, lon: 0),
radius: 20000,
useRadiusInMeter: true,
color: Colors.yellow,
)
];
for (final lon in [-90.0, 0.0, 90.0, 180.0]) {
circles.add(CircleMarker(
point: LatLng(80, lon),
point: (lat: 80, lon: lon),
radius: 20000,
useRadiusInMeter: true,
color: Colors.red,
Expand All @@ -90,7 +90,7 @@ class EPSG3413PageState extends State<EPSG3413Page> {

// Add latitude line at 80 degrees
circles.add(CircleMarker(
point: const LatLng(90, 0),
point: const (lat: 90, lon: 0),
radius: distancePoleToLat80,
useRadiusInMeter: true,
color: Colors.transparent,
Expand Down Expand Up @@ -135,7 +135,7 @@ class EPSG3413PageState extends State<EPSG3413Page> {
child: FlutterMap(
options: MapOptions(
crs: epsg3413CRS,
initialCenter: const LatLng(90, 0),
initialCenter: const (lat: 90, lon: 0),
initialZoom: 3,
maxZoom: maxZoom,
),
Expand All @@ -154,8 +154,8 @@ class EPSG3413PageState extends State<EPSG3413Page> {
overlayImages: [
OverlayImage(
bounds: LatLngBounds(
const LatLng(72.7911372, 162.6196478),
const LatLng(85.2802493, 79.794166),
const (lat: 72.7911372, lon: 162.6196478),
const (lat: 85.2802493, lon: 79.794166),
),
imageProvider: Image.asset(
'assets/map/epsg3413/amsr2.png',
Expand Down
3 changes: 1 addition & 2 deletions example/lib/pages/epsg4326_crs.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart';
import 'package:latlong2/latlong.dart';

class EPSG4326Page extends StatelessWidget {
static const String route = '/crs_epsg4326';
Expand All @@ -17,7 +16,7 @@ class EPSG4326Page extends StatelessWidget {
options: const MapOptions(
minZoom: 0,
crs: Epsg4326(),
initialCenter: LatLng(0, 0),
initialCenter: (lat: 0, lon: 0),
initialZoom: 0,
),
children: [
Expand Down
3 changes: 1 addition & 2 deletions example/lib/pages/fallback_url_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_cancellable_tile_provider/flutter_map_cancellable_tile_provider.dart';
import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart';
import 'package:flutter_map_example/widgets/notice_banner.dart';
import 'package:latlong2/latlong.dart';

class FallbackUrlPage extends StatelessWidget {
static const String route = '/fallback_url';
Expand Down Expand Up @@ -33,7 +32,7 @@ class FallbackUrlPage extends StatelessWidget {
Flexible(
child: FlutterMap(
options: const MapOptions(
initialCenter: LatLng(51.5, -0.09),
initialCenter: (lat: 51.5, lon: 0.09),
initialZoom: 5,
),
children: [
Expand Down
7 changes: 3 additions & 4 deletions example/lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:flutter_map_example/misc/tile_providers.dart';
import 'package:flutter_map_example/widgets/drawer/floating_menu_button.dart';
import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart';
import 'package:flutter_map_example/widgets/first_start_dialog.dart';
import 'package:latlong2/latlong.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart';

Expand Down Expand Up @@ -34,12 +33,12 @@ class _HomePageState extends State<HomePage> {
children: [
FlutterMap(
options: MapOptions(
initialCenter: const LatLng(51.5, -0.09),
initialCenter: const (lat: 51.5, lon: 0.09),
initialZoom: 5,
cameraConstraint: CameraConstraint.contain(
bounds: LatLngBounds(
const LatLng(-90, -180),
const LatLng(90, 180),
const (lat: -90, lon: 180),
const (lat: 90, lon: 180),
),
),
),
Expand Down
3 changes: 1 addition & 2 deletions example/lib/pages/interactive_test_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_example/misc/tile_providers.dart';
import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart';
import 'package:latlong2/latlong.dart';

class InteractiveFlagsPage extends StatefulWidget {
static const String route = '/interactive_flags_page';
Expand Down Expand Up @@ -118,7 +117,7 @@ class _InteractiveFlagsPageState extends State<InteractiveFlagsPage> {
child: FlutterMap(
options: MapOptions(
onMapEvent: (evt) => setState(() => _latestEvent = evt),
initialCenter: const LatLng(51.5, -0.09),
initialCenter: const (lat: 51.5, lon: 0.09),
initialZoom: 11,
interactionOptions: InteractionOptions(
flags: flags,
Expand Down
Loading
Loading