Search in sources :

Example 1 with Point

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;
}
Also used : Point(com.mapbox.mapboxsdk.plugins.cluster.geometry.Point) Point(com.mapbox.mapboxsdk.plugins.cluster.geometry.Point) SuppressLint(android.annotation.SuppressLint)

Example 2 with Point

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;
}
Also used : LongSparseArray(android.support.v4.util.LongSparseArray) Cluster(com.mapbox.mapboxsdk.plugins.cluster.clustering.Cluster) Point(com.mapbox.mapboxsdk.plugins.cluster.geometry.Point) SphericalMercatorProjection(com.mapbox.mapboxsdk.plugins.cluster.projection.SphericalMercatorProjection) HashSet(java.util.HashSet)

Aggregations

Point (com.mapbox.mapboxsdk.plugins.cluster.geometry.Point)2 SuppressLint (android.annotation.SuppressLint)1 LongSparseArray (android.support.v4.util.LongSparseArray)1 Cluster (com.mapbox.mapboxsdk.plugins.cluster.clustering.Cluster)1 SphericalMercatorProjection (com.mapbox.mapboxsdk.plugins.cluster.projection.SphericalMercatorProjection)1 HashSet (java.util.HashSet)1