@@ -197,35 +197,19 @@ class TileLayer extends StatefulWidget {
197
197
/// Only load tiles that are within these bounds
198
198
final LatLngBounds ? tileBounds;
199
199
200
- /// This transformer modifies how/when tile updates and pruning are triggered
201
- /// based on [MapEvent] s. It is a StreamTransformer and therefore it is
202
- /// possible to filter/modify/throttle the [TileUpdateEvent] s. Defaults to
203
- /// [TileUpdateTransformers.ignoreTapEvents] which disables loading/pruning
204
- /// for map taps, secondary taps and long presses. See TileUpdateTransformers
205
- /// for more transformer presets or implement your own.
200
+ /// Restricts and limits [TileUpdateEvent] s (which are emitted 'by'
201
+ /// [MapEvent] s), which cause tiles to update.
206
202
///
207
- /// Note: Changing the [tileUpdateTransformer] after TileLayer is created has
208
- /// no affect.
209
- final TileUpdateTransformer tileUpdateTransformer;
210
-
211
- /// Defines the minimum delay time from last map event before the tile layers
212
- /// are updated. This delay acts as a debounce period to prevent frequent
213
- /// reloading of tile layers in response to rapid, successive events
214
- /// (e.g., zooming or panning).
215
- ///
216
- /// 16ms could be a good starting point for most applications.
217
- /// This at 60fps this will wait one frame after the last event.
203
+ /// For more information, see [TileUpdateTransformer] .
218
204
///
219
- /// By setting this delay, we ensure that map layer updates are performed
220
- /// only after a period of inactivity, enhancing performance and user
221
- /// experience on lower performance devices .
205
+ /// Defaults to [TileUpdateTransformers.ignoreTapEvents] , which disables
206
+ /// updates for map taps, secondary taps and long presses, which alone should
207
+ /// not cause the camera to change position .
222
208
///
223
- /// - If multiple events occur within this delay period, only the last event
224
- /// triggers the tile layer update, reducing unnecessary processing and
225
- /// network requests.
226
- /// - If the [loadingDelay] is `Duration.zero` , the delay is completely
227
- /// disabled and the tile layer will update as soon as possible.
228
- final Duration loadingDelay;
209
+ /// Note that changing this after the layer has already been built will have
210
+ /// no effect. If necessary, force a rebuild of the entire layer by changing
211
+ /// the [key] .
212
+ final TileUpdateTransformer tileUpdateTransformer;
229
213
230
214
/// Create a new [TileLayer] for the [FlutterMap] widget.
231
215
TileLayer ({
@@ -258,7 +242,6 @@ class TileLayer extends StatefulWidget {
258
242
this .evictErrorTileStrategy = EvictErrorTileStrategy .none,
259
243
this .reset,
260
244
this .tileBounds,
261
- this .loadingDelay = Duration .zero,
262
245
TileUpdateTransformer ? tileUpdateTransformer,
263
246
String userAgentPackageName = 'unknown' ,
264
247
}) : assert (
@@ -353,9 +336,6 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
353
336
TileRangeCalculator (tileSize: widget.tileSize);
354
337
late TileScaleCalculator _tileScaleCalculator;
355
338
356
- /// Delay Timer for [TileLayer.loadingDelay]
357
- Timer ? _delayTimer;
358
-
359
339
// We have to hold on to the mapController hashCode to determine whether we
360
340
// need to reinitialize the listeners. didChangeDependencies is called on
361
341
// every map movement and if we unsubscribe and resubscribe every time we
@@ -370,26 +350,8 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
370
350
_loadAndPruneInVisibleBounds (MapCamera .of (context));
371
351
});
372
352
373
- /// This method is used to delay the execution of a function by the specified
374
- /// [TileLayer.loadingDelay] . This is useful to prevent frequent reloading
375
- /// of tile layers in response to rapid, successive events (e.g., zooming
376
- /// or panning).
377
- void _loadingDelay (VoidCallback action) {
378
- //execute immediately if delay is zero.
379
- if (widget.loadingDelay == Duration .zero) {
380
- action ();
381
- return ;
382
- }
383
-
384
- // Cancel the previous timer if it is still active.
385
- _delayTimer? .cancel ();
386
-
387
- // Reset the timer to wait for the debounce duration
388
- _delayTimer = Timer (widget.loadingDelay, action);
389
- }
390
-
391
353
// This is called on every map movement so we should avoid expensive logic
392
- // where possible.
354
+ // where possible, or filter as necessary
393
355
@override
394
356
void didChangeDependencies () {
395
357
super .didChangeDependencies ();
@@ -404,7 +366,7 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
404
366
_tileUpdateSubscription = mapController.mapEventStream
405
367
.map ((mapEvent) => TileUpdateEvent (mapEvent: mapEvent))
406
368
.transform (widget.tileUpdateTransformer)
407
- .listen ((event) => _loadingDelay (() => _onTileUpdateEvent (event)) );
369
+ .listen (_onTileUpdateEvent);
408
370
}
409
371
410
372
var reloadTiles = false ;
@@ -499,7 +461,6 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
499
461
_resetSub? .cancel ();
500
462
_pruneLater? .cancel ();
501
463
widget.tileProvider.dispose ();
502
- _delayTimer? .cancel ();
503
464
super .dispose ();
504
465
}
505
466
0 commit comments