org.oscim.core.BoundingBox Java Examples

The following examples show how to use org.oscim.core.BoundingBox. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DrawPathTaskTest.java    From open with GNU General Public License v3.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
    application = (TestMapzenApplication) Robolectric.application;
    application.inject(this);
    TestHelper.initBaseActivity();
    TestMap testMap = (TestMap) mapController.getMap();
    viewController = Mockito.mock(ViewController.class);
    testMap.setViewport(viewController);
    task = new DrawPathTask(application);
    box = Mockito.mock(BoundingBox.class);
    stub(viewController.getBBox()).toReturn(box);
    outsideBefore1 = new Location("f");
    outsideBefore1.setLatitude(1);
    outsideBefore2 = new Location("f");
    outsideBefore2.setLatitude(2);
    inside1 = new Location("f");
    inside1.setLatitude(3);
    inside2 = new Location("f");
    inside2.setLatitude(4);
    outSideAfter1 = new Location("f");
    outSideAfter1.setLatitude(5);
    outSideAfter2 = new Location("f");
    outSideAfter2.setLatitude(6);
}
 
Example #2
Source File: Animator.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void animateTo(long duration, BoundingBox bbox, Easing.Type easingType, int state) {
    ThreadUtils.assertMainThread();

    mMap.getMapPosition(mStartPos);
    /* TODO for large distance first scale out, then in
     * calculate the maximum scale at which the BoundingBox
     * is completely visible */
    double dx = Math.abs(longitudeToX(bbox.getMaxLongitude())
            - longitudeToX(bbox.getMinLongitude()));

    double dy = Math.abs(latitudeToY(bbox.getMinLatitude())
            - latitudeToY(bbox.getMaxLatitude()));

    log.debug("anim bbox " + bbox);

    double zx = mMap.getWidth() / (dx * Tile.SIZE);
    double zy = mMap.getHeight() / (dy * Tile.SIZE);
    double newScale = Math.min(zx, zy);

    GeoPoint p = bbox.getCenterPoint();

    mDeltaPos.set(longitudeToX(p.getLongitude()) - mStartPos.x,
            latitudeToY(p.getLatitude()) - mStartPos.y,
            newScale - mStartPos.scale,
            -mStartPos.bearing,
            -mStartPos.tilt);

    animStart(duration, state, easingType);
}
 
Example #3
Source File: GeoPointUtils.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculates the scale that allows to display the {@link BoundingBox} on a view with width and
 * height.
 *
 * @param bbox       the {@link BoundingBox} to display.
 * @param viewWidth  the width of the view.
 * @param viewHeight the height of the view.
 * @return the scale that allows to display the {@link BoundingBox} on a view with width and
 * height.
 */
public static double scaleForBounds(BoundingBox bbox, int viewWidth, int viewHeight) {
    double minx = MercatorProjection.longitudeToX(bbox.getMinLongitude());
    double miny = MercatorProjection.latitudeToY(bbox.getMaxLatitude());

    double dx = Math.abs(MercatorProjection.longitudeToX(bbox.getMaxLongitude()) - minx);
    double dy = Math.abs(MercatorProjection.latitudeToY(bbox.getMinLatitude()) - miny);
    double zx = viewWidth / (dx * Tile.SIZE);
    double zy = viewHeight / (dy * Tile.SIZE);

    return Math.min(zx, zy);
}
 
Example #4
Source File: RMapsDatabase.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
static TileSource.OpenResult initialize(SQLiteTileSource tileSource, SQLiteDatabase database) {
    try {
        int minZoom = (int) database.compileStatement(SQL_GET_MIN_ZOOM).simpleQueryForLong();
        int maxZoom = (int) database.compileStatement(SQL_GET_MAX_ZOOM).simpleQueryForLong();
        tileSource.setMinZoom(minZoom);
        tileSource.setMaxZoom(maxZoom);

        String[] args = {String.valueOf(17 - maxZoom)};
        int minX = getInt(database, SQL_GET_MIN_X, args);
        int minY = getInt(database, SQL_GET_MIN_Y, args);
        int maxX = getInt(database, SQL_GET_MAX_X, args) + 1;
        int maxY = getInt(database, SQL_GET_MAX_Y, args) + 1;

        double scale = 1 << maxZoom;
        tileSource.mBoundingBox = new BoundingBox(
                MercatorProjection.toLatitude(maxY / scale),
                MercatorProjection.toLongitude(minX / scale),
                MercatorProjection.toLatitude(minY / scale),
                MercatorProjection.toLongitude(maxX / scale)
        );

        //TODO Try to fill zoom table and see what happens
    } catch (SQLException e) {
        return new TileSource.OpenResult(e.toString());
    }
    return TileSource.OpenResult.SUCCESS;
}
 
