Skip to content

Commit 25b33e4

Browse files
committed
v3.1.0 - Bump dependency versions + Max distance clustering
1 parent cc8758a commit 25b33e4

8 files changed

Lines changed: 31 additions & 39 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 3.1.0
2+
3+
- Bump dependency versions
4+
- Max distance clustering
5+
16
## 3.0.0+1
27

38
- Remove useless log

example/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ description: A new Flutter project.
1414
version: 1.0.0+1
1515

1616
environment:
17-
sdk: ">=2.12.0 <3.0.0"
17+
sdk: ">=3.0.0 <4.0.0"
1818

1919
dependencies:
2020
flutter:
2121
sdk: flutter
2222

23-
google_maps_flutter: ^2.0.6
24-
google_maps_flutter_web: ^0.3.0+3
23+
google_maps_flutter: ^2.5.2
24+
google_maps_flutter_web: ^0.5.4+3
2525
google_maps_cluster_manager:
2626
path: ../
2727

lib/src/cluster_item.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:google_maps_cluster_manager/google_maps_cluster_manager.dart';
22
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
33

4-
abstract class ClusterItem {
4+
mixin ClusterItem {
55
LatLng get location;
66

77
String? _geohash;

lib/src/cluster_manager.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'dart:math';
2-
import 'dart:typed_data';
32
import 'dart:ui';
43

54
import 'package:flutter/foundation.dart';
@@ -128,18 +127,18 @@ class ClusterManager<T extends ClusterItem> {
128127
if (stopClusteringZoom != null && _zoom >= stopClusteringZoom!)
129128
return visibleItems.map((i) => Cluster<T>.fromItems([i])).toList();
130129

130+
List<Cluster<T>> markers;
131+
131132
if (clusterAlgorithm == ClusterAlgorithm.GEOHASH ||
132133
visibleItems.length >= maxItemsForMaxDistAlgo) {
133134
int level = _findLevel(levels);
134-
List<Cluster<T>> markers = _computeClusters(
135-
visibleItems, List.empty(growable: true),
135+
markers = _computeClusters(visibleItems, List.empty(growable: true),
136136
level: level);
137-
return markers;
138137
} else {
139-
List<Cluster<T>> markers =
140-
_computeClustersWithMaxDist(visibleItems, _zoom);
141-
return markers;
138+
markers = _computeClustersWithMaxDist(visibleItems, _zoom);
142139
}
140+
141+
return markers;
143142
}
144143

145144
LatLngBounds _inflateBounds(LatLngBounds bounds) {

lib/src/common.dart

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
11
import 'dart:math';
2-
import 'dart:ui';
32

43
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
54

6-
import 'cluster.dart';
7-
8-
const int _mio = 1000000;
9-
const int _thd = 1000;
10-
const double _PI = 3.141592653589793238;
11-
12-
class _Tuple {
13-
final LatLng pos1;
14-
final LatLng pos2;
15-
16-
_Tuple(this.pos1, this.pos2);
17-
18-
bool operator ==(o) => o is _Tuple && pos1 == o.pos1 && pos2 == o.pos2;
19-
int get hashCode => pos1.hashCode + pos2.hashCode;
20-
}
21-
225
class DistUtils {
236
// Zoom-Level:
247
// Level # Tiles Tile width
@@ -47,18 +30,18 @@ class DistUtils {
4730
// 18 68 719 476 736 0.001 0.596 1:2 thousand some buildings, trees
4831
// 19 274 877 906 944 0.0005 0.298 1:1 thousand local highway and crossing details
4932
// 20 1 099 511 627 776 0.00025 0.149 1:5 hundred A mid-sized building
50-
final Map<_Tuple, double> distCache = {};
33+
final Map<(LatLng, LatLng), double> distCache = {};
5134

5235
double getLatLonDist(LatLng point1, LatLng point2, int zoomLevel) {
53-
if (distCache[_Tuple(point1, point2)] != null) {
54-
return distCache[_Tuple(point1, point2)]!;
36+
if (distCache[(point1, point2)] != null) {
37+
return distCache[(point1, point2)]!;
5538
}
5639
double meterPerPixel = _getScalingFactor(zoomLevel);
5740
double dist = getDistanceFromLatLonInKm(point1.latitude, point1.longitude,
5841
point2.latitude, point2.longitude) /
59-
(meterPerPixel / _thd);
42+
(meterPerPixel / 1000);
6043
// print("dist is $x");
61-
distCache[_Tuple(point1, point2)] = dist;
44+
distCache[(point1, point2)] = dist;
6245
return dist;
6346
}
6447

@@ -78,7 +61,7 @@ class DistUtils {
7861
}
7962

8063
double _degreeToRadian(double degree) {
81-
return degree * _PI / 180;
64+
return degree * pi / 180;
8265
}
8366

8467
double _getScalingFactor(int zoomLevel) {

lib/src/geohash.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Geohash {
8080
];
8181

8282
/// Encode a latitude and longitude pair into a geohash string.
83-
static String encode(final LatLng latLng, {final int codeLength: 12}) {
83+
static String encode(final LatLng latLng, {final int codeLength = 12}) {
8484
if (codeLength > 20 || (identical(1.0, 1) && codeLength > 12)) {
8585
//Javascript can only handle 32 bit ints reliably.
8686
throw ArgumentError(

lib/src/max_dist_clustering.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class MaxDistClustering<T extends ClusterItem> {
3838
changed = false;
3939
for (Cluster<T> c in _cluster) {
4040
_MinDistCluster<T>? minDistCluster = getClosestCluster(c, zoomLevel);
41-
// print("mindistcluster ${minDistCluster?.dist}");
4241
if (minDistCluster == null || minDistCluster.dist > epsilon) continue;
4342
_cluster.add(Cluster.fromClusters(minDistCluster.cluster, c));
4443
_cluster.remove(c);

pubspec.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
name: google_maps_cluster_manager
22
description: Simple Flutter clustering library for Google Maps based on Geohash.
3-
version: 3.0.0+1
3+
version: 3.1.0
44
homepage: https://github.com/bpillon/google_maps_cluster_manager
55

66
environment:
7-
sdk: ">=2.12.0 <3.0.0"
7+
sdk: ">=3.0.0 <4.0.0"
88

99
dependencies:
1010
flutter:
1111
sdk: flutter
1212

13-
google_maps_flutter_platform_interface: ^2.1.0
13+
google_maps_flutter_platform_interface: ^2.4.3
1414

1515
dev_dependencies:
1616
flutter_test:
1717
sdk: flutter
18+
19+
topics:
20+
- google-maps
21+
- google-maps-flutter
22+
- map
23+
- cluster

0 commit comments

Comments
 (0)