Search in sources :

Example 11 with QuadPoint

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

the class MapMarkersLayer method onDraw.

@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
    widgetsFactory.updateInfo(useFingerLocation ? fingerLocation : null, tileBox.getZoom());
    OsmandSettings settings = map.getMyApplication().getSettings();
    if (tileBox.getZoom() < 3) {
        return;
    }
    int displayedWidgets = settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get();
    MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
    for (MapMarker marker : markersHelper.getMapMarkers()) {
        if (isLocationVisible(tileBox, marker) && !overlappedByWaypoint(marker) && !isInMotion(marker) && !isSynced(marker)) {
            Bitmap bmp = getMapMarkerBitmap(marker.colorIndex);
            int marginX = bmp.getWidth() / 6;
            int marginY = bmp.getHeight();
            int locationX = tileBox.getPixXFromLonNoRot(marker.getLongitude());
            int locationY = tileBox.getPixYFromLatNoRot(marker.getLatitude());
            canvas.rotate(-tileBox.getRotate(), locationX, locationY);
            canvas.drawBitmap(bmp, locationX - marginX, locationY - marginY, bitmapPaint);
            canvas.rotate(tileBox.getRotate(), locationX, locationY);
        }
    }
    if (settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()) {
        LatLon loc = tileBox.getCenterLatLon();
        int i = 0;
        for (MapMarker marker : markersHelper.getMapMarkers()) {
            if (!isLocationVisible(tileBox, marker) && !isInMotion(marker)) {
                canvas.save();
                net.osmand.Location.distanceBetween(loc.getLatitude(), loc.getLongitude(), marker.getLatitude(), marker.getLongitude(), calculations);
                float bearing = calculations[1] - 90;
                float radiusBearing = DIST_TO_SHOW * tileBox.getDensity();
                final QuadPoint cp = tileBox.getCenterPixelPoint();
                canvas.rotate(bearing, cp.x, cp.y);
                canvas.translate(-24 * tileBox.getDensity() + radiusBearing, -22 * tileBox.getDensity());
                canvas.drawBitmap(arrowShadow, cp.x, cp.y, bitmapPaint);
                canvas.drawBitmap(arrowToDestination, cp.x, cp.y, getMarkerDestPaint(marker.colorIndex));
                canvas.drawBitmap(arrowLight, cp.x, cp.y, bitmapPaint);
                canvas.restore();
            }
            i++;
            if (i > displayedWidgets - 1) {
                break;
            }
        }
    }
    if (contextMenuLayer.getMoveableObject() instanceof MapMarker) {
        MapMarker objectInMotion = (MapMarker) contextMenuLayer.getMoveableObject();
        PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox);
        Bitmap bitmap = getMapMarkerBitmap(objectInMotion.colorIndex);
        int marginX = bitmap.getWidth() / 6;
        int marginY = bitmap.getHeight();
        float locationX = pf.x;
        float locationY = pf.y;
        canvas.rotate(-tileBox.getRotate(), locationX, locationY);
        canvas.drawBitmap(bitmap, locationX - marginX, locationY - marginY, bitmapPaint);
    }
}
Also used : LatLon(net.osmand.data.LatLon) Bitmap(android.graphics.Bitmap) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) QuadPoint(net.osmand.data.QuadPoint) PointF(android.graphics.PointF) OsmandSettings(net.osmand.plus.OsmandSettings) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint) Paint(android.graphics.Paint)

Example 12 with QuadPoint

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

the class OsmandMapTileView method refreshBaseMapInternal.