Example #5
Source File: MainActivity.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onTrackView(Track track) {
    if (mLocationState == LocationState.NORTH || mLocationState == LocationState.TRACK) {
        mLocationState = LocationState.ENABLED;
        updateLocationDrawable();
    }
    BoundingBox box = track.getBoundingBox();
    box.extendBy(0.05);
    mMap.animator().animateTo(box);
}
 
Example #6
Source File: MainActivity.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onRouteView(Route route) {
    if (mLocationState == LocationState.NORTH || mLocationState == LocationState.TRACK) {
        mLocationState = LocationState.ENABLED;
        updateLocationDrawable();
    }
    BoundingBox box = route.getBoundingBox();
    box.extendBy(0.05);
    mMap.animator().animateTo(box);
}
 
Example #7
Source File: SQLiteMapInfo.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
public SQLiteMapInfo(String name, BoundingBox boundingBox) {
    this.name = name;
    this.boundingBox = boundingBox;
}
 
Example #8
Source File: GPMapView.java    From geopaparazzi with GNU General Public License v3.0 4 votes vote down vote up
public GPBBox getBoundingBox() {
    BoundingBox bb = map().getBoundingBox(0);
    return new GPBBox(bb.getMinLatitude(), bb.getMinLongitude(), bb.getMaxLatitude(), bb.getMaxLongitude());
}
 
Example #9
Source File: GPBBox.java    From geopaparazzi with GNU General Public License v3.0 4 votes vote down vote up
public GPBBox(double minLatitude, double minLongitude, double maxLatitude, double maxLongitude) {
    bbox = new BoundingBox(minLatitude, minLongitude, maxLatitude, maxLongitude);
}
 
Example #10
Source File: RoutePreviewFragment.java    From open with GNU General Public License v3.0 4 votes vote down vote up
private void displayRoute() {
    if (route == null) {
        return;
    }

    if (getActivity() == null) {
        return;
    }

    mapController.getMap().layers().remove(path);
    mapController.getMap().layers().remove(markers);
    path = new PathLayer(MapController.getMapController().getMap(), Color.DKGRAY, 8);
    markers = new ItemizedLayer<MarkerItem>(
            MapController.getMapController().getMap(), new ArrayList<MarkerItem>(),
            AndroidGraphics.makeMarker(getActivity().getResources()
                            .getDrawable(R.drawable.ic_pin),
                    MarkerItem.HotspotPlace.BOTTOM_CENTER), null);

    List<Location> points = route.getGeometry();
    long time = System.currentTimeMillis();
    Logger.d("RoutePreviewFragment::success Geometry points before: " + points.size());
    if (points.size() > REDUCE_TOLERANCE) {
        points = reduceWithTolerance(points, REDUCE_TOLERANCE);
    }
    Logger.d("Timing: " + String.valueOf(System.currentTimeMillis() - time));
    Logger.d("RoutePreviewFragment::success Geometry points after: " + points.size());
    path.clearPath();
    double minlat = Integer.MAX_VALUE;
    double minlon = Integer.MAX_VALUE;
    double maxlat = Integer.MIN_VALUE;
    double maxlon = Integer.MIN_VALUE;
    for (Location loc : points) {
        maxlat = Math.max(maxlat, loc.getLatitude());
        maxlon = Math.max(maxlon, loc.getLongitude());
        minlat = Math.min(minlat, loc.getLatitude());
        minlon = Math.min(minlon, loc.getLongitude());
        path.addPoint(locationToGeoPoint(loc));
    }

    BoundingBox bbox = new BoundingBox(minlat, minlon, maxlat, maxlon);
    int w = mapController.getMap().getWidth();
    int h = mapController.getMap().getHeight();
    MapPosition position = new MapPosition();
    position.setByBoundingBox(bbox, w, h);

    position.setScale(position.getZoomScale() * 0.85);

    mapController.getMap().setMapPosition(position);

    if (!mapController.getMap().layers().contains(path)) {
        mapController.getMap().layers().add(path);
    }

    if (!mapController.getMap().layers().contains(markers)) {
        mapController.getMap().layers().add(markers);
    }
    markers.removeAllItems();
    markers.addItem(getMarkerItem(R.drawable.ic_a, points.get(0),
            MarkerItem.HotspotPlace.CENTER));
    markers.addItem(getMarkerItem(R.drawable.ic_b, points.get(points.size() - 1),
            MarkerItem.HotspotPlace.BOTTOM_CENTER));
}
 
