-
-
Notifications
You must be signed in to change notification settings - Fork 871
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
[BUG] Repositioning the map through MapController
in onMapReady
prevents initial tiles loading
#1507
Comments
Hey @MatyasK, |
I created a sample app, the app bevahes the same way, so the map only loads after you move the camera around. (I created a test api key so you can use that). import 'package:flutter/material.dart';
import 'package:flutter_map/plugin_api.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 MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
),
home: MapView(),
);
}
}
class MapView extends StatelessWidget {
MapView({Key? key}) : super(key: key);
final MapController _mapController = MapController();
final mapPoints = <LatLng>[
LatLng(51.5, -0.09),
LatLng(53.3498, -6.2603),
LatLng(48.8566, 2.3522),
LatLng(52.5200, 13.4050),
LatLng(51.5074, -0.1278),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Map View')),
body: FlutterMap(
mapController: _mapController,
options: MapOptions(
maxZoom: 13,
onMapReady: () {
final markerBounds = LatLngBounds.fromPoints(mapPoints);
_mapController.fitBounds(
markerBounds,
options: const FitBoundsOptions(padding: EdgeInsets.all(70)),
);
},
),
children: [
TileLayer(
urlTemplate: 'https://api.tomtom.com/map/1/tile/basic/main/'
'{z}/{x}/{y}.png?key={apiKey}',
additionalOptions: const {
'apiKey': 'FnfFpG2MWmBYXNsvAFOAyJCJB7ftnoGd',
},
),
PolylineLayer(
polylines: [
Polyline(
strokeWidth: 3,
points: mapPoints,
color: Colors.green,
),
],
),
],
));
}
} |
Reproducible. The issue seems to be with running the |
@JaffaKetchup That solves the issue, thanks for your quick reply! |
MapController
in onMapReady
prevents tiles loading
MapController
in onMapReady
prevents tiles loadingMapController
in onMapReady
prevents initial tiles loading
This is likely related to #1475. |
I agree with you @JaffaKetchup. Maybe we should mention something about this in the documentation of either |
hmm I think it depends if this is part of a more subtle bug. I think its fine to leave this as is for this current issue (i.e there's a more correct fix). But I'm also wondering if its related to something like some bits in rorystephenson@a13353f (it may also be completely unrelated, just maybe the first place I'd look by the description of the problem). eg
For example, if there's a condition where previously we didn't have a size in the layout builder, and previously didn't send a map ready event until the size was resolved but now we do. We may find there are some other sneaky bugs that come in where people are doing things on a map ready when it isn't correctly sized or tiles loaded. I don't know this is the case at all, just kinda worth being aware that it could be part of a larger issue that pops up a few times. The whole layoutbuilder sizing thing has always been a bit of a pita :). |
Absolutely, whatever anyone does, it never seems to properly fix it!
I'll mention it in https://docs.fleaflet.dev/usage/controller#usage-in-initstate - on a related note, I've recently changed the guidance for
Maybe this should be converted to a general tracking issue then, for issues with initial sizing? |
Closing for now. More specific issues can be opened as necessary. |
What is the bug?
After migrating to v4 the tiles doesn't load. if you move the map around manually the tiles start to load.
How can we reproduce it?
Do you have a potential solution?
No response
Platforms
Android
Severity
Obtrusive: Prevents normal functioning but causes no errors in the console
The text was updated successfully, but these errors were encountered: