Search in sources :

Example 31 with RotatedTileBox

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

the class MapRouteInfoMenu method showLocationOnMap.

public static void showLocationOnMap(MapActivity mapActivity, double latitude, double longitude) {
    RotatedTileBox tb = mapActivity.getMapView().getCurrentRotatedTileBox().copy();
    int tileBoxWidthPx = 0;
    int tileBoxHeightPx = 0;
    MapRouteInfoMenu routeInfoMenu = mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu();
    WeakReference<MapRouteInfoMenuFragment> fragmentRef = routeInfoMenu.findMenuFragment();
    if (fragmentRef != null) {
        MapRouteInfoMenuFragment f = fragmentRef.get();
        if (mapActivity.isLandscapeLayout()) {
            tileBoxWidthPx = tb.getPixWidth() - f.getWidth();
        } else {
            tileBoxHeightPx = tb.getPixHeight() - f.getHeight();
        }
    }
    mapActivity.getMapView().fitLocationToMap(latitude, longitude, mapActivity.getMapView().getZoom(), tileBoxWidthPx, tileBoxHeightPx, AndroidUtils.dpToPx(mapActivity, 40f), true);
}
Also used : RotatedTileBox(net.osmand.data.RotatedTileBox) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint)

Example 32 with RotatedTileBox

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

the class MapillaryImageDialog method fetchTiles.

public void fetchTiles() {
    RotatedTileBox tileBox = getMapActivity().getMapView().getCurrentRotatedTileBox().copy();
    if (fetchedTileLat == tileBox.getLatitude() && fetchedTileLon == tileBox.getLongitude()) {
        return;
    }
    ITileSource map = TileSourceManager.getMapillaryVectorSource();
    int nzoom = tileBox.getZoom();
    if (nzoom < map.getMinimumZoomSupported()) {
        return;
    }
    ResourceManager mgr = getMapActivity().getMyApplication().getResourceManager();
    final QuadRect tilesRect = tileBox.getTileBounds();
    // recalculate for ellipsoid coordinates
    float ellipticTileCorrection = 0;
    if (map.isEllipticYTile()) {
        ellipticTileCorrection = (float) (MapUtils.getTileEllipsoidNumberY(nzoom, tileBox.getLatitude()) - tileBox.getCenterTileY());
    }
    int left = (int) Math.floor(tilesRect.left);
    int top = (int) Math.floor(tilesRect.top + ellipticTileCorrection);
    int width = (int) Math.ceil(tilesRect.right - left);
    int height = (int) Math.ceil(tilesRect.bottom + ellipticTileCorrection - top);
    int dzoom = nzoom - TILE_ZOOM;
    int div = (int) Math.pow(2.0, dzoom);
    Map<String, Pair<QuadPointDouble, GeometryTile>> tiles = new HashMap<>();
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            int tileX = (left + i) / div;
            int tileY = (top + j) / div;
            String tileId = mgr.calculateTileId(map, tileX, tileY, TILE_ZOOM);
            Pair<QuadPointDouble, GeometryTile> p = tiles.get(tileId);
            if (p == null) {
                GeometryTile tile = null;
                // asking tile image async
                boolean imgExist = mgr.tileExistOnFileSystem(tileId, map, tileX, tileY, TILE_ZOOM);
                if (imgExist) {
                    if (sync) {
                        tile = mgr.getGeometryTilesCache().getTileForMapSync(tileId, map, tileX, tileY, TILE_ZOOM, false);
                        sync = false;
                    } else {
                        tile = mgr.getGeometryTilesCache().getTileForMapAsync(tileId, map, tileX, tileY, TILE_ZOOM, false);
                    }
                }
                if (tile != null) {
                    tiles.put(tileId, new Pair<>(new QuadPointDouble(tileX, tileY), tile));
                }
            }
        }
    }
    fetchedTileLat = tileBox.getLatitude();
    fetchedTileLon = tileBox.getLongitude();
    this.tiles = new ArrayList<>(tiles.values());
}
Also used : RotatedTileBox(net.osmand.data.RotatedTileBox) HashMap(java.util.HashMap) ResourceManager(net.osmand.plus.resources.ResourceManager) QuadRect(net.osmand.data.QuadRect) Point(com.vividsolutions.jts.geom.Point) SuppressLint(android.annotation.SuppressLint) ITileSource(net.osmand.map.ITileSource) GeometryTile(net.osmand.data.GeometryTile) Pair(android.support.v4.util.Pair) QuadPointDouble(net.osmand.data.QuadPointDouble)

Example 33 with RotatedTileBox

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

the class MapViewTrackingUtilities method updateLocation.

