Topic: Float zoom in online maps beta 3.0.025

I have remade markers system from uGUI example for my needs. All works perfect in the last not beta version. But I need smooth zoom, that is amazing in beta version. So we decided to move our project to the beta version of online maps. And here we have a problem with markers positions on the map when zoom become float, but with int zoom, there is no problem. So when you drag the map in float zoom, markers position's calculation is wrong, and markers don't stay at its positions and moving with the map.
Need help, thanks.

Re: Float zoom in online maps beta 3.0.025

Hello.

This is a bug in OnlineMapsControlBase.GetPosition.
Fixed. The new version will be available soon.

Most likely you do not need this, but in Online Maps v3 there is an opportunity to rewrite marker drawer without creating your own system of markers.
You use the built-in marker engine + your own marker drawer.
Example:

using UnityEngine;

public class uGUIMarkerDrawer:MonoBehaviour
{
    private static uGUIMarkerDrawer instance;
    public RectTransform container;
    public GameObject prefab;

    private Canvas canvas;

    private Camera worldCamera
    {
        get
        {
            if (canvas.renderMode == RenderMode.ScreenSpaceOverlay) return null;
            return canvas.worldCamera;
        }
    }

    private void OnEnable()
    {
        instance = this;
        canvas = container.GetComponentInParent<Canvas>();
    }

    private void Start()
    {
        OnlineMapsControlBase.instance.markerDrawer = new Drawer(OnlineMapsControlBase.instance);
    }

    public class Drawer : OnlineMapsMarker2DDrawer
    {
        private OnlineMapsControlBase control;

        public Drawer(OnlineMapsControlBase control)
        {
            this.control = control;

            control.OnDrawMarkers += OnDrawMarkers;
        }

        public override void Dispose()
        {
            control.OnDrawMarkers -= OnDrawMarkers;
            control = null;
        }

        private void OnDrawMarkers()
        {
            double tlx, tly, brx, bry;
            map.GetCorners(out tlx, out tly, out brx, out bry);

            foreach (OnlineMapsMarker marker in OnlineMapsMarkerManager.instance.items)
            {
                DrawMarker(marker, tlx, tly, brx, bry);
            }
        }

        private void DrawMarker(OnlineMapsMarker marker, double tlx, double tly, double brx, double bry)
        {
            double px, py;
            marker.GetPosition(out px, out py);
            GameObject markerInstance = marker["instance"] as GameObject;

            if (px < tlx || px > brx || py < bry || py > tly)
            {
                if (markerInstance != null)
                {
                    OnlineMapsUtils.Destroy(markerInstance);
                    marker["instance"] = null;
                }
                return;
            }

            if (markerInstance == null)
            {
                marker["instance"] = markerInstance = Instantiate(instance.prefab);
                (markerInstance.transform as RectTransform).SetParent(instance.container);
                markerInstance.transform.localScale = Vector3.one;
            }

            Vector2 screenPosition = control.GetScreenPosition(px, py);
            RectTransform markerRectTransform = markerInstance.transform as RectTransform;

            screenPosition.y += markerRectTransform.rect.height / 2;

            Vector2 point;
            RectTransformUtility.ScreenPointToLocalPointInRectangle(markerRectTransform.parent as RectTransform, screenPosition, instance.worldCamera, out point);
            markerRectTransform.localPosition = point;
        }
    }
}
Kind Regards,
Infinity Code Team

Re: Float zoom in online maps beta 3.0.025

Thanks! New version fixed that problem. And thanks for the suggestion, I think we will try it.

Re: Float zoom in online maps beta 3.0.025

So I worked a bit with float zoom and have some problem with zooming markers. I need the size of the markers depends on map zoom and correlating with its size in the real world(for example, the marker is a circle zone and has radius 17m). So I'm calculating coordinates of two points of the marker like its center and top right corner(marker is sprite render) in unity world coordinate system.  Then I calculating needed scale for the marker, that depends on this coordinates of that 2 points and size of the sprite render.
  I'm using OnlineMapsControlBase.GetScreenPosition function for this. And looks like this function gives me wrong coordinates in some situation. If I use just int zoom or float zoom with step 1 (for example, zoom 17.1, then next zoom 18.1)- all is ok, but in float zoom, with the small step, I have this problem. 
  I tried to zoom marker with the small delay in a coroutine and it helps, but it's not a solution and user could see how marker's scale jump and it looks very bad for the user with this lugs.

Re: Float zoom in online maps beta 3.0.025

Please attach your code.
I'll check it out, and make the necessary changes to Online Maps.

Kind Regards,
Infinity Code Team

Re: Float zoom in online maps beta 3.0.025

Here is your file, that I have modified with OnZoom event.

Post's attachments

Attachment icon MarkerDrawer.cs 6.1 kb, 25 downloads since 2018-05-29 

Re: Float zoom in online maps beta 3.0.025

Unfortunately, I not able to reproduce the problem.
If possible, make a video that demonstrates the problem and show your settings.

In addition, I found a couple of problems in your code:
1. In OnZoom, NullReference exception is possible, because you do not check that markerInstance is not null.
2. DrawMarker. I do not know what you wanted to achieve, but your way of scaling the markers seems to me very strange. With 99% probability this way is wrong.

Kind Regards,
Infinity Code Team

8 (edited by drand 2018-05-29 14:51:52)

Re: Float zoom in online maps beta 3.0.025

It's just debug code to show the problem. Here is a video https://drive.google.com/open?id=1Yx41F … hqcviLCqCs   Black rectangle - area in real size and circle-zone should be inscribed in this rectangle in all zoom level of the map. So when the zoom is float my way of scaling marker doesn't work, but with int zoom - scaling work fine. Circle zone is sprite render. And the map is a tile set.

Re: Float zoom in online maps beta 3.0.025

Alex Vertax wrote:

2. DrawMarker. I do not know what you wanted to achieve, but your way of scaling the markers seems to me very strange. With 99% probability this way is wrong.

If you could suggest the better way I would be very grateful. Thanks!

Re: Float zoom in online maps beta 3.0.025

Perhaps the problem is that you are using OnlineMapsControlBase.OnMapZoom.
This will only be triggered when the user interacts with the map (wheel, double click, pitch to zoom, etc.).
This will not be triggered when the zoom is changed using inspector.
For OnZoom to be triggered with any zoom change, use OnlineMaps.OnChangeZoom.

Changed version of your script is attached.
As you can see, I'm using a different way to scale markers.

P.S. Online Maps has been updated.

Kind Regards,
Infinity Code Team

11 (edited by drand 2018-05-30 12:57:12)

Re: Float zoom in online maps beta 3.0.025

Alex Vertax wrote:

Perhaps the problem is that you are using OnlineMapsControlBase.OnMapZoom.
This will only be triggered when the user interacts with the map (wheel, double click, pitch to zoom, etc.).
This will not be triggered when the zoom is changed using inspector.
For OnZoom to be triggered with any zoom change, use OnlineMaps.OnChangeZoom.

In the project, I'm using OnlineMaps.OnChangeZoom. After plugin update, my variant of scale markers doesn't work correctly at all in the editor, but on android work's fine with float zoom(but with int step zoom - not, I mean if you zoom by double tap).

Alex Vertax wrote:

Changed version of your script is attached.
As you can see, I'm using a different way to scale markers.

Sorry, but I don't see the attached file.

Anyway, thanks for helping!

Re: Float zoom in online maps beta 3.0.025

Sorry, in the previous post I select, but did not add the file.

Post's attachments

Attachment icon MarkerDrawer.cs 4.31 kb, 21 downloads since 2018-05-30 

Kind Regards,
Infinity Code Team