Hey... I tried your example with no success...
I'm trying to smoothly zoom into a certain location while the map moves using a tween that updates the values ("ATween.FloatTo"). I've spent the whole afternoon on this and did not work... My last try was using this:
public void FocusUserLocation(bool p_tweenEnabled, int p_zoomLevel = 16, float p_duration = 0.5f, ATweenEase p_easeType = ATweenEase.CUBIC_IN_OUT, Action p_callback = null)
{
Vector2 __userLocation = RetrieveGPSData();
if (p_tweenEnabled)
{
if (focusTweenNodule == null)
{
Vector2 __mapPosition;
double __lng = 0.0;
double __lat = 0.0;
Vector2 localPoint;
RectTransform rectTransform = GameObject.FindWithTag("NavigateScreen").GetComponent<RectTransform>();
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Input.mousePosition,
Camera.main, out localPoint);
Rect mapRect = rectTransform.rect;
Vector2 defPivot = rectTransform.pivot;
Vector2 defSize = rectTransform.sizeDelta;
Vector2 defPosition = rectTransform.anchoredPosition;
Vector2 initialPosition = __userLocation;
Vector2 pivot = new Vector2();
float ox = localPoint.x + mapRect.width * defPivot.x;
float oy = localPoint.y + mapRect.height * defPivot.y;
pivot.x = ox / mapRect.width;
pivot.y = oy / mapRect.height;
float initialDistance = (GetMapLocation() - __userLocation).magnitude;
Vector2 offsetMax = rectTransform.offsetMax;
Vector2 offsetMin = rectTransform.offsetMin;
rectTransform.pivot = pivot;
rectTransform.offsetMax = offsetMax;
rectTransform.offsetMin = offsetMin;
_isUserLocationFocusActive = true;
onlineMaps.GetPosition(out __lng, out __lat);
__mapPosition = new Vector2((float)__lng, (float)__lat);
focusTweenNodule = ATween.Vector2To(__mapPosition, __userLocation, p_duration, p_easeType, delegate(Vector2 p_updatePosition)
{
float distance = (p_updatePosition - __userLocation).magnitude;
float a = distance / initialDistance;
onlineMaps.transform.localScale = new Vector3(a, a, a);
FocusLocation(p_updatePosition.x, p_updatePosition.y);
});
focusTweenNodule.onFinished += delegate
{
if (p_callback != null)
p_callback();
onlineMaps.transform.localScale = Vector3.one;
onlineMaps.zoom = p_zoomLevel;
focusTweenNodule = null;
_isUserLocationFocusActive = false;
};
}
}
else
{
FocusLocation(__userLocation.x, __userLocation.y);
onlineMaps.zoom = p_zoomLevel;
if (p_callback != null)
p_callback();
}
}
public void FocusLocation(float p_longitude, float p_latidude)
{
OnlineMaps.instance.SetPosition((double)p_longitude, (double)p_latidude);
}
I didn't get what RectTransform I have to use, because the map is not in a canvas. In this code I used a RectTransform from an object ("NavigateScreen") that is in a canvas, but it's not the map's object itself.
Please, I need a light on this