Topic: Center map at specific screen point

Hello there!

SetPositionAndZoom() centers a location. Is it possible to center it at a custom screen point?
Something like
SetPositionAndZoomToScreenPoint( double lng, double lat, float? zoom, Vector2 screenPoint ){...}

Problem in our application is, that the target point is not the center of the map (see image).
Any way to achieve this? smile

Best,
Martin

Post's attachments

Attachment icon OnlineMapsIssue.png 769.47 kb, 51 downloads since 2019-03-25 

Re: Center map at specific screen point

Hello.

Convert the screen position into geographic coordinates using OnlineMapsControlBase.GetCoords, and set these coordinates to a map.
http://infinity-code.com/doxygen/online … d0a0d3ee6f

Kind Regards,
Infinity Code Team.

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

Re: Center map at specific screen point

Alex Vertax wrote:

... and set these coordinates to a map.

That's the point I don't know how to achieve. big_smile

Re: Center map at specific screen point

OnlineMaps.SetPosition or OnlineMaps.SetPositionAndZoom.
http://infinity-code.com/doxygen/online … e65d01d9b7

Kind Regards,
Infinity Code Team.

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

Re: Center map at specific screen point

Okay, that answer wasn't really helpful, but I figured out how to do it. I had to calculate the offset between the marker and the screen point, then position the map accordingly.

In case someone else needs this:

public void CenterMapAtScreenPoint(Vector2 markerCoordinates, Vector3 _positionOfScreenPoint, float? _zoom = null)
    {
        // center the marker
        OnlineMaps.instance.SetPositionAndZoom(markerCoordinates.x, markerCoordinates.y, _zoom);

        // get coordinates of the ScreenPoint
        Vector2 screenPointCoordinates = OnlineMapsControlBase.instance.GetCoords(_positionOfScreenPoint);

        // calculate offset between marker and ScreenPoint
        float targetCoordsX = (float)(markerCoordinates.x  - (markerCoordinates.x  - screenPointCoordinates.x));
        float targetCoordsY = (float)(markerCoordinates.y + (markerCoordinates.y - screenPointCoordinates.y));

        // move map
        OnlineMaps.instance.SetPositionAndZoom(targetCoordsX, targetCoordsY, _zoom);
    }