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

Improve tile management #572

Merged
merged 20 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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