Search in sources :

Example 1 with TileView

use of com.qozix.tileview.TileView in project TrekAdvisor by peterLaurence.

the class MarkerLayer method attachMarkerGrab.

/**
 * A {@link MarkerGrab} is used along with a {@link MarkerTouchMoveListener} to reflect its
 * displacement to the marker passed as argument.
 */
private static void attachMarkerGrab(final MovableMarker movableMarker, TileView tileView, Map map, Context context) {
    /* Add a view as background, to move easily the marker */
    MarkerTouchMoveListener.MarkerMoveCallback markerMoveCallback = new MarkerTouchMoveListener.MarkerMoveCallback() {

        @Override
        public void onMarkerMove(TileView tileView, View view, double x, double y) {
            tileView.moveMarker(view, x, y);
            tileView.moveMarker(movableMarker, x, y);
            movableMarker.setRelativeX(x);
            movableMarker.setRelativeY(y);
        }
    };
    MarkerGrab markerGrab = new MarkerGrab(context);
    MarkerTouchMoveListener.MarkerClickCallback markerClickCallback = new MovableMarkerClickCallback(movableMarker, markerGrab, tileView, map);
    markerGrab.setOnTouchListener(new MarkerTouchMoveListener(tileView, markerMoveCallback, markerClickCallback));
    tileView.addMarker(markerGrab, movableMarker.getRelativeX(), movableMarker.getRelativeY(), -0.5f, -0.5f);
    markerGrab.morphIn();
}
Also used : MarkerGrab(com.peterlaurence.trekadvisor.menu.mapview.components.MarkerGrab) TileView(com.qozix.tileview.TileView) TileView(com.qozix.tileview.TileView) View(android.view.View) MarkerTouchMoveListener(com.peterlaurence.trekadvisor.menu.tools.MarkerTouchMoveListener)

Example 2 with TileView

use of com.qozix.tileview.TileView in project TrekAdvisor by peterLaurence.

the class MapCalibrationFragment method setMap.

/**
 * Sets the map to generate a new {@link TileView}.
 *
 * @param map The new {@link Map} object
 */
public void setMap(Map map) {
    /* Keep a weakRef for future references */
    mMapWeakReference = new WeakReference<>(map);
    TileView tileView = new TileView(this.getContext());
    /* Set the size of the view in px at scale 1 */
    tileView.setSize(map.getWidthPx(), map.getHeightPx());
    /* Lowest scale */
    List<MapGson.Level> levelList = map.getLevelList();
    float scale = 1 / (float) Math.pow(2, levelList.size() - 1);
    /* Scale limits */
    tileView.setScaleLimits(scale, 2);
    /* Starting scale */
    tileView.setScale(scale);
    /* DetailLevel definition */
    for (MapGson.Level level : levelList) {
        tileView.addDetailLevel(scale, level.level, level.tile_size.x, level.tile_size.y);
        /* Calculate each level scale for best precision */
        scale = 1 / (float) Math.pow(2, levelList.size() - level.level - 2);
    }
    /* Panning outside of the map is not possible --affects minimum scale */
    tileView.setShouldScaleToFit(true);
    /* Disable animations. As of 03/2016, it leads to performance drops */
    tileView.setTransitionsEnabled(false);
    /* Render while panning */
    tileView.setShouldRenderWhilePanning(true);
    /* Map calibration */
    tileView.defineBounds(0, 0, 1, 1);
    /* The calibration marker */
    mCalibrationMarker = new CalibrationMarker(this.getContext());
    MarkerTouchMoveListener.MarkerMoveCallback callback = new CalibrationMarkerMoveCallback();
    mCalibrationMarker.setOnTouchListener(new MarkerTouchMoveListener(tileView, callback));
    tileView.addMarker(mCalibrationMarker, 0.5, 0.5, -0.5f, -0.5f);
    /* The BitmapProvider */
    tileView.setBitmapProvider(map.getBitmapProvider());
    /* Add the TileView to the root view */
    setTileView(tileView);
    /* Update the ui */
    rootView.setup();
    /* Check whether the Map has defined a projection */
    if (map.getProjection() == null) {
        rootView.noProjectionDefined();
    } else {
        rootView.projectionDefined();
    }
}
Also used : MapGson(com.peterlaurence.trekadvisor.core.map.gson.MapGson) TileView(com.qozix.tileview.TileView) CalibrationMarker(com.peterlaurence.trekadvisor.menu.mapcalibration.components.CalibrationMarker) MarkerTouchMoveListener(com.peterlaurence.trekadvisor.menu.tools.MarkerTouchMoveListener)

Example 3 with TileView

use of com.qozix.tileview.TileView in project TrekAdvisor by peterLaurence.

the class DistanceLayer method show.

/**
 * Shows the two {@link DistanceMarker} and the {@link DistanceView}.<br>
 * {@link #init(Map, TileViewExtended)} must have been called before.
 */
