Search in sources :

Example 41 with QuadRect

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

the class TrackActivity method addNewGpxData.

public void addNewGpxData(NewGpxData.ActionType actionType, TrkSegment segment) {
    GPXFile gpxFile = getGpx();
    QuadRect rect = getRect();
    NewGpxData newGpxData = new NewGpxData(gpxFile, rect, actionType, segment);
    WptPt pointToShow = gpxFile != null ? gpxFile.findPointToShow() : null;
    if (pointToShow != null) {
        LatLon location = new LatLon(pointToShow.getLatitude(), pointToShow.getLongitude());
        final OsmandSettings settings = app.getSettings();
        settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_WPT, getString(R.string.add_line)), false, newGpxData);
        MapActivity.launchMapActivityMoveToTop(this);
    }
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) NewGpxData(net.osmand.plus.measurementtool.NewGpxData) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) QuadRect(net.osmand.data.QuadRect) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 42 with QuadRect

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

the class MapActivity method readLocationToShow.

public void readLocationToShow() {
    if (!getDashboard().isVisible()) {
        mapLayers.getMapControlsLayer().showMapControlsIfHidden();
    }
    LatLon cur = new LatLon(mapView.getLatitude(), mapView.getLongitude());
    LatLon latLonToShow = settings.getAndClearMapLocationToShow();
    PointDescription mapLabelToShow = settings.getAndClearMapLabelToShow(latLonToShow);
    Object toShow = settings.getAndClearObjectToShow();
    boolean editToShow = settings.getAndClearEditObjectToShow();
    int status = settings.isRouteToPointNavigateAndClear();
    String searchRequestToShow = settings.getAndClearSearchRequestToShow();
    if (status != 0) {
        // always enable and follow and let calculate it (i.e.GPS is not accessible in a garage)
        Location loc = new Location("map");
        loc.setLatitude(mapView.getLatitude());
        loc.setLongitude(mapView.getLongitude());
        getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true, true);
        if (dashboardOnMap.isVisible()) {
            dashboardOnMap.hideDashboard();
        }
    }
    if (searchRequestToShow != null) {
        showQuickSearch(searchRequestToShow);
    }
    if (latLonToShow != null) {
        if (dashboardOnMap.isVisible()) {
            dashboardOnMap.hideDashboard();
        }
        // remember if map should come back to isMapLinkedToLocation=true
        mapViewTrackingUtilities.setMapLinkedToLocation(false);
        if (mapLabelToShow != null && !mapLabelToShow.contextMenuDisabled()) {
            mapContextMenu.setMapCenter(latLonToShow);
            mapContextMenu.setMapPosition(mapView.getMapPosition());
            mapContextMenu.setCenterMarker(true);
            RotatedTileBox tb = mapView.getCurrentRotatedTileBox().copy();
            LatLon prevCenter = tb.getCenterLatLon();
            double border = 0.8;
            int tbw = (int) (tb.getPixWidth() * border);
            int tbh = (int) (tb.getPixHeight() * border);
            tb.setPixelDimensions(tbw, tbh);
            tb.setLatLonCenter(latLonToShow.getLatitude(), latLonToShow.getLongitude());
            tb.setZoom(ZOOM_LABEL_DISPLAY);
            while (!tb.containsLatLon(prevCenter.getLatitude(), prevCenter.getLongitude()) && tb.getZoom() > MIN_ZOOM_LABEL_DISPLAY) {
                tb.setZoom(tb.getZoom() - 1);
            }
            // mapContextMenu.setMapZoom(settings.getMapZoomToShow());
            mapContextMenu.setMapZoom(tb.getZoom());
            if (toShow instanceof GpxDisplayItem) {
                TrackDetailsMenu trackDetailsMenu = mapLayers.getMapControlsLayer().getTrackDetailsMenu();
                trackDetailsMenu.setGpxItem((GpxDisplayItem) toShow);
                trackDetailsMenu.show();
            } else if (MapRouteInfoMenu.isVisible()) {
                mapContextMenu.showMinimized(latLonToShow, mapLabelToShow, toShow);
                mapLayers.getMapControlsLayer().getMapRouteInfoMenu().updateMenu();
                MapRouteInfoMenu.showLocationOnMap(this, latLonToShow.getLatitude(), latLonToShow.getLongitude());
            } else if (toShow instanceof QuadRect) {
                QuadRect qr = (QuadRect) toShow;
                mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
            } else if (toShow instanceof NewGpxPoint) {
                NewGpxPoint newGpxPoint = (NewGpxPoint) toShow;
                QuadRect qr = newGpxPoint.getRect();
                mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
                getMapLayers().getContextMenuLayer().enterAddGpxPointMode(newGpxPoint);
            } else if (toShow instanceof NewGpxData) {
                NewGpxData newGpxData = (NewGpxData) toShow;
                QuadRect qr = newGpxData.getRect();
                mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
                MeasurementEditingContext editingContext = new MeasurementEditingContext();
                editingContext.setNewGpxData(newGpxData);
                MeasurementToolFragment.showInstance(getSupportFragmentManager(), editingContext);
            } else {
                mapContextMenu.show(latLonToShow, mapLabelToShow, toShow);
            }
            if (editToShow) {
                mapContextMenu.openEditor();
            }
        } else if (!latLonToShow.equals(cur)) {
            mapView.getAnimatedDraggingThread().startMoving(latLonToShow.getLatitude(), latLonToShow.getLongitude(), settings.getMapZoomToShow(), true);
        }
    }
}
Also used : MeasurementEditingContext(net.osmand.plus.measurementtool.MeasurementEditingContext) RotatedTileBox(net.osmand.data.RotatedTileBox) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) GpxDisplayItem(net.osmand.plus.GpxSelectionHelper.GpxDisplayItem) QuadRect(net.osmand.data.QuadRect) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) LatLon(net.osmand.data.LatLon) TrackDetailsMenu(net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu) PointDescription(net.osmand.data.PointDescription) NewGpxData(net.osmand.plus.measurementtool.NewGpxData) Location(net.osmand.Location)

