Search in sources :

Example 6 with QuadRect

use of net.osmand.data.QuadRect in project Osmand by osmandapp.

the class HillshadeLayer method createTileSource.

private SQLiteTileSource createTileSource(MapActivity activity) {
    return new SQLiteTileSource(activity.getMyApplication(), null, new ArrayList<TileSourceTemplate>()) {

        @Override
        protected SQLiteConnection getDatabase() {
            throw new UnsupportedOperationException();
        }

        public boolean isLocked() {
            return false;
        }

        List<String> getTileSource(int x, int y, int zoom) {
            ArrayList<String> ls = new ArrayList<String>();
            int z = (zoom - ZOOM_BOUNDARY);
            if (z > 0) {
                indexedResources.queryInBox(new QuadRect(x >> z, y >> z, (x >> z), (y >> z)), ls);
            } else {
                indexedResources.queryInBox(new QuadRect(x << -z, y << -z, (x + 1) << -z, (y + 1) << -z), ls);
            }
            return ls;
        }

        @Override
        public boolean exists(int x, int y, int zoom) {
            List<String> ts = getTileSource(x, y, zoom);
            for (String t : ts) {
                SQLiteTileSource sqLiteTileSource = resources.get(t);
                if (sqLiteTileSource != null && sqLiteTileSource.exists(x, y, zoom)) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public Bitmap getImage(int x, int y, int zoom, long[] timeHolder) {
            List<String> ts = getTileSource(x, y, zoom);
            for (String t : ts) {
                SQLiteTileSource sqLiteTileSource = resources.get(t);
                if (sqLiteTileSource != null) {
                    Bitmap bmp = sqLiteTileSource.getImage(x, y, zoom, timeHolder);
                    if (bmp != null) {
                        return sqLiteTileSource.getImage(x, y, zoom, timeHolder);
                    }
                }
            }
            return null;
        }

        @Override
        public int getBitDensity() {
            return 32;
        }

        @Override
        public int getMinimumZoomSupported() {
            return 5;
        }

        @Override
        public int getMaximumZoomSupported() {
            return 11;
        }

        @Override
        public int getTileSize() {
            return 256;
        }

        @Override
        public boolean couldBeDownloadedFromInternet() {
            return false;
        }

        @Override
        public String getName() {
            return "Hillshade";
        }

        @Override
        public String getTileFormat() {
            return "jpg";
        }
    };
}
Also used : Bitmap(android.graphics.Bitmap) TileSourceTemplate(net.osmand.map.TileSourceManager.TileSourceTemplate) ArrayList(java.util.ArrayList) QuadRect(net.osmand.data.QuadRect) SQLiteTileSource(net.osmand.plus.SQLiteTileSource)

Example 7 with QuadRect

use of net.osmand.data.QuadRect in project Osmand by osmandapp.

the class MapActivityActions method createReloadTitleDialog.

private Dialog createReloadTitleDialog(final Bundle args) {
    AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
    builder.setMessage(R.string.context_menu_item_update_map_confirm);
    builder.setNegativeButton(R.string.shared_string_cancel, null);
    final OsmandMapTileView mapView = mapActivity.getMapView();
    builder.setPositiveButton(R.string.context_menu_item_update_map, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            int zoom = args.getInt(KEY_ZOOM);
            BaseMapLayer mainLayer = mapView.getMainLayer();
            if (!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()) {
                Toast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
                return;
            }
            final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap();
            if (mapSource == null || !mapSource.couldBeDownloadedFromInternet()) {
                Toast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
                return;
            }
            final RotatedTileBox tb = mapView.getCurrentRotatedTileBox();
            final QuadRect tilesRect = tb.getTileBounds();
            int left = (int) Math.floor(tilesRect.left);
            int top = (int) Math.floor(tilesRect.top);
            int width = (int) (Math.ceil(tilesRect.right) - left);
            int height = (int) (Math.ceil(tilesRect.bottom) - top);
            for (int i = 0; i < width; i++) {
                for (int j = 0; j < height; j++) {
                    ((OsmandApplication) mapActivity.getApplication()).getResourceManager().clearTileForMap(null, mapSource, i + left, j + top, zoom);
                }
            }
            mapView.refreshMap();
        }
    });
    return builder.create();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) BaseMapLayer(net.osmand.plus.views.BaseMapLayer) RotatedTileBox(net.osmand.data.RotatedTileBox) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder) QuadRect(net.osmand.data.QuadRect) MapTileLayer(net.osmand.plus.views.MapTileLayer) ITileSource(net.osmand.map.ITileSource) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView)

Example 8 with QuadRect

use of net.osmand.data.QuadRect in project Osmand by osmandapp.

the class TrackActivity method addPoint.

