Topic: Disable user drag control (keep zoom control)

Hi,

We need to disable user drag control but keeping user zoom control. We want to display some markers around the user current location avoiding that user move outside of a radius (keeping center of map)

Is it possible? We only find the "Allow user control option", but it disable drag and zoom controls.

thanks,

Re: Disable user drag control (keep zoom control)

Hello.

Unfortunately, there is no built-in way to do this.
But there is a little trick, how to cancel the map drag.

Post's attachments

Attachment icon LockPositionExample2.cs 575 b, 384 downloads since 2016-04-06 

Kind Regards,
Infinity Code Team.

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

Re: Disable user drag control (keep zoom control)

Hi Alex,

Works perfect!

A last question, Is there way to get and change "zoom mode" for OnlineMapsUIImageControl?, since I am not working with tiles set and OnlineMapsUIImageControl object does not have a smoothZoomMode attribute to change its value to "center".

thanks and regards.

Re: Disable user drag control (keep zoom control)

In the current version there is no such field.
Nobody asked about this before.
We will add this field in the next version.
I think this is useful in some cases.

You can work around this in the following way:

public class LockPositionExample2 : MonoBehaviour 
{
    private Vector2 originalPosition;

    private void Start () 
    {
        OnlineMapsControlBase.instance.OnMapPress += OnMapPress;
        OnlineMapsControlBase.instance.OnMapRelease += OnMapRelease;
    }

    private void OnChangePosition()
    {
        OnlineMaps.instance.dispatchEvents = false;
        OnlineMaps.instance.position = originalPosition;
        OnlineMaps.instance.dispatchEvents = true;
    }

    private void OnMapPress()
    {
        originalPosition = OnlineMaps.instance.position;
        OnlineMaps.instance.OnUpdateBefore += OnUpdateBefore;
        OnlineMaps.instance.OnChangePosition += OnChangePosition;
    }

    private void OnMapRelease()
    {
        OnlineMaps.instance.OnChangePosition -= OnChangePosition;
    }

    private void OnUpdateBefore()
    {
        OnlineMapsControlBase.instance.isMapDrag = false;
        OnlineMaps.instance.OnUpdateBefore -= OnUpdateBefore;
    }
}
Kind Regards,
Infinity Code Team.

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

5 (edited by dgonzalez 2016-04-06 22:25:51)

Re: Disable user drag control (keep zoom control)

Hi,

Thanks for your help and time.

I resolve last question by follow:

private Vector2 mapCenter;

    void Start()
    {
        
       
        OnlineMapsLocationService.instance.OnLocationChanged += OnLocationChanged;
        OnlineMapsControlBase.instance.OnMapPress += OnMapPress;
        OnlineMapsControlBase.instance.OnMapZoom += OnMapZoom;
    }

    private void OnLocationChanged(Vector2 position)
   {
        mapCenter = position;
   }

   private void OnMapPress()
  {
        OnlineMaps.instance.OnUpdateBefore += OnUpdateBefore;
  }

  private void OnUpdateBefore()
  {
        OnlineMapsControlBase.instance.isMapDrag = false;
        OnlineMaps.instance.OnUpdateBefore -= OnUpdateBefore;
  }

  private void OnMapZoom()
  {
        OnlineMaps.instance.position = mapCenter;
  }

regards,

Re: Disable user drag control (keep zoom control)

@Alex,
Have you provided this feature in recent updates?
or should i use the code you wrote?

Re: Disable user drag control (keep zoom control)

Hello.

No, this feature has not yet been implemented.
Use the examples above.

Kind Regards,
Infinity Code Team.

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