private void refreshBaseMapInternal(RotatedTileBox tileBox, DrawSettings drawSettings) {
    if (tileBox.getPixHeight() == 0 || tileBox.getPixWidth() == 0) {
        return;
    }
    if (bufferBitmapTmp == null || tileBox.getPixHeight() != bufferBitmapTmp.getHeight() || tileBox.getPixWidth() != bufferBitmapTmp.getWidth()) {
        bufferBitmapTmp = Bitmap.createBitmap(tileBox.getPixWidth(), tileBox.getPixHeight(), Config.RGB_565);
    }
    long start = SystemClock.elapsedRealtime();
    final QuadPoint c = tileBox.getCenterPixelPoint();
    Canvas canvas = new Canvas(bufferBitmapTmp);
    fillCanvas(canvas, drawSettings);
    for (int i = 0; i < layers.size(); i++) {
        try {
            OsmandMapLayer layer = layers.get(i);
            canvas.save();
            // rotate if needed
            if (!layer.drawInScreenPixels()) {
                canvas.rotate(tileBox.getRotate(), c.x, c.y);
            }
            layer.onPrepareBufferImage(canvas, tileBox, drawSettings);
            canvas.restore();
        } catch (IndexOutOfBoundsException e) {
            // skip it
            canvas.restore();
        }
    }
    Bitmap t = bufferBitmap;
    synchronized (this) {
        bufferImgLoc = tileBox;
        bufferBitmap = bufferBitmapTmp;
        bufferBitmapTmp = t;
    }
    long end = SystemClock.elapsedRealtime();
    additional.calculateFPS(start, end);
}
Also used : Bitmap(android.graphics.Bitmap) QuadPoint(net.osmand.data.QuadPoint) Canvas(android.graphics.Canvas) QuadPoint(net.osmand.data.QuadPoint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Example 13 with QuadPoint

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

the class RulerControlLayer method initLayer.

@Override
public void initLayer(final OsmandMapTileView view) {
    app = mapActivity.getMyApplication();
    this.view = view;
    mapDensity = mapActivity.getMyApplication().getSettings().MAP_DENSITY;
    cacheMapDensity = mapDensity.get();
    cacheDistances = new ArrayList<>();
    cacheCenter = new QuadPoint();
    maxRadiusInDp = mapActivity.getResources().getDimensionPixelSize(R.dimen.map_ruler_width);
    rightWidgetsPanel = mapActivity.findViewById(R.id.map_right_widgets_panel);
    touchPoint = new PointF();
    acceptableTouchRadius = mapActivity.getResources().getDimensionPixelSize(R.dimen.acceptable_touch_radius);
    centerIconDay = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_ruler_center_day);
    centerIconNight = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_ruler_center_night);
    bitmapPaint = new Paint();
    bitmapPaint.setAntiAlias(true);
    bitmapPaint.setDither(true);
    bitmapPaint.setFilterBitmap(true);
    lineAttrs = new RenderingLineAttributes("rulerLine");
    float circleTextSize = TEXT_SIZE * mapActivity.getResources().getDisplayMetrics().density;
    float lineTextSize = DISTANCE_TEXT_SIZE * mapActivity.getResources().getDisplayMetrics().density;
    lineFontAttrs = new RenderingLineAttributes("rulerLineFont");
    lineFontAttrs.paint.setTextSize(lineTextSize);
    lineFontAttrs.paint2.setTextSize(lineTextSize);
    circleAttrs = new RenderingLineAttributes("rulerCircle");
    circleAttrs.paint2.setTextSize(circleTextSize);
    circleAttrs.paint3.setTextSize(circleTextSize);
    circleAttrsAlt = new RenderingLineAttributes("rulerCircleAlt");
    circleAttrsAlt.paint2.setTextSize(circleTextSize);
    circleAttrsAlt.paint3.setTextSize(circleTextSize);
    handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            view.refreshMap();
        }
    };
}
Also used : QuadPoint(net.osmand.data.QuadPoint) Message(android.os.Message) PointF(android.graphics.PointF) Handler(android.os.Handler) Paint(android.graphics.Paint)

Example 14 with QuadPoint

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

the class RulerControlLayer method onDraw.

