diff --git a/lib/src/misc/simplify.dart b/lib/simplify.dart similarity index 85% rename from lib/src/misc/simplify.dart rename to lib/simplify.dart index 564d47453..99b0c3423 100644 --- a/lib/src/misc/simplify.dart +++ b/lib/simplify.dart @@ -1,6 +1,7 @@ // implementation based on // https://github.com/mourner/simplify-js/blob/master/simplify.js +library simplify; import 'package:latlong2/latlong.dart'; @@ -25,8 +26,7 @@ double _getSqSegDist( double dy = p2.latitude - y; if (dx != 0 || dy != 0) { final double t = - ((p.longitude - x) * dx + (p.latitude - y) * dy) / - (dx * dx + dy * dy); + ((p.longitude - x) * dx + (p.latitude - y) * dy) / (dx * dx + dy * dy); if (t > 1) { x = p2.longitude; y = p2.latitude; @@ -42,7 +42,7 @@ double _getSqSegDist( return dx * dx + dy * dy; } -List _simplifyRadialDist( +List simplifyRadialDist( List points, double sqTolerance, ) { @@ -91,7 +91,7 @@ void _simplifyDPStep( } // simplification using Ramer-Douglas-Peucker algorithm -List _simplifyDouglasPeucker( +List simplifyDouglasPeucker( List points, double sqTolerance, ) { @@ -102,7 +102,8 @@ List _simplifyDouglasPeucker( return simplified; } -// both algorithms combined for awesome performance +/// high quality simplification uses the Ramer-Douglas-Peucker algorithm +/// otherwise it just merges close points List simplify( List points, double tolerance, { @@ -114,7 +115,7 @@ List simplify( List nextPoints = points; final double sqTolerance = tolerance * tolerance; nextPoints = - highestQuality ? points : _simplifyRadialDist(nextPoints, sqTolerance); - nextPoints = _simplifyDouglasPeucker(nextPoints, sqTolerance); + highestQuality ? points : simplifyRadialDist(nextPoints, sqTolerance); + nextPoints = simplifyDouglasPeucker(nextPoints, sqTolerance); return nextPoints; } diff --git a/lib/src/layer/polygon_layer/polygon_layer.dart b/lib/src/layer/polygon_layer/polygon_layer.dart index 9dd2284c4..aa7c4c7ac 100644 --- a/lib/src/layer/polygon_layer/polygon_layer.dart +++ b/lib/src/layer/polygon_layer/polygon_layer.dart @@ -7,7 +7,7 @@ import 'package:flutter_map/src/layer/general/mobile_layer_transformer.dart'; import 'package:flutter_map/src/layer/polygon_layer/label.dart'; import 'package:flutter_map/src/map/camera/camera.dart'; import 'package:flutter_map/src/misc/point_extensions.dart'; -import 'package:flutter_map/src/misc/simplify.dart'; +import 'package:flutter_map/simplify.dart'; import 'package:latlong2/latlong.dart' hide Path; // conflict with Path from UI enum PolygonLabelPlacement { @@ -164,8 +164,13 @@ class PolygonPainter extends CustomPainter { final double? simplificationTolerance; final bool simplificationHighQuality; - PolygonPainter(this.polygons, this.camera, this.polygonLabels, - this.simplificationTolerance, this.simplificationHighQuality, this.drawLabelsLast) + PolygonPainter( + this.polygons, + this.camera, + this.polygonLabels, + this.simplificationTolerance, + this.simplificationHighQuality, + this.drawLabelsLast) : bounds = camera.visibleBounds; int get hash { diff --git a/lib/src/layer/polyline_layer.dart b/lib/src/layer/polyline_layer.dart index fbe5f508a..906814346 100644 --- a/lib/src/layer/polyline_layer.dart +++ b/lib/src/layer/polyline_layer.dart @@ -4,7 +4,7 @@ import 'dart:ui' as ui; import 'package:flutter/widgets.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:flutter_map/src/misc/simplify.dart'; +import 'package:flutter_map/simplify.dart'; import 'package:latlong2/latlong.dart'; class Polyline { @@ -51,9 +51,6 @@ class Polyline { @immutable class PolylineLayer extends StatelessWidget { final List polylines; - @Deprecated( - 'has no effect anymore, polyline culling is enabled by default and controlled by margin') - final bool polylineCulling; /// extent outside of the viewport before culling polylines, set to null to /// disable polyline culling @@ -68,7 +65,6 @@ class PolylineLayer extends StatelessWidget { const PolylineLayer({ super.key, required this.polylines, - this.polylineCulling = true, this.polylineCullingMargin = 0, this.simplificationTolerance = 1, this.simplificationHighQuality = false,