Search in sources :

Example 1 with SphericalMercatorProjection

use of com.google.maps.android.projection.SphericalMercatorProjection in project android-maps-utils by googlemaps.

the class GridBasedAlgorithm method getClusters.

@Override
public Set<? extends Cluster<T>> getClusters(double zoom) {
    long numCells = (long) Math.ceil(256 * Math.pow(2, zoom) / GRID_SIZE);
    SphericalMercatorProjection proj = new SphericalMercatorProjection(numCells);
    HashSet<Cluster<T>> clusters = new HashSet<Cluster<T>>();
    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.google.maps.android.clustering.Cluster) Point(com.google.maps.android.geometry.Point) SphericalMercatorProjection(com.google.maps.android.projection.SphericalMercatorProjection) HashSet(java.util.HashSet)

Example 2 with SphericalMercatorProjection

use of com.google.maps.android.projection.SphericalMercatorProjection in project android-maps-utils by googlemaps.

the class GridBasedAlgorithm method getClusters.

@Override
public Set<? extends Cluster<T>> getClusters(float zoom) {
    long numCells = (long) Math.ceil(256 * Math.pow(2, zoom) / mGridSize);
    SphericalMercatorProjection proj = new SphericalMercatorProjection(numCells);
    HashSet<Cluster<T>> clusters = new HashSet<Cluster<T>>();
    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(androidx.collection.LongSparseArray) Cluster(com.google.maps.android.clustering.Cluster) Point(com.google.maps.android.geometry.Point) SphericalMercatorProjection(com.google.maps.android.projection.SphericalMercatorProjection) HashSet(java.util.HashSet)

Example 3 with SphericalMercatorProjection

use of com.google.maps.android.projection.SphericalMercatorProjection in project wigle-wifi-wardriving by wiglenet.

the class GridBasedAlgorithm method getClusters.

@Override
public Set<? extends Cluster<T>> getClusters(double zoom) {
    long numCells = (long) Math.ceil(256 * Math.pow(2, zoom) / GRID_SIZE);
    SphericalMercatorProjection proj = new SphericalMercatorProjection(numCells);
    HashSet<Cluster<T>> clusters = new HashSet<Cluster<T>>();
    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.google.maps.android.clustering.Cluster) Point(com.google.maps.android.geometry.Point) SphericalMercatorProjection(com.google.maps.android.projection.SphericalMercatorProjection) HashSet(java.util.HashSet)

Aggregations

Cluster (com.google.maps.android.clustering.Cluster)3 Point (com.google.maps.android.geometry.Point)3 SphericalMercatorProjection (com.google.maps.android.projection.SphericalMercatorProjection)3 HashSet (java.util.HashSet)3 LongSparseArray (android.support.v4.util.LongSparseArray)2 LongSparseArray (androidx.collection.LongSparseArray)1