Skip to content

Commit

Permalink
Pick fleaflet#572.
Browse files Browse the repository at this point in the history
  • Loading branch information
pento committed Apr 5, 2020
1 parent 09819a3 commit 5906b07
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 5906b07

Please sign in to comment.