use of com.mapbox.mapboxsdk.plugins.cluster.geometry.Point in project mapbox-plugins-android by mapbox.
the class DefaultClusterRenderer method findClosestCluster.
private Point findClosestCluster(List<Point> markers, Point point) {
if (markers == null || markers.isEmpty()) {
return null;
}
int maxDistance = mClusterManagerPlugin.getAlgorithm().getMaxDistanceBetweenClusteredItems();
double minDistSquared = maxDistance * maxDistance;
Point closest = null;
for (Point candidate : markers) {
double dist = distanceSquared(candidate, point);
if (dist < minDistSquared) {
closest = candidate;
minDistSquared = dist;
}
}
return closest;
}
use of com.mapbox.mapboxsdk.plugins.cluster.geometry.Point in project mapbox-plugins-android by mapbox.
the class GridBasedAlgorithm method getClusters.
@Override
public Set<? extends Cluster<T>> getClusters(double zoom) {
long numCells = (long) Math.ceil(256 * Math.pow(2, zoom) / mGridSize);
SphericalMercatorProjection proj = new SphericalMercatorProjection(numCells);
HashSet<Cluster<T>> clusters = new HashSet<>();
LongSparseArray<StaticCluster<T>> sparseArray = new LongSparseArray<StaticCluster<T>>();
synchronized (mItems) {
for (T item : mItems) {
Point p = proj.toPoint(item.getPosition());
long coord = getCoord(numCells, p.x, p.y);
StaticCluster<T> cluster = sparseArray.get(coord);
if (cluster == null) {
cluster = new StaticCluster<T>(proj.toLatLng(new Point(Math.floor(p.x) + .5, Math.floor(p.y) + .5)));
sparseArray.put(coord, cluster);
clusters.add(cluster);
}
cluster.add(item);
}
}
return clusters;
}
Aggregations