Topic: Smooth Zoom mode without scaling map object
Hello
Is there anyway to use smooth zoom mode (OnlineMapsTileSetControl) without scaling map object?
Thank you and best regards.
You are not logged in. Please login or register.
Infinity Code Forum → Online Maps Help → Smooth Zoom mode without scaling map object
Hello
Is there anyway to use smooth zoom mode (OnlineMapsTileSetControl) without scaling map object?
Thank you and best regards.
Hello.
Online Maps does not have such built-in feature.
But you can implement this by using camera position, camera fov (perspective), or camera size (orthographic).
Thank you for your reply.
Could you kindly show me the sample code to do this?
Hello.
Example of smooth zoom using FOV:
using UnityEngine;
public class SmoothZoomCameraFOV : MonoBehaviour
{
private OnlineMaps map;
private OnlineMapsTileSetControl control;
private Camera activeCamera;
private bool zoomStarted;
private float lastGestureDistance;
private float fov;
private float minFOV;
private float doubleFOV;
private void Start()
{
map = OnlineMaps.instance;
control = OnlineMapsTileSetControl.instance;
activeCamera = control.activeCamera;
control.allowZoom = false;
fov = activeCamera.fieldOfView;
minFOV = fov * 0.3f;
doubleFOV = fov * 1.2f;
}
private void Update()
{
if (Input.touchCount == 2)
{
Vector2 p1 = Input.GetTouch(0).position;
Vector2 p2 = Input.GetTouch(1).position;
float distance = (p1 - p2).magnitude;
if (!zoomStarted)
{
zoomStarted = true;
}
else
{
float scale = 1;
if (Mathf.Abs(distance - lastGestureDistance) > 2) scale = distance / lastGestureDistance;
fov /= scale;
if (fov < minFOV)
{
fov *= 2;
map.zoom++;
}
else if (fov > doubleFOV)
{
fov /= 2;
map.zoom--;
}
activeCamera.fieldOfView = fov;
}
lastGestureDistance = distance;
}
else
{
if (zoomStarted)
{
zoomStarted = false;
lastGestureDistance = 0;
}
}
}
}Infinity Code Forum → Online Maps Help → Smooth Zoom mode without scaling map object
Powered by PunBB, supported by Informer Technologies, Inc.