1 (edited by danielesuppo 2019-08-10 17:09:22)

Topic: Problem when zooming and panning the map at the same time

if I zoom the map with a Lerp let's say from 10 to 14, and at the same time I move in the same Lerp the map (just a couple of Km) the Latitude and Longitude go crazy...
Just lerping the zoom, or the pan, is ok.

This is my code

while (Time.time - tm <= time)
            float t = (Time.time - tm) / time;
            ///Get end tile map position
            OnlineMapsVector2d endPos = GetTilePosition(placeholder);

            ///Lerp final position
            OnlineMapsVector2d pos = OnlineMapsVector2d.Lerp(initPos, endPos, t);
            OnlineMaps.instance.SetTilePosition(pos.x, pos.y);

            ///If the actual map zoom level is less than the
            ///default zoom level, zoom in the map
                if (OnlineMaps.instance.floatZoom < defaultMapZoom)
                     OnlineMaps.instance.floatZoom = Mathf.Lerp(OnlineMaps.instance.floatZoom, GameManager.defaultMapZoom, t);
            yield return null;

private OnlineMapsVector2d GetTilePosition(Transform target)
        OnlineMapsVector2d pos = new OnlineMapsVector2d();
        if (OnlineMapsTileSetControl.instance.GetCoordsByWorldPosition
            (out double lon, out double lat, target.position))
                (lon, lat, OnlineMaps.instance.zoom, out double endPosX, out double endPosY);

            pos.x = endPosX;
            pos.y = endPosY;
        return pos;

2 (edited by danielesuppo 2019-08-10 18:16:54)

Re: Problem when zooming and panning the map at the same time

I've made a test using "OnlineMaps.instance.SetPosition", instead of "OnlineMaps.instance.SetTilePosition", and it work correctly with the map movement and map zoom.

Some post ago you wrote me that the best approach to move the map is SetTilePosition, but in this case it does not seem to work so well.

So, what should I use?
Many thanks!

Re: Problem when zooming and panning the map at the same time


Why in this case the map goes crazy:
SetTilePosition uses the current zoom unless you specify which zoom to use.
When the integer zoom increases (decreases), the number of tiles horizontally and vertically doubles, and your tile position is not where you expect it to be.

To avoid this, SetTilePosition can take a third parameter - zoom, which you should use in this case.
Something like:

OnlineMaps.instance.SetTilePosition(pos.x, pos.y, (int)GameManager.defaultMapZoom);

// ...

private OnlineMapsVector2d GetTilePosition(Transform target)
// ...
    OnlineMaps.instance.projection.CoordinatesToTile (lon, lat, (int)GameManager.defaultMapZoom, out double endPosX, out double endPosY);
// ...

// The same goes for initPos.

I did not write about SetTilePosition.
I wrote that for animation of movement it is better to use a tile position.
Will you use SetTilePosition or projection.TileToCoordinates + SetPosition, it doesn't matter.

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!