public void show() {
    /* Create the DistanceView (the line between the two markers) */
    mDistanceView = new DistanceView(mContext, mTileView.getScale());
    mTileView.addScaleChangeListener(mDistanceView);
    mTileView.addView(mDistanceView);
    /* Setup the first marker */
    mDistanceMarkerFirst = new DistanceMarker(mContext);
    MarkerTouchMoveListener.MarkerMoveCallback firstMarkerMoveCallback = new MarkerTouchMoveListener.MarkerMoveCallback() {

        @Override
        public void onMarkerMove(TileView tileView, View view, double x, double y) {
            mFirstMarkerRelativeX = x;
            mFirstMarkerRelativeY = y;
            tileView.moveMarker(mDistanceMarkerFirst, x, y);
            onMarkerMoved();
        }
    };
    MarkerTouchMoveListener firstMarkerTouchMoveListener = new MarkerTouchMoveListener(mTileView, firstMarkerMoveCallback);
    mDistanceMarkerFirst.setOnTouchListener(firstMarkerTouchMoveListener);
    /* Setup the second marker*/
    mDistanceMarkerSecond = new DistanceMarker(mContext);
    MarkerTouchMoveListener.MarkerMoveCallback secondMarkerMoveCallback = new MarkerTouchMoveListener.MarkerMoveCallback() {

        @Override
        public void onMarkerMove(TileView tileView, View view, double x, double y) {
            mSecondMarkerRelativeX = x;
            mSecondMarkerRelativeY = y;
            tileView.moveMarker(mDistanceMarkerSecond, x, y);
            onMarkerMoved();
        }
    };
    MarkerTouchMoveListener secondMarkerTouchMoveListener = new MarkerTouchMoveListener(mTileView, secondMarkerMoveCallback);
    mDistanceMarkerSecond.setOnTouchListener(secondMarkerTouchMoveListener);
    /* Set their positions */
    initDistanceMarkers();
    onMarkerMoved();
    /* ..and add them to the TileView */
    mTileView.addMarker(mDistanceMarkerFirst, mFirstMarkerRelativeX, mFirstMarkerRelativeY, -0.5f, -0.5f);
    mTileView.addMarker(mDistanceMarkerSecond, mSecondMarkerRelativeX, mSecondMarkerRelativeY, -0.5f, -0.5f);
    mVisible = true;
    /* Start the thread that will process distance calculations */
    prepareDistanceCalculation();
}
Also used : DistanceMarker(com.peterlaurence.trekadvisor.menu.mapview.components.DistanceMarker) TileView(com.qozix.tileview.TileView) DistanceView(com.peterlaurence.trekadvisor.menu.mapview.components.DistanceView) TileView(com.qozix.tileview.TileView) View(android.view.View) DistanceView(com.peterlaurence.trekadvisor.menu.mapview.components.DistanceView) MarkerTouchMoveListener(com.peterlaurence.trekadvisor.menu.tools.MarkerTouchMoveListener)

Example 4 with TileView

use of com.qozix.tileview.TileView in project TrekAdvisor by peterLaurence.

the class MarkerLayer method setTileView.

private void setTileView(final TileView tileView) {
    mTileView = tileView;
    mTileView.setMarkerTapListener(new MarkerLayout.MarkerTapListener() {

        @Override
        public void onMarkerTap(View view, int x, int y) {
            if (view instanceof MovableMarker) {
                MovableMarker movableMarker = (MovableMarker) view;
                /* Prepare the callout */
                MarkerCallout markerCallout = new MarkerCallout(mContext);
                markerCallout.setMoveAction(new MorphMarkerRunnable(movableMarker, markerCallout, mTileView, mContext, mMap));
                markerCallout.setEditAction(new EditMarkerRunnable(movableMarker, MarkerLayer.this, markerCallout, mTileView, mRequestManageMarkerListener));
                markerCallout.setDeleteAction(new DeleteMarkerRunnable(mParentView, movableMarker, markerCallout, tileView, mMap));
                MarkerGson.Marker marker = movableMarker.getMarker();
                markerCallout.setTitle(marker.name);
                markerCallout.setSubTitle(marker.lat, marker.lon);
                mTileView.addCallout(markerCallout, movableMarker.getRelativeX(), movableMarker.getRelativeY(), -0.5f, -1.2f);
                markerCallout.transitionIn();
            }
        }
    });
}
Also used : MarkerCallout(com.peterlaurence.trekadvisor.menu.mapview.components.MarkerCallout) MarkerLayout(com.qozix.tileview.markers.MarkerLayout) MovableMarker(com.peterlaurence.trekadvisor.menu.mapview.components.MovableMarker) TileView(com.qozix.tileview.TileView) View(android.view.View) MovableMarker(com.peterlaurence.trekadvisor.menu.mapview.components.MovableMarker)

Aggregations

TileView (com.qozix.tileview.TileView)4 View (android.view.View)3 MarkerTouchMoveListener (com.peterlaurence.trekadvisor.menu.tools.MarkerTouchMoveListener)3 MapGson (com.peterlaurence.trekadvisor.core.map.gson.MapGson)1 CalibrationMarker (com.peterlaurence.trekadvisor.menu.mapcalibration.components.CalibrationMarker)1 DistanceMarker (com.peterlaurence.trekadvisor.menu.mapview.components.DistanceMarker)1 DistanceView (com.peterlaurence.trekadvisor.menu.mapview.components.DistanceView)1 MarkerCallout (com.peterlaurence.trekadvisor.menu.mapview.components.MarkerCallout)1 MarkerGrab (com.peterlaurence.trekadvisor.menu.mapview.components.MarkerGrab)1 MovableMarker (com.peterlaurence.trekadvisor.menu.mapview.components.MovableMarker)1 MarkerLayout (com.qozix.tileview.markers.MarkerLayout)1