public void addPoint(PointDescription pointDescription) {
    Intent currentIntent = getIntent();
    if (currentIntent != null) {
        currentIntent.putExtra(TrackActivity.OPEN_POINTS_TAB, true);
    }
    final OsmandSettings settings = app.getSettings();
    GPXFile gpx = getGpx();
    LatLon location = settings.getLastKnownMapLocation();
    QuadRect rect = getRect();
    NewGpxPoint newGpxPoint = new NewGpxPoint(gpx, pointDescription, rect);
    if (gpx != null && location != null) {
        settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), pointDescription, false, newGpxPoint);
        MapActivity.launchMapActivityMoveToTop(this);
    }
}
Also used : LatLon(net.osmand.data.LatLon) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) Intent(android.content.Intent) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) QuadRect(net.osmand.data.QuadRect) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 9 with QuadRect

use of net.osmand.data.QuadRect in project Osmand by osmandapp.

the class TrackActivity method getRect.

public QuadRect getRect() {
    double left = 0, right = 0;
    double top = 0, bottom = 0;
    if (getGpx() != null) {
        for (GPXUtilities.Track track : getGpx().tracks) {
            for (GPXUtilities.TrkSegment segment : track.segments) {
                for (WptPt p : segment.points) {
                    if (left == 0 && right == 0) {
                        left = p.getLongitude();
                        right = p.getLongitude();
                        top = p.getLatitude();
                        bottom = p.getLatitude();
                    } else {
                        left = Math.min(left, p.getLongitude());
                        right = Math.max(right, p.getLongitude());
                        top = Math.max(top, p.getLatitude());
                        bottom = Math.min(bottom, p.getLatitude());
                    }
                }
            }
        }
        for (WptPt p : getGpx().getPoints()) {
            if (left == 0 && right == 0) {
                left = p.getLongitude();
                right = p.getLongitude();
                top = p.getLatitude();
                bottom = p.getLatitude();
            } else {
                left = Math.min(left, p.getLongitude());
                right = Math.max(right, p.getLongitude());
                top = Math.max(top, p.getLatitude());
                bottom = Math.min(bottom, p.getLatitude());
            }
        }
        for (GPXUtilities.Route route : getGpx().routes) {
            for (WptPt p : route.points) {
                if (left == 0 && right == 0) {
                    left = p.getLongitude();
                    right = p.getLongitude();
                    top = p.getLatitude();
                    bottom = p.getLatitude();
                } else {
                    left = Math.min(left, p.getLongitude());
                    right = Math.max(right, p.getLongitude());
                    top = Math.max(top, p.getLatitude());
                    bottom = Math.min(bottom, p.getLatitude());
                }
            }
        }
    }
    return new QuadRect(left, top, right, bottom);
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) QuadRect(net.osmand.data.QuadRect) GPXUtilities(net.osmand.plus.GPXUtilities)

Example 10 with QuadRect

use of net.osmand.data.QuadRect in project Osmand by osmandapp.

the class AudioNotesLayer method onPrepareBufferImage.

@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
    if (tileBox.getZoom() >= startZoom) {
        float iconSize = audio.getWidth() * 3 / 2.5f;
        QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
        DataTileManager<Recording> recs = plugin.getRecordings();
        final QuadRect latlon = tileBox.getLatLonBounds();
        List<Recording> objects = recs.getObjects(latlon.top, latlon.left, latlon.bottom, latlon.right);
        List<Recording> fullObjects = new ArrayList<>();
        List<LatLon> fullObjectsLatLon = new ArrayList<>();
        List<LatLon> smallObjectsLatLon = new ArrayList<>();
        for (Recording o : objects) {
            if (o != contextMenuLayer.getMoveableObject()) {
                float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
                float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
                if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
                    canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
                    smallObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude()));
                } else {
                    fullObjects.add(o);
                    fullObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude()));
                }
            }
        }
        for (Recording o : fullObjects) {
            float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
            float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
            drawRecording(canvas, o, x, y);
        }
        this.fullObjectsLatLon = fullObjectsLatLon;
        this.smallObjectsLatLon = smallObjectsLatLon;
    }
}
Also used : LatLon(net.osmand.data.LatLon) ArrayList(java.util.ArrayList) Recording(net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording) QuadRect(net.osmand.data.QuadRect)

Aggregations

QuadRect (net.osmand.data.QuadRect)60 Paint (android.graphics.Paint)19 ArrayList (java.util.ArrayList)19 LatLon (net.osmand.data.LatLon)13 Bitmap (android.graphics.Bitmap)8 RotatedTileBox (net.osmand.data.RotatedTileBox)8 WptPt (net.osmand.plus.GPXUtilities.WptPt)8 TIntArrayList (gnu.trove.list.array.TIntArrayList)7 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)6 Amenity (net.osmand.data.Amenity)5 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)4 Point (com.vividsolutions.jts.geom.Point)4 List (java.util.List)4 QuadPointDouble (net.osmand.data.QuadPointDouble)4 TransportStop (net.osmand.data.TransportStop)4 PoiCategory (net.osmand.osm.PoiCategory)4 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)4 Rect (android.graphics.Rect)3 RectF (android.graphics.RectF)3 File (java.io.File)3