Skip to content

Commit

Permalink
Improve tile management (#572)
Browse files Browse the repository at this point in the history
* imporve tile managment initial commit based on Leaflet

* abort improve

* let user control throttleUpdate behaviour via updateInterval

* let user controll throttleUpdate behaviour 2

* support fadeIn

* create throttle stream which supports trailing calls

* create trailing call Throttle (add missing util.dart)

* update Throttle stream which is independent of StreamController

* order tiles by zIndex

* start fade when Tile image loaded

* create Tile sort without any closure

* beauty code

* support minZoom minNativeZoom / maxNativeZoom

* remove Tiles when tileZoom is out of zoom limits and restore them when tileZoom is within limits

* fix -- Zooming out very far causes null pointers #59

* support zoomReverse / zoomOffset

* support error tile image / improve tile fade in (remove hacky solution)

* use direct milliseconds instead of Duration to avoid microseconds

* fix -- Exception caught by image resource service - not handled. #444

* remove diagnostic prints
  • Loading branch information
maRci002 committed Apr 7, 2020
1 parent 8db1d54 commit d4aefae
Show file tree
Hide file tree
Showing 5 changed files with 700 additions and 172 deletions.
35 changes: 35 additions & 0 deletions lib/src/core/util.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:tuple/tuple.dart';

var _templateRe = RegExp(r'\{ *([\w_-]+) *\}');
Expand All @@ -22,3 +24,36 @@ double wrapNum(double x, Tuple2<double, double> range, [bool includeMax]) {
var d = max - min;
return x == max && includeMax != null ? x : ((x - min) % d + d) % d + min;
}

StreamTransformer<T, T> throttleStreamTransformerWithTrailingCall<T>(
Duration duration) {
Timer timer;
T recentData;
var trailingCall = false;

void Function(T data, EventSink<T> sink) throttleHandler;
throttleHandler = (T data, EventSink<T> sink) {
recentData = data;

if (timer == null) {
sink.add(recentData);
timer = Timer(duration, () {
timer = null;

if (trailingCall) {
trailingCall = false;
throttleHandler(recentData, sink);
}
});
} else {
trailingCall = true;
}
};

return StreamTransformer<T, T>.fromHandlers(
handleData: throttleHandler,
handleDone: (EventSink<T> sink) {
timer?.cancel();
sink.close();
});
}
7 changes: 5 additions & 2 deletions lib/src/gestures/gestures.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,11 @@ abstract class MapGestureMixin extends State<FlutterMap>
return Offset(point.x.toDouble(), point.y.toDouble());
}

double _getZoomForScale(double startZoom, double scale) =>
startZoom + math.log(scale) / math.ln2;
double _getZoomForScale(double startZoom, double scale) {
var resultZoom = startZoom + math.log(scale) / math.ln2;

return map.fitZoomToBounds(resultZoom);
}

@override
void dispose() {
Expand Down
Loading

0 comments on commit d4aefae

Please sign in to comment.