@Override
public void updateLocation(Location location) {
    myLocation = location;
    showViewAngle = false;
    if (location != null) {
        locationProvider = location.getProvider();
        if (settings.DRIVING_REGION_AUTOMATIC.get() && !drivingRegionUpdated && !app.isApplicationInitializing()) {
            drivingRegionUpdated = true;
            detectDrivingRegion(new LatLon(location.getLatitude(), location.getLongitude()));
        }
    }
    if (mapView != null) {
        RotatedTileBox tb = mapView.getCurrentRotatedTileBox();
        if (isMapLinkedToLocation() && location != null) {
            Pair<Integer, Double> zoom = null;
            Float rotation = null;
            if (settings.AUTO_ZOOM_MAP.get()) {
                zoom = autozoom(location);
            }
            int currentMapRotation = settings.ROTATE_MAP.get();
            float speedForDirectionOfMovement = settings.SWITCH_MAP_DIRECTION_TO_COMPASS.get();
            boolean smallSpeedForDirectionOfMovement = speedForDirectionOfMovement != 0 && isSmallSpeedForDirectionOfMovement(location, speedForDirectionOfMovement);
            boolean smallSpeedForCompass = isSmallSpeedForCompass(location);
            boolean smallSpeedForAnimation = isSmallSpeedForAnimation(location);
            // boolean virtualBearing = fMode && settings.SNAP_TO_ROAD.get();
            showViewAngle = (!location.hasBearing() || smallSpeedForCompass) && (tb != null && tb.containsLatLon(location.getLatitude(), location.getLongitude()));
            if (currentMapRotation == OsmandSettings.ROTATE_MAP_BEARING) {
                if (smallSpeedForDirectionOfMovement) {
                    showViewAngle = routePlanningMode;
                } else if (location.hasBearing() && !smallSpeedForCompass) {
                    // special case when bearing equals to zero (we don't change anything)
                    if (location.getBearing() != 0f) {
                        rotation = -location.getBearing();
                    }
                }
            } else if (currentMapRotation == OsmandSettings.ROTATE_MAP_COMPASS) {
                // disable compass rotation in that mode
                showViewAngle = routePlanningMode;
            }
            registerUnregisterSensor(location, smallSpeedForDirectionOfMovement);
            if (settings.ANIMATE_MY_LOCATION.get() && !smallSpeedForAnimation && !movingToMyLocation && settings.WAKE_ON_VOICE_INT.get() == 0) {
                mapView.getAnimatedDraggingThread().startMoving(location.getLatitude(), location.getLongitude(), zoom, rotation, false);
            } else {
                if (zoom != null) {
                    mapView.getAnimatedDraggingThread().startZooming(zoom.first, zoom.second, false);
                }
                if (rotation != null) {
                    mapView.setRotate(rotation);
                }
                mapView.setLatLon(location.getLatitude(), location.getLongitude());
            }
        } else if (location != null) {
            showViewAngle = (!location.hasBearing() || isSmallSpeedForCompass(location)) && (tb != null && tb.containsLatLon(location.getLatitude(), location.getLongitude()));
            registerUnregisterSensor(location, false);
        }
        RoutingHelper routingHelper = app.getRoutingHelper();
        followingMode = routingHelper.isFollowingMode();
        if (routePlanningMode != routingHelper.isRoutePlanningMode()) {
            switchToRoutePlanningMode();
        }
        // When location is changed we need to refresh map in order to show movement!
        mapView.refreshMap();
    }
    if (dashboard != null) {
        dashboard.updateMyLocation(location);
    }
    if (contextMenu != null) {
        contextMenu.updateMyLocation(location);
    }
}
Also used : LatLon(net.osmand.data.LatLon) RotatedTileBox(net.osmand.data.RotatedTileBox) RoutingHelper(net.osmand.plus.routing.RoutingHelper)

Example 34 with RotatedTileBox

use of net.osmand.data.RotatedTileBox 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 35 with RotatedTileBox

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

the class MapVectorLayer method onPrepareBufferImage.