@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
    if (rulerModeOn()) {
        lineAttrs.updatePaints(view, settings, tb);
        lineFontAttrs.updatePaints(view, settings, tb);
        lineFontAttrs.paint.setStyle(Style.FILL);
        circleAttrs.updatePaints(view, settings, tb);
        circleAttrs.paint2.setStyle(Style.FILL);
        circleAttrsAlt.updatePaints(view, settings, tb);
        circleAttrsAlt.paint2.setStyle(Style.FILL);
        final QuadPoint center = tb.getCenterPixelPoint();
        final RulerMode mode = app.getSettings().RULER_MODE.get();
        final long currentTime = System.currentTimeMillis();
        if (cacheMultiTouchEndTime != view.getMultiTouchEndTime()) {
            cacheMultiTouchEndTime = view.getMultiTouchEndTime();
            refreshMapDelayed();
        }
        if (touched && view.isMultiTouch()) {
            touched = false;
            touchEndTime = currentTime;
        }
        if (tb.isZoomAnimated()) {
            wasZoom = true;
        }
        showTwoFingersDistance = !tb.isZoomAnimated() && !view.isWasZoomInMultiTouch() && currentTime - view.getMultiTouchStartTime() > DELAY_BEFORE_DRAW && (view.isMultiTouch() || currentTime - cacheMultiTouchEndTime < DRAW_TIME);
        showDistBetweenFingerAndLocation = !wasZoom && !showTwoFingersDistance && !view.isMultiTouch() && !touchOutside && touchStartTime - view.getMultiTouchStartTime() > DELAY_BEFORE_DRAW && currentTime - touchStartTime > DELAY_BEFORE_DRAW && (touched || currentTime - touchEndTime < DRAW_TIME);
        drawCenterIcon(canvas, tb, center, settings.isNightMode(), mode);
        Location currentLoc = app.getLocationProvider().getLastKnownLocation();
        if (showDistBetweenFingerAndLocation && currentLoc != null) {
            drawDistBetweenFingerAndLocation(canvas, tb, currentLoc, settings.isNightMode());
        } else if (showTwoFingersDistance) {
            drawTwoFingersDistance(canvas, tb, view.getFirstTouchPointLatLon(), view.getSecondTouchPointLatLon(), settings.isNightMode());
        }
        if (mode == RulerMode.FIRST || mode == RulerMode.SECOND) {
            updateData(tb, center);
            RenderingLineAttributes attrs = mode == RulerMode.FIRST ? circleAttrs : circleAttrsAlt;
            for (int i = 1; i <= cacheDistances.size(); i++) {
                drawCircle(canvas, tb, i, center, attrs);
            }
        }
    }
}
Also used : RulerMode(net.osmand.plus.OsmandSettings.RulerMode) QuadPoint(net.osmand.data.QuadPoint) QuadPoint(net.osmand.data.QuadPoint) Paint(android.graphics.Paint) Location(net.osmand.Location)

Aggregations

QuadPoint (net.osmand.data.QuadPoint)14 Paint (android.graphics.Paint)5 LatLon (net.osmand.data.LatLon)5 RouteDataObject (net.osmand.binary.RouteDataObject)3 RotatedTileBox (net.osmand.data.RotatedTileBox)3 SuppressLint (android.annotation.SuppressLint)2 Bitmap (android.graphics.Bitmap)2 PointF (android.graphics.PointF)2 RouteSegmentPoint (net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint)2 Canvas (android.graphics.Canvas)1 Handler (android.os.Handler)1 Message (android.os.Message)1 ArrayList (java.util.ArrayList)1 Location (net.osmand.Location)1 MapMarkersHelper (net.osmand.plus.MapMarkersHelper)1 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)1 OsmandSettings (net.osmand.plus.OsmandSettings)1 RulerMode (net.osmand.plus.OsmandSettings.RulerMode)1 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)1 GeoParsedPoint (net.osmand.util.GeoPointParserUtil.GeoParsedPoint)1