org.mapsforge.core.model.BoundingBox Java Examples

The following examples show how to use org.mapsforge.core.model.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: NavigationOverlay.java    From WhereYouGo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas) {
    // TODO Auto-generated method stub
    if (target == null || !myLocationOverlay.isMyLocationEnabled()
            || myLocationOverlay.getLastLocation() == null)
        return;
    double canvasPixelLeft =
            MercatorProjection.longitudeToPixelX(boundingBox.minLongitude, zoomLevel);
    double canvasPixelTop = MercatorProjection.latitudeToPixelY(boundingBox.maxLatitude, zoomLevel);
    Point canvasPosition = new Point(canvasPixelLeft, canvasPixelTop);

    Location startLocation = myLocationOverlay.getLastLocation();
    GeoPoint start = new GeoPoint(startLocation.getLatitude(), startLocation.getLongitude());

    List<GeoPoint> geoPoints = new ArrayList<GeoPoint>();
    geoPoints.add(start);
    geoPoints.add(target);
    line.setPolygonalChain(new PolygonalChain(geoPoints));
    line.draw(boundingBox, zoomLevel, canvas, canvasPosition);

/*
 * double canvasPixelLeft = MercatorProjection.longitudeToPixelX( boundingBox.minLongitude,
 * zoomLevel); double canvasPixelTop = MercatorProjection.latitudeToPixelY(
 * boundingBox.maxLatitude, zoomLevel); Point canvasPosition = new Point(canvasPixelLeft,
 * canvasPixelTop); Point a = getPoint(start, canvasPosition, zoomLevel); Point b =
 * getPoint(target, canvasPosition, zoomLevel); canvas.drawLine(a.x, a.y, b.x, b.y, paint);
 */
}
 
Example #2
Source File: RotationMarker.java    From WhereYouGo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public synchronized boolean draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas,
                                 Point canvasPosition) {
    GeoPoint geoPoint = this.getGeoPoint();
    Drawable drawable = this.getDrawable();
    if (geoPoint == null || drawable == null) {
        return false;
    }

    double latitude = geoPoint.latitude;
    double longitude = geoPoint.longitude;
    int pixelX =
            (int) (MercatorProjection.longitudeToPixelX(longitude, zoomLevel) - canvasPosition.x);
    int pixelY =
            (int) (MercatorProjection.latitudeToPixelY(latitude, zoomLevel) - canvasPosition.y);

    Rect drawableBounds = drawable.copyBounds();
    int left = pixelX + drawableBounds.left;
    int top = pixelY + drawableBounds.top;
    int right = pixelX + drawableBounds.right;
    int bottom = pixelY + drawableBounds.bottom;

    if (!intersect(canvas, left, top, right, bottom)) {
        return false;
    }

    int saveCount = canvas.save();
    canvas.rotate(rotation, (float) pixelX, (float) pixelY);
    drawable.setBounds(left, top, right, bottom);
    drawable.draw(canvas);
    drawable.setBounds(drawableBounds);
    canvas.restoreToCount(saveCount);
    return true;
}
 
Example #3
Source File: MyLocationOverlay.java    From WhereYouGo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas) {
    if (!this.myLocationEnabled) {
        return;
    }

    double canvasPixelLeft =
            MercatorProjection.longitudeToPixelX(boundingBox.minLongitude, zoomLevel);
    double canvasPixelTop = MercatorProjection.latitudeToPixelY(boundingBox.maxLatitude, zoomLevel);
    Point canvasPosition = new Point(canvasPixelLeft, canvasPixelTop);
    this.circle.draw(boundingBox, zoomLevel, canvas, canvasPosition);
    this.marker.draw(boundingBox, zoomLevel, canvas, canvasPosition);
}
 
Example #4
Source File: MapsforgeNwwLayer.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public MapsforgeNwwLayer(String layerName, File[] mapsforgeFiles, Integer tileSize, Float scaleFactor)
		throws Exception {
	super(makeLevels(layerName, getTilegenerator(mapsforgeFiles, tileSize, scaleFactor), tileSize));
	this.layerName = layerName;
	this.setUseTransparentTextures(true);

	MultiMapDataStore mapDatabase = new MultiMapDataStore(DataPolicy.RETURN_ALL);
	for (int i = 0; i < mapsforgeFiles.length; i++)
		mapDatabase.addMapDataStore(new MapFile(mapsforgeFiles[i]), false, false);
	BoundingBox boundingBox = mapDatabase.boundingBox();
	LatLong centerPoint = boundingBox.getCenterPoint();
	centerCoordinate = new Coordinate(centerPoint.longitude, centerPoint.latitude);
	mapDatabase.close();
}
 
