Hi there,
Just wondering if there was any update on the float zoom feature that was mentioned before.
I'm working on a feature that allows a user to click on one of several markers on interest then, ideally, the view should smoothly zoom in until the area around the marker is at closest zoom. Then have the option to reset which will smoothly zoom back out until all the markers are visable.
I managed to get it basically working by only doing any actions on the discrete change over point of the zoom. Here are the relevant functions:
public void MoveToPosition (Vector2 posIn, int targetZoomIn) {
fromPosition = OnlineMaps.instance.position;
startZoom = OnlineMaps.instance.zoom;
zoomIn = targetZoomIn > startZoom;
time = timePerZoom * Mathf.Abs (targetZoomIn - startZoom);
targetZoom = targetZoomIn;
toPosition = posIn;
angle = 0;
isMovement = true;
}
void runMovement ()
{
angle += Time.deltaTime / time;
if (angle > 1) {
isMovement = false;
OnlineMaps.instance.zoom = targetZoom;
OnlineMaps.instance.SetPosition (toPosition.x, toPosition.y);
return;
}
int currentZoom = Mathf.RoundToInt (Mathf.Lerp (startZoom, targetZoom, angle));
if (OnlineMaps.instance.zoom != currentZoom) {
if (zoomIn) {
OnlineMapsControlBase.instance.ZoomOnPoint (currentZoom - OnlineMaps.instance.zoom,
OnlineMapsControlBase.instance.GetScreenPosition (toPosition));
Vector2 CenterScreen = OnlineMapsControlBase.instance.GetCoords (new Vector2 (Screen.width / 2, Screen.height / 2));
Vector2 pos = Vector2.Lerp (CenterScreen, toPosition, angle);
OnlineMaps.instance.SetPosition (pos.x, pos.y);
} else {
int zoomsLeft = currentZoom - targetZoom;
OnlineMapsControlBase.instance.ZoomOnPoint (currentZoom - OnlineMaps.instance.zoom,
OnlineMapsControlBase.instance.GetScreenPosition (fromPosition));
Vector2 pos = Vector2.Lerp (fromPosition, toPosition, Mathf.Pow(0.5f,zoomsLeft));
OnlineMaps.instance.SetPosition (pos.x, pos.y);
}
}
}
public void ZoomToCenterOfMarkers ()
{
Vector2 center;
int zoom;
OnlineMapsUtils.GetCenterPointAndZoom (OnlineMaps.instance.markers, out center, out zoom);
MoveToPosition (center, zoom + 1); // Unsure why but the view is better at plus one zoom
}
Do you have any advice on how to make this smoother? I tried to adapt the smooth zoom feature (which I realise is designed for touch input) but it didn't perform well over large zoom amounts (starting with whole world and zooming in to a point of interest like the start of google earth).
Thanks