Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ jobs:
- name: Install pana
run: dart pub global activate pana
- name: Check package score
run: pana --exit-code-threshold 0 .
# we cannot reach the top score: we use logger that doesn't support wasm, so -10
run: pana --exit-code-threshold 10 .

analyse-code:
name: "Analyse Code"
Expand Down
32 changes: 23 additions & 9 deletions lib/src/geo/crs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ abstract class Crs {

/// Similar to [latLngToXY] but converts the XY coordinates to an [Offset].
Offset latLngToOffset(LatLng latlng, double zoom) {
final (x, y) = latLngToXY(latlng, scale(zoom));
final (x, y) = latLngToXY(checkLatLng(latlng), scale(zoom));
return Offset(x, y);
}

Expand All @@ -72,6 +72,17 @@ abstract class Crs {
/// Whether this CRS supports repeating worlds: repeated (feature) layers and
/// unbounded horizontal scrolling along the longitude axis
bool get replicatesWorldLongitude => false;

/// Throws if [latlng] is not finite (e.g. either NaN or infinite), which may
/// cause memory leak.
/// cf. https://github.com/fleaflet/flutter_map/issues/2178
@protected
LatLng checkLatLng(LatLng latlng) {
if (!(latlng.latitude.isFinite && latlng.longitude.isFinite)) {
throw Exception('LatLng is not finite: $latlng');
}
return latlng;
}
}

/// Internal base class for CRS with a single zoom-level independent transformation.
Expand Down Expand Up @@ -104,7 +115,7 @@ abstract class CrsWithStaticTransformation extends Crs {

@override
(double, double) latLngToXY(LatLng latlng, double scale) {
final (x, y) = projection.projectXY(latlng);
final (x, y) = projection.projectXY(checkLatLng(latlng));
return _transformation.transform(x, y, scale);
}

Expand Down Expand Up @@ -164,15 +175,18 @@ class Epsg3857 extends CrsWithStaticTransformation {
);

@override
(double, double) latLngToXY(LatLng latlng, double scale) =>
_transformation.transform(
SphericalMercator.projectLng(latlng.longitude),
SphericalMercator.projectLat(latlng.latitude),
scale,
);
(double, double) latLngToXY(LatLng latlng, double scale) {
checkLatLng(latlng);
return _transformation.transform(
SphericalMercator.projectLng(latlng.longitude),
SphericalMercator.projectLat(latlng.latitude),
scale,
);
}

@override
Offset latLngToOffset(LatLng latlng, double zoom) {
checkLatLng(latlng);
final (x, y) = _transformation.transform(
SphericalMercator.projectLng(latlng.longitude),
SphericalMercator.projectLat(latlng.latitude),
Expand Down Expand Up @@ -276,7 +290,7 @@ class Proj4Crs extends Crs {
/// map point.
@override
(double, double) latLngToXY(LatLng latlng, double scale) {
final (x, y) = projection.projectXY(latlng);
final (x, y) = projection.projectXY(checkLatLng(latlng));
final transformation = _getTransformationByZoom(zoom(scale));
return transformation.transform(x, y, scale);
}
Expand Down
9 changes: 7 additions & 2 deletions lib/src/gestures/map_interactive_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class MapInteractiveViewerState extends State<MapInteractiveViewer>

late var _keyboardPanAnimationPrevZoom = _camera.zoom; // to detect changes
late double _keyboardPanAnimationMaxVelocity;

double _keyboardPanAnimationMaxVelocityCalculator(double zoom) =>
_interactionOptions.keyboardOptions.maxPanVelocity?.call(zoom) ??
5 * math.log(0.15 * zoom + 1) + 1;
Expand All @@ -124,7 +125,9 @@ class MapInteractiveViewerState extends State<MapInteractiveViewer>

// Shortcuts
MapCamera get _camera => widget.controller.camera;

MapOptions get _options => widget.controller.options;

InteractionOptions get _interactionOptions => _options.interactionOptions;

@override
Expand Down Expand Up @@ -1243,7 +1246,8 @@ class MapInteractiveViewerState extends State<MapInteractiveViewer>
yield initManagerListeners(
manager: _keyboardZoomAnimationManager,
sum: _NumInfiniteSumAnimation.new,
onTick: (value) {
onTick: (valueParameter) {
num value = valueParameter;
if (_isZoomLeaping.value) {
value *= keyboardOptions.zoomLeapVelocityMultiplier;
}
Expand All @@ -1260,7 +1264,8 @@ class MapInteractiveViewerState extends State<MapInteractiveViewer>
yield initManagerListeners(
manager: _keyboardRotateAnimationManager,
sum: _NumInfiniteSumAnimation.new,
onTick: (value) {
onTick: (valueParameter) {
num value = valueParameter;
if (_isRotateLeaping.value) {
value *= keyboardOptions.rotateLeapVelocityMultiplier;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ Future<void> tileAndSizeMonitorWriterWorker(
void writeTile({
required final String path,
required final CachedMapTileMetadata metadata,
Uint8List? tileBytes,
Uint8List? tileBytesParameter,
}) {
Uint8List? tileBytes = tileBytesParameter;
final tileFile = File(path);
final initialTileFileExists = tileFile.existsSync();
final initialTileFileLength =
Expand Down Expand Up @@ -315,7 +316,7 @@ Future<void> tileAndSizeMonitorWriterWorker(
:final CachedMapTileMetadata metadata,
:final Uint8List? tileBytes,
)) {
writeTile(path: path, metadata: metadata, tileBytes: tileBytes);
writeTile(path: path, metadata: metadata, tileBytesParameter: tileBytes);
} else if (val == false) {
disableSizeMonitor();
} else if (val == null) {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/map/camera/camera_fit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class FitInsideBounds extends CameraFit {
).size;

final scale = _rectInRotRectScale(
angleRad: camera.rotationRad,
angleRadParameter: camera.rotationRad,
smallRectHalfWidth: cameraSize.width / 2.0,
smallRectHalfHeight: cameraSize.height / 2.0,
bigRectHalfWidth: projectedBoundsSize.width / 2.0,
Expand Down Expand Up @@ -305,13 +305,13 @@ class FitInsideBounds extends CameraFit {
///
/// This algorithm has been adapted from https://stackoverflow.com/a/75907251
static double _rectInRotRectScale({
required double angleRad,
required double angleRadParameter,
required double smallRectHalfWidth,
required double smallRectHalfHeight,
required double bigRectHalfWidth,
required double bigRectHalfHeight,
}) {
angleRad = _normalize(angleRad, 0, 2.0 * math.pi);
final angleRad = _normalize(angleRadParameter, 0, 2.0 * math.pi);
var kmin = double.infinity;
final quadrant = (2.0 * angleRad / math.pi).floor();
if (quadrant.isOdd) {
Expand Down