Example #5
Source File: Mapsforge2MbtilesConverter.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
private OsmTilegenerator getGenerator( ReferencedEnvelope llBounds ) {
//        MapWorkerPool.NUMBER_OF_THREADS = 4;
//        // Map buffer size
//        ReadBuffer.setMaximumBufferSize(6500000);
//        // Square frame buffer
//        FrameBufferController.setUseSquareFrameBuffer(false);

        DisplayModel model = new DisplayModel();
        model.setUserScaleFactor(pScaleFactor);
        model.setFixedTileSize(pTilesize);

        DataPolicy dataPolicy = DataPolicy.RETURN_ALL;
        MultiMapDataStore mapDatabase = new MultiMapDataStore(dataPolicy);
        for( int i = 0; i < inMapFiles.length; i++ )
            mapDatabase.addMapDataStore(new MapFile(inMapFiles[i]), false, false);

        if (llBounds != null) {
            BoundingBox bb = mapDatabase.boundingBox();
            llBounds.expandToInclude(new Envelope(bb.minLongitude, bb.maxLongitude, bb.minLatitude, bb.maxLatitude));
        }

        InMemoryTileCache tileCache = new InMemoryTileCache(200);
        DatabaseRenderer renderer = new DatabaseRenderer(mapDatabase, AwtGraphicFactory.INSTANCE, tileCache,
                new TileBasedLabelStore(tileCache.getCapacityFirstLevel()), true, true, null);
        InternalRenderTheme xmlRenderTheme = InternalRenderTheme.DEFAULT;
        RenderThemeFuture theme = new RenderThemeFuture(AwtGraphicFactory.INSTANCE, xmlRenderTheme, model);
        // super important!! without the following line, all rendering
        // activities will block until the theme is created.
        new Thread(theme).start();
        OsmTilegenerator osmTilegenerator = new OsmTilegenerator(mapDatabase, renderer, theme, model, pTilesize);
        return osmTilegenerator;
    }
 
Example #6
Source File: MapsforgeTilesGenerator.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get lat/lon bounds of map.
 * 
 * @return the bounds as [n,s,w,e].
 */
public double[] getMapBounds() {
    BoundingBox bb = mapDataStore.boundingBox();
    double[] nswe = new double[4];
    nswe[0] = bb.maxLatitude;
    nswe[1] = bb.minLatitude;
    nswe[2] = bb.minLongitude;
    nswe[3] = bb.maxLongitude;
    return nswe;
}
 
Example #7
Source File: MapsForgeTileSource.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
public org.osmdroid.util.BoundingBox getBoundsOsmdroid(){
    BoundingBox boundingBox = mapDatabase.boundingBox();
    final double latNorth= Math.min(MapView.getTileSystem().getMaxLatitude(),boundingBox.maxLatitude);
    final double latSouth= Math.max(MapView.getTileSystem().getMinLatitude(),boundingBox.minLatitude);
    return new org.osmdroid.util.BoundingBox(
            latNorth, boundingBox.maxLongitude,
            latSouth, boundingBox.minLongitude);
}
 
Example #8
Source File: ForgeMap.java    From Androzic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void recalculateCache()
{
	if (!isCurrent)
		return;

	int nx = (int) Math.ceil(viewportWidth * 1. / (tileSize * dynZoom)) + 4;
	int ny = (int) Math.ceil(viewportHeight * 1. / (tileSize * dynZoom)) + 4;

	BoundingBox boundingBox = mapDataStore.boundingBox();

	getTileXYByLatLon(boundingBox.maxLatitude, boundingBox.minLongitude, minCR);
	getTileXYByLatLon(boundingBox.minLatitude, boundingBox.maxLongitude, maxCR);

	int mnx = maxCR[0] - minCR[0] + 2;
	int mny = maxCR[1] - minCR[1] + 2;
	if (nx > mnx)
		nx = mnx;
	if (ny > mny)
		ny = mny;
	int cacheSize = (int) Math.ceil(nx * ny * 1.2);
	Log.i("ForgeMap", "Cache size: " + cacheSize);
	Log.i("ForgeMap", "Capacity: " + tileCache.getCapacityFirstLevel());

	if (cacheSize > tileCache.getCapacityFirstLevel())
	{
		TileCache oldCache = memoryTileCache;
		memoryTileCache = new InMemoryTileCache(cacheSize);
		tileCache.setFirstLevelCache(memoryTileCache);
		if (oldCache != null)
			oldCache.destroy();
	}
}
 
Example #9
Source File: MapsForgeTileSource.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
public BoundingBox getBounds(){
    return mapDatabase.boundingBox();
}
 
Example #10
Source File: ForgeLayer.java    From Androzic with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint)
{
}