Android Open Source - Flight-Computer-Android-Flightradar24 My Location Circle






From Project

Back to project page Flight-Computer-Android-Flightradar24.

License

The source code is released under:

GNU General Public License

If you think the Android project Flight-Computer-Android-Flightradar24 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nutiteq.utils;
/*from w  ww  .  j a  va2  s .c  o  m*/
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import javax.microedition.khronos.opengles.GL10;

import android.location.Location;

import com.nutiteq.components.MapPos;
import com.nutiteq.projections.Projection;
import com.nutiteq.utils.Const;

public class MyLocationCircle {
    private static final int NR_OF_CIRCLE_VERTS = 24;
    private FloatBuffer circleVertBuf;
    private float circleX;
    private float circleY;
    private float circleRadius;
    private float circleScale;
    private float circleAlpha = 1.0f;
    private boolean visible = false;
    
    public MyLocationCircle() {
        // Create circle vertex array for later use in drawing
        ByteBuffer byteBuffer = ByteBuffer
                .allocateDirect((NR_OF_CIRCLE_VERTS + 2) * 3 * Float.SIZE / 8);
        byteBuffer.order(ByteOrder.nativeOrder());
        circleVertBuf = byteBuffer.asFloatBuffer();
        float degreesPerVert = 360.0f / NR_OF_CIRCLE_VERTS;
        circleVertBuf.put(0);
        circleVertBuf.put(0);
        circleVertBuf.put(0);
        for (float tsj = 0; tsj < 360; tsj += degreesPerVert) {
            circleVertBuf.put(android.util.FloatMath.cos(tsj * Const.DEG_TO_RAD));
            circleVertBuf.put(android.util.FloatMath.sin(tsj * Const.DEG_TO_RAD));
            circleVertBuf.put(0);
        }
        circleVertBuf.put(1);
        circleVertBuf.put(0);
        circleVertBuf.put(0);
        circleVertBuf.position(0);
    }
    
    /**
     * Draw circle, called for each frame
     * @param gl OpenGL context
     * @param zoomPow2 Zoom level in power of 2, to calculate easily fixed size on map
     */
    public void draw(GL10 gl, float zoomPow2){
        if(!visible){
            return;
        }

        // circle max radius 
        // make sure that it is at least minimum radius, otherwise is too small in general zoom
        float circleScaleMax = Math.max(
                Const.UNIT_SIZE * circleRadius / 7500000f, // based on GPS accuracy. This constant depends on latitude
                Const.UNIT_SIZE / zoomPow2 * 0.2f); // minimum, fixed value
        float circleScaleStep = circleScaleMax / 100.0f;
        float circleAlphaStep = -circleScaleStep
                / (circleScaleMax - circleScaleStep);
        
        gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
        
        // Colour is yellow (R=1,G=1,B=0)
        gl.glColor4f(1, 1, 0, circleAlpha);

        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, circleVertBuf);

        gl.glPushMatrix();
        gl.glTranslatef(circleX, circleY, 0);
        
        gl.glScalef(circleScale , circleScale , 1);
        gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, NR_OF_CIRCLE_VERTS + 2);
        gl.glPopMatrix();

        // circleScale is size of circle for current frame,
        // in range of 1...circleScaleMax, step circleScaleStep
        // also drawing transparency (alpha channel) is reduced for larger circles
        circleScale += circleScaleStep;
        circleAlpha += circleAlphaStep;
        if (circleScale > circleScaleMax) {
            circleScale = 0.0f;
            circleAlpha = 1.0f;
        }       
    }

    public void setVisible(boolean visible) {
        this.visible = visible;
    }

    public void setLocation(Projection proj, Location location) {
        MapPos mapPos = proj.fromWgs84(location.getLongitude(),
                 location.getLatitude());
        this.circleX = (float) proj.toInternal(mapPos.x, mapPos.y).x;
        this.circleY = (float) proj.toInternal(mapPos.x, mapPos.y).y;
        this.circleRadius = location.getAccuracy();
        
    }
}




Java Source Code List

com.flightcomputer.Circle.java
com.flightcomputer.DownloadActivity.java
com.flightcomputer.EditPreferences.java
com.flightcomputer.FCActivity.java
com.flightcomputer.GpsSkyActivity.java
com.flightcomputer.IgcLoad.java
com.flightcomputer.LeonardoLiveWriter.java
com.flightcomputer.MapEventListener.java
com.flightcomputer.PositionWriter.java
com.flightcomputer.PressureAltimeterActivity.java
com.flightcomputer.RouteLine.java
com.flightcomputer.Task.java
com.flightcomputer.TrckLine.java
com.flightcomputer.filefilter.FilterByFileExtension.java
com.flightcomputer.filefilter.ValidFileFilter.java
com.flightcomputer.filefilter.ValidMapFile.java
com.flightcomputer.filefilter.ValidRenderTheme.java
com.flightcomputer.filepicker.FilePickerIconAdapter.java
com.flightcomputer.filepicker.FilePicker.java
com.flightcomputer.utilities.BaroService.java
com.flightcomputer.utilities.BeepThread.java
com.flightcomputer.utilities.GpsSkyView.java
com.flightcomputer.utilities.KalmanFilter.java
com.flightcomputer.utilities.PiecewiseLinearFunction.java
com.flightcomputer.utilities.Point2d.java
com.flightcomputer.utilities.VerticalProgressBar_Reverse.java
com.flightcomputer.utilities.VerticalProgressBar.java
com.flightcomputer.openGlUtils.java
com.nutiteq.advancedmap.mapquest.SearchQueryResults.java
com.nutiteq.advancedmap.mapquest.SearchSuggestionProvider.java
com.nutiteq.services.geocode.MapQuestGeocoder.java
com.nutiteq.utils.MapsforgeMapLayer.java
com.nutiteq.utils.MbTilesDatabaseHelper.java
com.nutiteq.utils.MyLocationCircle.java
com.nutiteq.utils.NetUtils.java
com.nutiteq.utils.UiUtils.java
com.nutiteq.utils.UtfGridHelper.java
com.nutiteq.utils.UtfGridLayerInterface.java