@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tilesRect, DrawSettings drawSettings) {
    if (!visible) {
        return;
    }
    // if (!isVectorDataVisible() && tileLayer != null) {
    // tileLayer.drawTileMap(canvas, tilesRect);
    // resourceManager.getRenderer().interruptLoadingMap();
    // } else {
    final MapRendererView mapRenderer = view.getMapRenderer();
    if (mapRenderer != null && !oldRender) {
        NativeCoreContext.getMapRendererContext().setNightMode(drawSettings.isNightMode());
        OsmandSettings st = view.getApplication().getSettings();
        if (!Algorithms.objectEquals(st.MAP_UNDERLAY.get(), cachedUnderlay)) {
            cachedUnderlay = st.MAP_UNDERLAY.get();
            ITileSource tileSource = st.getTileSourceByName(cachedUnderlay, false);
            if (tileSource != null) {
                TileSourceProxyProvider prov = new TileSourceProxyProvider(view.getApplication(), tileSource);
                mapRenderer.setMapLayerProvider(-1, prov.instantiateProxy(true));
                prov.swigReleaseOwnership();
            // mapRenderer.setMapLayerProvider(-1,
            // net.osmand.core.jni.OnlineTileSources.getBuiltIn().createProviderFor("Mapnik (OsmAnd)"));
            } else {
                mapRenderer.resetMapLayerProvider(-1);
            }
        }
        if (!Algorithms.objectEquals(st.MAP_TRANSPARENCY.get(), cachedMapTransparency)) {
            cachedMapTransparency = st.MAP_TRANSPARENCY.get();
            MapLayerConfiguration mapLayerConfiguration = new MapLayerConfiguration();
            mapLayerConfiguration.setOpacityFactor(((float) cachedMapTransparency) / 255.0f);
            mapRenderer.setMapLayerConfiguration(0, mapLayerConfiguration);
        }
        if (!Algorithms.objectEquals(st.MAP_OVERLAY.get(), cachedOverlay)) {
            cachedOverlay = st.MAP_OVERLAY.get();
            ITileSource tileSource = st.getTileSourceByName(cachedOverlay, false);
            if (tileSource != null) {
                TileSourceProxyProvider prov = new TileSourceProxyProvider(view.getApplication(), tileSource);
                mapRenderer.setMapLayerProvider(1, prov.instantiateProxy(true));
                prov.swigReleaseOwnership();
            // mapRenderer.setMapLayerProvider(1,
            // net.osmand.core.jni.OnlineTileSources.getBuiltIn().createProviderFor("Mapnik (OsmAnd)"));
            } else {
                mapRenderer.resetMapLayerProvider(1);
            }
        }
        if (!Algorithms.objectEquals(st.MAP_OVERLAY_TRANSPARENCY.get(), cachedOverlayTransparency)) {
            cachedOverlayTransparency = st.MAP_OVERLAY_TRANSPARENCY.get();
            MapLayerConfiguration mapLayerConfiguration = new MapLayerConfiguration();
            mapLayerConfiguration.setOpacityFactor(((float) cachedOverlayTransparency) / 255.0f);
            mapRenderer.setMapLayerConfiguration(1, mapLayerConfiguration);
        }
        // opengl renderer
        LatLon ll = tilesRect.getLatLonFromPixel(tilesRect.getPixWidth() / 2, tilesRect.getPixHeight() / 2);
        mapRenderer.setTarget(new PointI(MapUtils.get31TileNumberX(ll.getLongitude()), MapUtils.get31TileNumberY(ll.getLatitude())));
        mapRenderer.setAzimuth(-tilesRect.getRotate());
        mapRenderer.setZoom((float) (tilesRect.getZoom() + tilesRect.getZoomAnimation() + tilesRect.getZoomFloatPart()));
        float zoomMagnifier = st.MAP_DENSITY.get();
        mapRenderer.setVisualZoomShift(zoomMagnifier - 1.0f);
    } else {
        if (!view.isZooming()) {
            if (resourceManager.updateRenderedMapNeeded(tilesRect, drawSettings)) {
                // pixRect.set(-view.getWidth(), -view.getHeight() / 2, 2 * view.getWidth(), 3 *
                // view.getHeight() / 2);
                final RotatedTileBox copy = tilesRect.copy();
                copy.increasePixelDimensions(copy.getPixWidth() / 3, copy.getPixHeight() / 4);
                resourceManager.updateRendererMap(copy, null);
            }
        }
        MapRenderRepositories renderer = resourceManager.getRenderer();
        drawRenderedMap(canvas, renderer.getBitmap(), renderer.getBitmapLocation(), tilesRect);
        drawRenderedMap(canvas, renderer.getPrevBitmap(), renderer.getPrevBmpLocation(), tilesRect);
    }
}
Also used : LatLon(net.osmand.data.LatLon) RotatedTileBox(net.osmand.data.RotatedTileBox) MapLayerConfiguration(net.osmand.core.jni.MapLayerConfiguration) MapRendererView(net.osmand.core.android.MapRendererView) PointI(net.osmand.core.jni.PointI) ITileSource(net.osmand.map.ITileSource) TileSourceProxyProvider(net.osmand.core.android.TileSourceProxyProvider) OsmandSettings(net.osmand.plus.OsmandSettings)

Aggregations

RotatedTileBox (net.osmand.data.RotatedTileBox)48 LatLon (net.osmand.data.LatLon)20 QuadPoint (net.osmand.data.QuadPoint)15 Paint (android.graphics.Paint)11 QuadRect (net.osmand.data.QuadRect)8 SuppressLint (android.annotation.SuppressLint)7 View (android.view.View)6 ImageView (android.widget.ImageView)5 ArrayList (java.util.ArrayList)4 Location (net.osmand.Location)4 ITileSource (net.osmand.map.ITileSource)4 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)4 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)4 PointF (android.graphics.PointF)3 TextView (android.widget.TextView)3 List (java.util.List)3 QuadPointDouble (net.osmand.data.QuadPointDouble)3 WptPt (net.osmand.plus.GPXUtilities.WptPt)3 DialogInterface (android.content.DialogInterface)2 Bitmap (android.graphics.Bitmap)2