Example 43 with QuadRect

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

the class SearchPhrase method get1km31Rect.

public QuadRect get1km31Rect() {
    if (cache1kmRect != null) {
        return cache1kmRect;
    }
    LatLon l = getLastTokenLocation();
    if (l == null) {
        return null;
    }
    float coeff = (float) (1000 / MapUtils.getTileDistanceWidth(SearchRequest.ZOOM_TO_SEARCH_POI));
    double tx = MapUtils.getTileNumberX(SearchRequest.ZOOM_TO_SEARCH_POI, l.getLongitude());
    double ty = MapUtils.getTileNumberY(SearchRequest.ZOOM_TO_SEARCH_POI, l.getLatitude());
    double topLeftX = Math.max(0, tx - coeff);
    double topLeftY = Math.max(0, ty - coeff);
    int max = (1 << SearchRequest.ZOOM_TO_SEARCH_POI) - 1;
    double bottomRightX = Math.min(max, tx + coeff);
    double bottomRightY = Math.min(max, ty + coeff);
    double pw = MapUtils.getPowZoom(31 - SearchRequest.ZOOM_TO_SEARCH_POI);
    cache1kmRect = new QuadRect(topLeftX * pw, topLeftY * pw, bottomRightX * pw, bottomRightY * pw);
    return cache1kmRect;
}
Also used : LatLon(net.osmand.data.LatLon) QuadRect(net.osmand.data.QuadRect)

Example 44 with QuadRect

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

the class MapUtils method calculateLatLonBbox.

public static QuadRect calculateLatLonBbox(double latitude, double longitude, int radiusMeters) {
    int zoom = 16;
    float coeff = (float) (radiusMeters / MapUtils.getTileDistanceWidth(zoom));
    double tx = MapUtils.getTileNumberX(zoom, longitude);
    double ty = MapUtils.getTileNumberY(zoom, latitude);
    double topLeftX = Math.max(0, tx - coeff);
    double topLeftY = Math.max(0, ty - coeff);
    int max = (1 << zoom) - 1;
    double bottomRightX = Math.min(max, tx + coeff);
    double bottomRightY = Math.min(max, ty + coeff);
    double pw = MapUtils.getPowZoom(31 - zoom);
    QuadRect rect = new QuadRect(topLeftX * pw, topLeftY * pw, bottomRightX * pw, bottomRightY * pw);
    rect.left = MapUtils.get31LongitudeX((int) rect.left);
    rect.top = MapUtils.get31LatitudeY((int) rect.top);
    rect.right = MapUtils.get31LongitudeX((int) rect.right);
    rect.bottom = MapUtils.get31LatitudeY((int) rect.bottom);
    return rect;
}
Also used : QuadRect(net.osmand.data.QuadRect) GeoParsedPoint(net.osmand.util.GeoPointParserUtil.GeoParsedPoint) QuadPoint(net.osmand.data.QuadPoint)

Example 45 with QuadRect

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

the class TextRenderer method intersects.

boolean intersects(QuadRect tRect, float tRot, QuadRect sRect, float sRot) {
    if (Math.abs(tRot) < Math.PI / 15 && Math.abs(sRot) < Math.PI / 15) {
        return QuadRect.intersects(tRect, sRect);
    }
    double dist = Math.sqrt(sqr(tRect.centerX() - sRect.centerX()) + sqr(tRect.centerY() - sRect.centerY()));
    if (dist < 3) {
        return true;
    }
    // difference close to 90/270 degrees
    if (Math.abs(Math.cos(tRot - sRot)) < 0.3) {
        // rotate one rectangle to 90 degrees
        tRot += Math.PI / 2;
        double l = tRect.centerX() - tRect.height() / 2;
        double t = tRect.centerY() - tRect.width() / 2;
        tRect = new QuadRect(l, t, l + tRect.height(), t + tRect.width());
    }
    // determine difference close to 180/0 degrees
    if (Math.abs(Math.sin(tRot - sRot)) < 0.3) {
        // rotate t box
        // (calculate offset for t center suppose we rotate around s center)
        float diff = (float) (-Math.atan2(tRect.centerX() - sRect.centerX(), tRect.centerY() - sRect.centerY()) + Math.PI / 2);
        diff -= sRot;
        double left = sRect.centerX() + dist * Math.cos(diff) - tRect.width() / 2;
        double top = sRect.centerY() - dist * Math.sin(diff) - tRect.height() / 2;
        QuadRect nRect = new QuadRect(left, top, left + tRect.width(), top + tRect.height());
        return QuadRect.intersects(nRect, sRect);
    }
    // TODO other cases not covered
    return QuadRect.intersects(tRect, sRect);
}
Also used : 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