use of com.peterlaurence.trekadvisor.menu.mapcalibration.components.CalibrationMarker 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();
}
}
use of com.peterlaurence.trekadvisor.menu.mapcalibration.components.CalibrationMarker in project TrekAdvisor by peterLaurence.
the class MapCalibrationFragment method moveCalibrationMarker.
/**
* Before telling the {@link TileView} to move a marker, we save its relative coordinates so we
* can use them later on calibration save.
*/
private static void moveCalibrationMarker(TileView tileView, View view, double x, double y) {
CalibrationMarker calibrationMarker = (CalibrationMarker) view;
calibrationMarker.setRelativeX(x);
calibrationMarker.setRelativeY(y);
tileView.moveMarker(view, x, y);
}
Aggregations