1 (edited by Sangrene 2018-02-19 15:56:24)

Topic: Scale markers on smooth zoom

Hi everyone,

I recently added  a custom tileset control script that Alex put in a precedent topic, which allows the zoom to be kind of smooth on mobile when using two fingers (just like the next verson will be with float zoom range). Unfortunately I can't manage to scale markers inversely to the zoom level and I would be glad if anyone share what function to use.

Here is my custom tileset control with the ComputePinSizes the function to scale markers, being called at every small zoom from the user.

EDIT : Also, I have a strange shift at the end of the zoom that I didn't manage to solve, it seems that it is not related to the code of my custom TilesetControl.

Post's attachments

Attachment icon CustomTileSetControlMarkerZoom.cs 5.84 kb, 108 downloads since 2018-02-19 

Re: Scale markers on smooth zoom

Hello.

private void ComputePinSizes (float scale)
{
    float inverseScale = 1 / scale;
    for (int i = 0; i < OnlineMaps.instance.markers.Length; i++)
    {
        OnlineMaps.instance.markers[i].scale = inverseScale;
    }
    OnlineMaps.instance.Redraw();
}

When I tested, I did not see a shift.
Please send the video what kind of shift you mean.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Scale markers on smooth zoom

Hi Alex,

Thanks for this. Here is the link to the video when you can see the shift and the scale problem :

https://drive.google.com/open?id=1ojOF3 … UeFw1woFyU

As you can see, when I click on a marker I scale it from 0.5 to 0.70, but by setting the markers scale to a constant value and not multiplying the previous scale I don't keep the last clicked marker on a higher scale than the others. I could store a click boolean in the marker tags and scale it accordingly but is there another cleaner way to achieve this ?

Thanks !

Re: Scale markers on smooth zoom

Thank you for the video. It really helped to understand what was happening.
Try to replace:

else
{
    if (smoothZoomStarted)
    {
        lastGestureDistance = 0;
        Vector2 center = new Vector2 (Screen.width / 2, Screen.height / 2);
        double ox, oy;
        if (transform.localScale.x < 0.9)
        {
            ZoomOnPoint(1, center);
            transform.localScale *= 2;
        }
        if (GetCoords (out ox, out oy, center))
        {
            map.SetPosition (ox, oy);
            float scaleDifference = m_originalScale.x - transform.localScale.x;
            transform.localPosition = m_originalPosition + new Vector3 (map.tilesetSize.x / -2, 0, map.tilesetSize.y / 2) * scaleDifference;
        }
        ComputePinSizes (transform.localScale.x);
        needRestoreZoom = 3;
    }
    smoothZoomStarted = false;
}

to:

else
{
    if (smoothZoomStarted)
    {
        lastGestureDistance = 0;
        needRestoreZoom = 3;
    }
    smoothZoomStarted = false;
}

We have at least two ways to scale the active marker:
1. In ComputePinSizes, check that the current marker is active, and multiply it scale by your ratio.
2. Keep the original marker.scale in marker.customData, and in ComputePinSizes multiply inverseScale by the value from marker.customData.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Scale markers on smooth zoom

Thanks Alex !

I was totally looking at another part of the code... The problem was when the 2nd finger was raised right ?
I'll try the 1st idea, it was my first thing to try smile

Still the best support among all the Unity assets !

Re: Scale markers on smooth zoom

Yes, the video shows that the shift occurs at the end of the zoom.
This is the part of the code that I changed.

The problem did not appear on my devices, so I can not be 100% sure.
Only you know it helped or not.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Scale markers on smooth zoom

I managed to solve both of my problems ! Thanks a lot Alex smile