Search in sources :

Example 1 with CoordinateTranslater

use of com.qozix.tileview.geom.CoordinateTranslater in project TrekAdvisor by peterLaurence.

the class DistanceLayer method initDistanceMarkers.

private void initDistanceMarkers() {
    /* Calculate the relative coordinates of the first marker */
    int x = mTileView.getScrollX() + (int) (mTileView.getWidth() * 0.66f) - mTileView.getOffsetX();
    int y = mTileView.getScrollY() + (int) (mTileView.getHeight() * 0.33f) - mTileView.getOffsetY();
    CoordinateTranslater coordinateTranslater = mTileView.getCoordinateTranslater();
    double relativeX = coordinateTranslater.translateAndScaleAbsoluteToRelativeX(x, mTileView.getScale());
    double relativeY = coordinateTranslater.translateAndScaleAbsoluteToRelativeY(y, mTileView.getScale());
    mFirstMarkerRelativeX = Math.min(relativeX, coordinateTranslater.getRight());
    mFirstMarkerRelativeY = Math.min(relativeY, coordinateTranslater.getTop());
    /* Calculate the relative coordinates of the second marker */
    x = mTileView.getScrollX() + (int) (mTileView.getWidth() * 0.33f) - mTileView.getOffsetX();
    y = mTileView.getScrollY() + (int) (mTileView.getHeight() * 0.66f) - mTileView.getOffsetY();
    relativeX = coordinateTranslater.translateAndScaleAbsoluteToRelativeX(x, mTileView.getScale());
    relativeY = coordinateTranslater.translateAndScaleAbsoluteToRelativeY(y, mTileView.getScale());
    mSecondMarkerRelativeX = Math.max(relativeX, coordinateTranslater.getLeft());
    mSecondMarkerRelativeY = Math.max(relativeY, coordinateTranslater.getBottom());
}
Also used : CoordinateTranslater(com.qozix.tileview.geom.CoordinateTranslater)

Example 2 with CoordinateTranslater

use of com.qozix.tileview.geom.CoordinateTranslater in project TrekAdvisor by peterLaurence.

the class DistanceLayer method onMarkerMoved.

private void onMarkerMoved() {
    /* Update the ui */
    CoordinateTranslater translater = mTileView.getCoordinateTranslater();
    mDistanceView.updateLine((float) translater.translateX(mFirstMarkerRelativeX), (float) translater.translateY(mFirstMarkerRelativeY), (float) translater.translateX(mSecondMarkerRelativeX), (float) translater.translateY(mSecondMarkerRelativeY));
    /* Schedule distance calculation */
    if (mHandler != null) {
        mHandler.submit(mFirstMarkerRelativeX, mFirstMarkerRelativeY, mSecondMarkerRelativeX, mSecondMarkerRelativeY);
    }
}
Also used : CoordinateTranslater(com.qozix.tileview.geom.CoordinateTranslater)

Example 3 with CoordinateTranslater

use of com.qozix.tileview.geom.CoordinateTranslater in project TrekAdvisor by peterLaurence.

the class MapViewFragment method updateMapIfNecessary.

/**
 * Only update the map if its a new one. <br>
 * Once the map is updated, a {@link TileViewExtended} instance is created, so layers can be
 * updated.
 */
private void updateMapIfNecessary() {
    Map map = mMapProvider.getCurrentMap();
    if (map != null) {
        if (mMap != null && mMap.equals(map)) {
            Map.MapBounds newBounds = map.getMapBounds();
            if (mTileView != null) {
                CoordinateTranslater c = mTileView.getCoordinateTranslater();
                if (newBounds != null && !newBounds.compareTo(c.getLeft(), c.getTop(), c.getRight(), c.getBottom())) {
                    setTileViewBounds(mTileView, map);
                }
            }
        } else {
            setMap(map);
            updateLayers();
        }
    }
}
Also used : CoordinateTranslater(com.qozix.tileview.geom.CoordinateTranslater) Map(com.peterlaurence.trekadvisor.core.map.Map)

Example 4 with CoordinateTranslater

use of com.qozix.tileview.geom.CoordinateTranslater in project TrekAdvisor by peterLaurence.

the class MarkerLayer method addNewMarker.

/**
 * Add a {@link MovableMarker} to the center of the {@link TileView}.
 */
void addNewMarker() {
    /* Calculate the relative coordinates of the center of the screen */
    int x = mTileView.getScrollX() + mTileView.getWidth() / 2 - mTileView.getOffsetX();
    int y = mTileView.getScrollY() + mTileView.getHeight() / 2 - mTileView.getOffsetY();
    CoordinateTranslater coordinateTranslater = mTileView.getCoordinateTranslater();
    final double relativeX = coordinateTranslater.translateAndScaleAbsoluteToRelativeX(x, mTileView.getScale());
    final double relativeY = coordinateTranslater.translateAndScaleAbsoluteToRelativeY(y, mTileView.getScale());
    final MovableMarker movableMarker;
    /* Create a new marker and add it to the map */
    MarkerGson.Marker newMarker = new MarkerGson.Marker();
    if (mMap.getProjection() == null) {
        newMarker.lat = relativeY;
        newMarker.lon = relativeX;
    } else {
        newMarker.proj_x = relativeX;
        newMarker.proj_y = relativeY;
        double[] wgs84Coords;
        wgs84Coords = mMap.getProjection().undoProjection(relativeX, relativeY);
        if (wgs84Coords != null) {
            newMarker.lon = wgs84Coords[0];
            newMarker.lat = wgs84Coords[1];
        }
    }
    /* Create the corresponding view */
    movableMarker = new MovableMarker(mContext, false, newMarker);
    movableMarker.setRelativeX(relativeX);
    movableMarker.setRelativeY(relativeY);
    movableMarker.initRounded();
    if (mMap != null) {
        mMap.addMarker(newMarker);
    }
    /* Easily move the marker */
    attachMarkerGrab(movableMarker, mTileView, mMap, mContext);
    mTileView.addMarker(movableMarker, relativeX, relativeY, -0.5f, -0.5f);
}
Also used : MarkerGson(com.peterlaurence.trekadvisor.core.map.gson.MarkerGson) CoordinateTranslater(com.qozix.tileview.geom.CoordinateTranslater) MovableMarker(com.peterlaurence.trekadvisor.menu.mapview.components.MovableMarker) MovableMarker(com.peterlaurence.trekadvisor.menu.mapview.components.MovableMarker)

Aggregations

CoordinateTranslater (com.qozix.tileview.geom.CoordinateTranslater)4 Map (com.peterlaurence.trekadvisor.core.map.Map)1 MarkerGson (com.peterlaurence.trekadvisor.core.map.gson.MarkerGson)1 MovableMarker (com.peterlaurence.trekadvisor.menu.mapview.components.MovableMarker)1