diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..036fffd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.minimap.maxColumn": 80 +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f430ec3..7d4d75e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.0.0 + +* BREAKING CHANGE: This version uses latlong2 for latitude and longitude calculation. The goal is to make it compatible with flutter_map + ## 2.0.1 * Update Dart DSK version up to 2.17.0 diff --git a/README.md b/README.md index 8c37f5a..ea01b0c 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ In your dart/flutter project add the dependency: ``` dependencies: ... - maps_toolkit: ^2.0.1 + maps_toolkit: ^3.0.0 ``` A simple usage example: diff --git a/example/maps_toolkit_example.dart b/example/maps_toolkit_example.dart index 59b7420..afcfd1a 100644 --- a/example/maps_toolkit_example.dart +++ b/example/maps_toolkit_example.dart @@ -1,3 +1,4 @@ +import 'package:latlong2/latlong.dart'; import 'package:maps_toolkit/maps_toolkit.dart'; void main() { diff --git a/lib/maps_toolkit.dart b/lib/maps_toolkit.dart index 78df2ae..ca7b9a2 100644 --- a/lib/maps_toolkit.dart +++ b/lib/maps_toolkit.dart @@ -1,6 +1,6 @@ /// Maps toolkit (port from android-maps-utils library) library maps_toolkit; -export 'src/latlng.dart'; +// export 'src/latlng_.dart'; export 'src/polygon_util.dart'; export 'src/spherical_util.dart'; diff --git a/lib/src/kalman_filter.dart b/lib/src/kalman_filter.dart index 703e87e..8da5bed 100644 --- a/lib/src/kalman_filter.dart +++ b/lib/src/kalman_filter.dart @@ -1,6 +1,8 @@ import 'dart:math'; -import 'latlng.dart'; +// import 'latlng.dart'; +import 'package:latlong2/latlong.dart'; + import 'location.dart'; import 'spherical_util.dart'; diff --git a/lib/src/latlng.dart b/lib/src/latlng.dart deleted file mode 100644 index b1eae7d..0000000 --- a/lib/src/latlng.dart +++ /dev/null @@ -1,32 +0,0 @@ -class LatLng { - final double latitude; - final double longitude; - - LatLng(this.latitude, this.longitude); - - factory LatLng.fromMap(Map dataMap) => - LatLng(dataMap['latitude']!, dataMap['longitude']!); - - @override - // ignore: type_annotate_public_apis - bool operator ==(other) { - if (other is LatLng) { - return other.latitude == latitude && other.longitude == longitude; - } - - return false; - } - - @override - int get hashCode => - _combine(_combine(0, latitude.hashCode), longitude.hashCode); - - int _combine(int hash, int value) { - hash = 0x1fffffff & (hash + value); - hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10)); - return hash ^ (hash >> 6); - } - - @override - String toString() => 'Lat: $latitude, Lng: $longitude'; -} diff --git a/lib/src/latlng_X.dart b/lib/src/latlng_X.dart new file mode 100644 index 0000000..244e9b1 --- /dev/null +++ b/lib/src/latlng_X.dart @@ -0,0 +1,32 @@ +// class LatLng_X { +// final double latitude; +// final double longitude; + +// LatLng_(this.latitude, this.longitude); + +// factory LatLng_.fromMap(Map dataMap) => +// LatLng_(dataMap['latitude']!, dataMap['longitude']!); + +// @override +// // ignore: type_annotate_public_apis +// bool operator ==(other) { +// if (other is LatLng_) { +// return other.latitude == latitude && other.longitude == longitude; +// } + +// return false; +// } + +// @override +// int get hashCode => +// _combine(_combine(0, latitude.hashCode), longitude.hashCode); + +// int _combine(int hash, int value) { +// hash = 0x1fffffff & (hash + value); +// hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10)); +// return hash ^ (hash >> 6); +// } + +// @override +// String toString() => 'Lat: $latitude, Lng: $longitude'; +// } diff --git a/lib/src/location.dart b/lib/src/location.dart index 127f9c9..bd289a6 100644 --- a/lib/src/location.dart +++ b/lib/src/location.dart @@ -1,4 +1,6 @@ -import 'latlng.dart'; +import 'package:latlong2/latlong.dart'; + +// import 'latlng_.dart'; class Location { final LatLng latlng; diff --git a/lib/src/polygon_util.dart b/lib/src/polygon_util.dart index d131aaa..631445b 100644 --- a/lib/src/polygon_util.dart +++ b/lib/src/polygon_util.dart @@ -1,9 +1,10 @@ import 'dart:collection'; import 'dart:math'; +import 'package:latlong2/latlong.dart'; import 'package:maps_toolkit/src/spherical_util.dart'; -import 'latlng.dart'; +// import 'latlng_.dart'; import 'math_util.dart'; /// Port of PolyUtil from android-maps-utils (https://github.com/googlemaps/android-maps-utils) diff --git a/lib/src/spherical_util.dart b/lib/src/spherical_util.dart index a083a89..db4bd61 100644 --- a/lib/src/spherical_util.dart +++ b/lib/src/spherical_util.dart @@ -1,6 +1,8 @@ import 'dart:math'; -import 'latlng.dart'; +import 'package:latlong2/latlong.dart'; + +// import 'latlng_.dart'; import 'math_util.dart'; /// Port of SphericalUtil from android-maps-utils (https://github.com/googlemaps/android-maps-utils) diff --git a/pubspec.yaml b/pubspec.yaml index 23e8132..8b80dff 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,12 +1,13 @@ name: maps_toolkit description: Maps toolkit - geo-measurements utils - area of polygon, distance between point, heading and offset between points (port of SphericalUtil, PolyUtil from `android-maps-utils`). -version: 2.0.1 +version: 3.0.0 homepage: https://github.com/kb0/maps_toolkit/ environment: - sdk: ">=2.17.0 <3.0.0" + sdk: '>=2.17.0 <3.0.0' -dependencies: +dependencies: + latlong2: ^0.8.1 dev_dependencies: lints: ^2.0.0 diff --git a/test/maps_toolkit_test.dart b/test/maps_toolkit_test.dart index 1ca00a1..c1ade54 100644 --- a/test/maps_toolkit_test.dart +++ b/test/maps_toolkit_test.dart @@ -1,5 +1,6 @@ import 'dart:math'; +import 'package:latlong2/latlong.dart'; import 'package:maps_toolkit/maps_toolkit.dart'; import 'package:maps_toolkit/src/math_util.dart'; import 'package:test/test.dart'; diff --git a/test/polygon_util_test.dart b/test/polygon_util_test.dart index 7f5734f..9381757 100644 --- a/test/polygon_util_test.dart +++ b/test/polygon_util_test.dart @@ -1,3 +1,4 @@ +import 'package:latlong2/latlong.dart'; import 'package:maps_toolkit/maps_toolkit.dart'; import 'package:test/test.dart'; @@ -111,8 +112,13 @@ void main() { PolygonUtil.containsLocation(LatLng(1, 1), [], false), equals(false)); }); + // test('containsLocation without point', () { + // expect(PolygonUtil.containsLocation(LatLng(99, 99), polygon, true), + // equals(false)); + // }); + test('containsLocation without point', () { - expect(PolygonUtil.containsLocation(LatLng(99, 99), polygon, true), + expect(PolygonUtil.containsLocation(LatLng(90, 90), polygon, true), equals(false)); }); @@ -240,7 +246,8 @@ void main() { makeList([-45, -180, -45, -small]), makeList([ -45, - 180 + small, + //180 + small, + 180, // MAX: 180 degree -45, 180 - small, -45 - small,