Search in sources :

Example 1 with Point

use of com.google.maps.android.geometry.Point in project cw-omnibus by commonsguy.

the class PointQuadTree method add.

/**
     * Insert an item.
     */
public void add(T item) {
    Point point = item.getPoint();
    insert(point.x, point.y, item);
}
Also used : Point(com.google.maps.android.geometry.Point)

Example 2 with Point

use of com.google.maps.android.geometry.Point 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 3 with Point

use of com.google.maps.android.geometry.Point in project wigle-wifi-wardriving by wiglenet.

the class PointQuadTreeTest method testVeryDeepTree.

/**
 * Tests 30,000 items at the same point.
 * Timing results are averaged.
 */
public void testVeryDeepTree() {
    for (int i = 0; i < 30000; i++) {
        mTree.add(new Item(0, 0));
    }
    assertEquals(30000, searchAll().size());
    assertEquals(30000, mTree.search(new Bounds(0, .1, 0, .1)).size());
    assertEquals(0, mTree.search(new Bounds(.1, 1, .1, 1)).size());
    mTree.clear();
}
Also used : Bounds(com.google.maps.android.geometry.Bounds) Point(com.google.maps.android.geometry.Point)

Example 4 with Point

use of com.google.maps.android.geometry.Point in project wigle-wifi-wardriving by wiglenet.

the class DefaultClusterRenderer method findClosestCluster.

private static Point findClosestCluster(List<Point> markers, Point point) {
    if (markers == null || markers.isEmpty())
        return null;
    // TODO: make this configurable.
    double minDistSquared = MAX_DISTANCE_AT_ZOOM * MAX_DISTANCE_AT_ZOOM;
    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.google.maps.android.geometry.Point)

Example 5 with Point

use of com.google.maps.android.geometry.Point in project android-maps-utils by googlemaps.

the class HeatmapTileProvider method getMaxValue.

/**
 * Calculate a reasonable maximum intensity value to map to maximum color intensity
 *
 * @param points    Collection of LatLngs to put into buckets
 * @param bounds    Bucket boundaries
 * @param radius    radius of convolution
 * @param screenDim larger dimension of screen in pixels (for scale)
 * @return Approximate max value
 */
static double getMaxValue(Collection<WeightedLatLng> points, Bounds bounds, int radius, int screenDim) {
    // Approximate scale as if entire heatmap is on the screen
    // ie scale dimensions to larger of width or height (screenDim)
    double minX = bounds.minX;
    double maxX = bounds.maxX;
    double minY = bounds.minY;
    double maxY = bounds.maxY;
    double boundsDim = (maxX - minX > maxY - minY) ? maxX - minX : maxY - minY;
    // Number of buckets: have diameter sized buckets
    int nBuckets = (int) (screenDim / (2 * radius) + 0.5);
    // Scaling factor to convert width in terms of point distance, to which bucket
    double scale = nBuckets / boundsDim;
    // Make buckets
    // Use a sparse array - use LongSparseArray just in case
    LongSparseArray<LongSparseArray<Double>> buckets = new LongSparseArray<LongSparseArray<Double>>();
    // double[][] buckets = new double[nBuckets][nBuckets];
    // Assign into buckets + find max value as we go along
    double x, y;
    double max = 0;
    for (WeightedLatLng l : points) {
        x = l.getPoint().x;
        y = l.getPoint().y;
        int xBucket = (int) ((x - minX) * scale);
        int yBucket = (int) ((y - minY) * scale);
        // Check if x bucket exists, if not make it
        LongSparseArray<Double> column = buckets.get(xBucket);
        if (column == null) {
            column = new LongSparseArray<Double>();
            buckets.put(xBucket, column);
        }
        // Check if there is already a y value there
        Double value = column.get(yBucket);
        if (value == null) {
            value = 0.0;
        }
        value += l.getIntensity();
        // Yes, do need to update it, despite it being a Double.
        column.put(yBucket, value);
        if (value > max)
            max = value;
    }
    return max;
}
Also used : LongSparseArray(androidx.collection.LongSparseArray) Point(com.google.maps.android.geometry.Point)

Aggregations

Point (com.google.maps.android.geometry.Point)16 Bounds (com.google.maps.android.geometry.Bounds)5 LongSparseArray (android.support.v4.util.LongSparseArray)3 Cluster (com.google.maps.android.clustering.Cluster)3 SphericalMercatorProjection (com.google.maps.android.projection.SphericalMercatorProjection)3 HashSet (java.util.HashSet)3 Bitmap (android.graphics.Bitmap)2 LongSparseArray (androidx.collection.LongSparseArray)2 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 Test (org.junit.Test)1