Search in sources :

Example 6 with Point

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

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 7 with Point

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

the class HeatmapTileProvider method getTile.

/**
     * Creates tile.
     *
     * @param x    X coordinate of tile.
     * @param y    Y coordinate of tile.
     * @param zoom Zoom level.
     * @return image in Tile format
     */
public Tile getTile(int x, int y, int zoom) {
    // Convert tile coordinates and zoom into Point/Bounds format
    // Know that at zoom level 0, there is one tile: (0, 0) (arbitrary width 512)
    // Each zoom level multiplies number of tiles by 2
    // Width of the world = WORLD_WIDTH = 1
    // x = [0, 1) corresponds to [-180, 180)
    // calculate width of one tile, given there are 2 ^ zoom tiles in that zoom level
    // In terms of world width units
    double tileWidth = WORLD_WIDTH / Math.pow(2, zoom);
    // how much padding to include in search
    // is to tileWidth as mRadius (padding in terms of pixels) is to TILE_DIM
    // In terms of world width units
    double padding = tileWidth * mRadius / TILE_DIM;
    // padded tile width
    // In terms of world width units
    double tileWidthPadded = tileWidth + 2 * padding;
    // padded bucket width - divided by number of buckets
    // In terms of world width units
    double bucketWidth = tileWidthPadded / (TILE_DIM + mRadius * 2);
    // Make bounds: minX, maxX, minY, maxY
    double minX = x * tileWidth - padding;
    double maxX = (x + 1) * tileWidth + padding;
    double minY = y * tileWidth - padding;
    double maxY = (y + 1) * tileWidth + padding;
    // Deal with overlap across lat = 180
    // Need to make it wrap around both ways
    // However, maximum tile size is such that you wont ever have to deal with both, so
    // hence, the else
    // Note: Tile must remain square, so cant optimise by editing bounds
    double xOffset = 0;
    Collection<WeightedLatLng> wrappedPoints = new ArrayList<WeightedLatLng>();
    if (minX < 0) {
        // Need to consider "negative" points
        // (minX to 0) ->  (512+minX to 512) ie +512
        // add 512 to search bounds and subtract 512 from actual points
        Bounds overlapBounds = new Bounds(minX + WORLD_WIDTH, WORLD_WIDTH, minY, maxY);
        xOffset = -WORLD_WIDTH;
        wrappedPoints = mTree.search(overlapBounds);
    } else if (maxX > WORLD_WIDTH) {
        // Cant both be true as then tile covers whole world
        // Need to consider "overflow" points
        // (512 to maxX) -> (0 to maxX-512) ie -512
        // subtract 512 from search bounds and add 512 to actual points
        Bounds overlapBounds = new Bounds(0, maxX - WORLD_WIDTH, minY, maxY);
        xOffset = WORLD_WIDTH;
        wrappedPoints = mTree.search(overlapBounds);
    }
    // Main tile bounds to search
    Bounds tileBounds = new Bounds(minX, maxX, minY, maxY);
    // If outside of *padded* quadtree bounds, return blank tile
    // This is comparing our bounds to the padded bounds of all points in the quadtree
    // ie tiles that don't touch the heatmap at all
    Bounds paddedBounds = new Bounds(mBounds.minX - padding, mBounds.maxX + padding, mBounds.minY - padding, mBounds.maxY + padding);
    if (!tileBounds.intersects(paddedBounds)) {
        return TileProvider.NO_TILE;
    }
    // Search for all points within tile bounds
    Collection<WeightedLatLng> points = mTree.search(tileBounds);
    // If no points, return blank tile
    if (points.isEmpty()) {
        return TileProvider.NO_TILE;
    }
    // Quantize points
    double[][] intensity = new double[TILE_DIM + mRadius * 2][TILE_DIM + mRadius * 2];
    for (WeightedLatLng w : points) {
        Point p = w.getPoint();
        int bucketX = (int) ((p.x - minX) / bucketWidth);
        int bucketY = (int) ((p.y - minY) / bucketWidth);
        intensity[bucketX][bucketY] += w.getIntensity();
    }
    // Quantize wraparound points (taking xOffset into account)
    for (WeightedLatLng w : wrappedPoints) {
        Point p = w.getPoint();
        int bucketX = (int) ((p.x + xOffset - minX) / bucketWidth);
        int bucketY = (int) ((p.y - minY) / bucketWidth);
        intensity[bucketX][bucketY] += w.getIntensity();
    }
    // Convolve it ("smoothen" it out)
    double[][] convolved = convolve(intensity, mKernel);
    // Color it into a bitmap
    Bitmap bitmap = colorize(convolved, mColorMap, mMaxIntensity[zoom]);
    // Convert bitmap to tile and return
    return convertBitmap(bitmap);
}
Also used : Bitmap(android.graphics.Bitmap) Bounds(com.google.maps.android.geometry.Bounds) ArrayList(java.util.ArrayList) Point(com.google.maps.android.geometry.Point) Point(com.google.maps.android.geometry.Point)

Example 8 with Point

use of com.google.maps.android.geometry.Point in project coins-android by bubelov.

the class StaticClusterRenderer 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)

Aggregations

Point (com.google.maps.android.geometry.Point)8 LongSparseArray (android.support.v4.util.LongSparseArray)2 Bounds (com.google.maps.android.geometry.Bounds)2 Bitmap (android.graphics.Bitmap)1 Cluster (com.google.maps.android.clustering.Cluster)1 SphericalMercatorProjection (com.google.maps.android.projection.SphericalMercatorProjection)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1