Search in sources :

Example 1 with Projection

use of com.peterlaurence.trekadvisor.core.projection.Projection in project TrekAdvisor by peterLaurence.

the class MapCalibrationFragment method onSave.

/**
 * Save the current calibration point. Its index is saved in {@code mCurrentCalibrationPoint}.
 */
@Override
public void onSave() {
    double x = rootView.getXValue();
    double y = rootView.getYValue();
    if (x == Double.MAX_VALUE || y == Double.MAX_VALUE) {
        return;
    }
    /* Get the calibration points */
    Map map = mMapWeakReference.get();
    if (map == null)
        return;
    List<MapGson.Calibration.CalibrationPoint> calibrationPointList = map.getCalibrationPoints();
    MapGson.Calibration.CalibrationPoint calibrationPoint;
    if (calibrationPointList.size() > mCurrentCalibrationPoint) {
        calibrationPoint = calibrationPointList.get(mCurrentCalibrationPoint);
    } else {
        calibrationPoint = new MapGson.Calibration.CalibrationPoint();
        map.addCalibrationPoint(calibrationPoint);
    }
    Projection projection = map.getProjection();
    if (rootView.isWgs84() && projection != null) {
        double[] projectedValues = projection.doProjection(y, x);
        if (projectedValues != null) {
            calibrationPoint.proj_x = projectedValues[0];
            calibrationPoint.proj_y = projectedValues[1];
        } else {
            displayErrorMessage(R.string.projected_instead_of_wgs84);
            return;
        }
    } else {
        /* If no projection is defined or no mistake is detected, we continue */
        if (projection == null || projection.undoProjection(x, y) != null) {
            calibrationPoint.proj_x = x;
            calibrationPoint.proj_y = y;
        } else {
            /* ..else, show error message and stop */
            displayErrorMessage(R.string.wgs84_instead_of_projected);
            return;
        }
    }
    /* Save relative position */
    calibrationPoint.x = mCalibrationMarker.getRelativeX();
    calibrationPoint.y = mCalibrationMarker.getRelativeY();
    /* Update calibration */
    map.calibrate();
    /* Save */
    MapLoader.getInstance().saveMap(map);
    showSaveConfirmation();
}
Also used : MapGson(com.peterlaurence.trekadvisor.core.map.gson.MapGson) Projection(com.peterlaurence.trekadvisor.core.projection.Projection) Map(com.peterlaurence.trekadvisor.core.map.Map)

Example 2 with Projection

use of com.peterlaurence.trekadvisor.core.projection.Projection in project TrekAdvisor by peterLaurence.

the class MapCalibrationFragment method updateCoordinateFieldsFromData.

private void updateCoordinateFieldsFromData(int calibrationPointNumber) {
    /* Get the calibration points */
    Map map = mMapWeakReference.get();
    if (map == null)
        return;
    List<MapGson.Calibration.CalibrationPoint> calibrationPointList = map.getCalibrationPoints();
    if (calibrationPointList != null && calibrationPointList.size() > calibrationPointNumber) {
        MapGson.Calibration.CalibrationPoint calibrationPoint = calibrationPointList.get(calibrationPointNumber);
        Projection projection = mMapWeakReference.get().getProjection();
        if (rootView.isWgs84() && projection != null) {
            double[] wgs84 = projection.undoProjection(calibrationPoint.proj_x, calibrationPoint.proj_y);
            if (wgs84 != null && wgs84.length == 2) {
                rootView.updateCoordinateFields(wgs84[0], wgs84[1]);
            }
        } else {
            rootView.updateCoordinateFields(calibrationPoint.proj_x, calibrationPoint.proj_y);
        }
    }
}
Also used : MapGson(com.peterlaurence.trekadvisor.core.map.gson.MapGson) Projection(com.peterlaurence.trekadvisor.core.projection.Projection) Map(com.peterlaurence.trekadvisor.core.map.Map)

Example 3 with Projection

use of com.peterlaurence.trekadvisor.core.projection.Projection in project TrekAdvisor by peterLaurence.

the class MapViewFragment method onLocationReceived.

private void onLocationReceived(Location location) {
    if (isHidden())
        return;
    if (location != null) {
        /* If there is no TileView, no need to go further */
        if (mTileView == null) {
            return;
        }
        /* In the case there is no Projection defined, the latitude and longitude are used */
        Projection projection = mMap.getProjection();
        if (projection != null) {
            ProjectionTask projectionTask = new ProjectionTask(this, location.getLatitude(), location.getLongitude(), projection);
            projectionTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        } else {
            updatePosition(location.getLongitude(), location.getLatitude());
        }
        /* If the user wants to see the speed */
        if (mSpeedListener != null) {
            mSpeedListener.onSpeed(location.getSpeed(), SpeedUnit.KM_H);
        }
    }
}
Also used : ProjectionTask(com.peterlaurence.trekadvisor.core.projection.ProjectionTask) Projection(com.peterlaurence.trekadvisor.core.projection.Projection)

Example 4 with Projection

use of com.peterlaurence.trekadvisor.core.projection.Projection in project TrekAdvisor by peterLaurence.

the class MapLoader method mutateMapProjection.

/**
 * Mutate the {@link Projection} of a given {@link Map}.
 *
 * @return true on success, false if something went wrong.
 */
public boolean mutateMapProjection(Map map, String projectionName) {
    Class<? extends Projection> projectionType = PROJECTION_HASH_MAP.get(projectionName);
    try {
        Projection projection = projectionType.newInstance();
        map.setProjection(projection);
    } catch (InstantiationException | IllegalAccessException e) {
        // wrong projection name
        return false;
    }
    return true;
}
Also used : MercatorProjection(com.peterlaurence.trekadvisor.core.projection.MercatorProjection) Projection(com.peterlaurence.trekadvisor.core.projection.Projection)

Example 5 with Projection

use of com.peterlaurence.trekadvisor.core.projection.Projection in project TrekAdvisor by peterLaurence.

the class MapCalibrationFragment method onWgs84modeChanged.

@Override
public void onWgs84modeChanged(boolean isWgs84) {
    Projection projection = mMapWeakReference.get().getProjection();
    if (projection == null)
        return;
    double x = rootView.getXValue();
    double y = rootView.getYValue();
    if (isWgs84) {
        double[] wgs84 = projection.undoProjection(x, y);
        if (wgs84 != null) {
            rootView.updateCoordinateFields(wgs84[0], wgs84[1]);
        }
    } else {
        double[] projectedValues = projection.doProjection(y, x);
        if (projectedValues != null) {
            rootView.updateCoordinateFields(projectedValues[0], projectedValues[1]);
        }
    }
}
Also used : Projection(com.peterlaurence.trekadvisor.core.projection.Projection)

Aggregations

Projection (com.peterlaurence.trekadvisor.core.projection.Projection)5 Map (com.peterlaurence.trekadvisor.core.map.Map)2 MapGson (com.peterlaurence.trekadvisor.core.map.gson.MapGson)2 MercatorProjection (com.peterlaurence.trekadvisor.core.projection.MercatorProjection)1 ProjectionTask (com.peterlaurence.trekadvisor.core.projection.ProjectionTask)1