Example #11
Source File: DrawPathTask.java    From open with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Void doInBackground(ArrayList<Location>... locs) {
    final ArrayList<Location> locations = locs[0];
    final ViewController viewPort = mapController.getMap().viewport();
    if (isCancelled()) {
        Logger.d("Cancelled before starting");
        return null;
    }
    BoundingBox boundingBox = viewPort.getBBox();

    ArrayList<PathLayer> layers = new ArrayList<PathLayer>();
    long starttime = System.currentTimeMillis();
    PathLayer p = null;
    boolean prePointAdded = false;
    for (Location loc : locations) {
        if (isCancelled()) {
            Logger.d("Cancelled during iteration: index: "
                    + String.valueOf(locations.indexOf(loc)
                    + " of: " + String.valueOf(locations.size())));
            return null;
        }
        GeoPoint point = locationToGeoPoint(loc);
        if (boundingBox.contains(point)) {

            if (p == null) {
                p = new PathLayer(
                        mapController.getMap(), Color.BLACK, 8);
                layers.add(p);
            }
            if (!prePointAdded) {
                int previousId = locations.indexOf(loc) - 1;
                if (previousId > 0) {
                    p.addPoint(locationToGeoPoint(locations.get(previousId)));
                }
                prePointAdded = true;
            }
            p.addPoint(point);
        } else {
            prePointAdded = false;
            if (p != null) {
                p.addPoint(locationToGeoPoint(loc));
                p = null;
            }
        }
    }
    mapController.getMap().layers().addAll(layers);
    mapController.moveToTop(RouteLocationIndicator.class);
    mapController.clearLinesExcept(layers);
    Logger.d("TIMING: " + (System.currentTimeMillis() - starttime));
    Logger.d("viewbox: " + viewPort.getBBox().toString());
    return null;
}
 
Example #12
Source File: GmsMapsTypeHelper.java    From android_packages_apps_GmsCore with Apache License 2.0 4 votes vote down vote up
public static BoundingBox fromLatLngBounds(LatLngBounds bounds) {
    return new BoundingBox(bounds.southwest.latitude, bounds.southwest.longitude,
            bounds.northeast.latitude, bounds.northeast.longitude);
}
 
Example #13
Source File: Map.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
public BoundingBox getBoundingBox(int expand) {
    Box box = new Box();
    mViewport.getBBox(box, expand);
    box.map2mercator();
    return new BoundingBox(box.ymin, box.xmin, box.ymax, box.xmax);
}
 
Example #14
Source File: Viewport.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
public void setMapLimit(BoundingBox mapLimit) {
    this.mMinX = MercatorProjection.longitudeToX(mapLimit.getMinLongitude());
    this.mMinY = MercatorProjection.latitudeToY(mapLimit.getMaxLatitude());
    this.mMaxX = MercatorProjection.longitudeToX(mapLimit.getMaxLongitude());
    this.mMaxY = MercatorProjection.latitudeToY(mapLimit.getMinLatitude());
}
 
Example #15
Source File: Viewport.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
public BoundingBox getMapLimit() {
    return new BoundingBox(
            MercatorProjection.toLatitude(mMaxY), MercatorProjection.toLongitude(mMinX),
            MercatorProjection.toLatitude(mMinY), MercatorProjection.toLongitude(mMaxX)
    );
}
 
Example #16
Source File: Animator.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
public void animateTo(BoundingBox bbox) {
    animateTo(1000, bbox, Easing.Type.LINEAR);
}
 
Example #17
Source File: Animator.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
public synchronized void animateTo(long duration, BoundingBox bbox, Easing.Type easingType) {
    animateTo(duration, bbox, easingType, ANIM_MOVE | ANIM_SCALE | ANIM_ROTATE | ANIM_TILT);
}
 
Example #18
Source File: Animator.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
public synchronized void animateTo(long duration, BoundingBox bbox) {
    animateTo(duration, bbox, Easing.Type.LINEAR);
}