Topic: Update position (lat,lng) of drawn OnlineMapsDrawingElement

Hi,

I'm trying to update the position of a drawn OnlineMapsDrawingElement so it sticks to the player (LocationService).
I thought I had it with this code: https://forum.infinity-code.com/viewtop … 6536#p6536

using System;
using UnityEngine;

public class DrawCircleAroundPlayer : MonoBehaviour
{
    /// <summary>
    /// Radius of the circle
    /// </summary>
    public float radiusKM = 0.1f;

    /// <summary>
    /// Number of segments
    /// </summary>
    public int segments = 32;

    private OnlineMapsMarker3DInstance onlineMapsMarker;
    private OnlineMaps map;

    private void Start()
    {
        map = OnlineMaps.instance;
        onlineMapsMarker = GetComponent<OnlineMapsMarker3DInstance>();
        name = onlineMapsMarker.marker.label;
        DrawCircle();
    }

    /// <summary>
    /// Draw circle around player with set radius
    /// </summary>
    private void DrawCircle()
    {
        // Get the coordinates under cursor
        double lng = onlineMapsMarker.marker.position.x;
        double lat = onlineMapsMarker.marker.position.y;

        // Get the coordinate at the desired distance
        double nlng, nlat;
        OnlineMapsUtils.GetCoordinateInDistance(lng, lat, radiusKM, 90, out nlng, out nlat);

        double tx1, ty1, tx2, ty2;

        // Convert the coordinate under cursor to tile position
        map.projection.CoordinatesToTile(lng, lat, 20, out tx1, out ty1);

        // Convert remote coordinate to tile position
        map.projection.CoordinatesToTile(nlng, nlat, 20, out tx2, out ty2);

        // Calculate radius in tiles
        double r = tx2 - tx1;

        // Create a new array for points
        OnlineMapsVector2d[] points = new OnlineMapsVector2d[segments];

        // Calculate a step
        double step = 360d / segments;

        // Calculate each point of circle
        for (int i = 0; i < segments; i++)
        {
            double px = tx1 + Math.Cos(step * i * OnlineMapsUtils.Deg2Rad) * r;
            double py = ty1 + Math.Sin(step * i * OnlineMapsUtils.Deg2Rad) * r;
            map.projection.TileToCoordinates(px, py, 20, out lng, out lat);
            points[i] = new OnlineMapsVector2d(lng, lat);
        }

        // Create a new polygon to draw a circle
        OnlineMapsDrawingElementManager.AddItem(new OnlineMapsDrawingPoly(points, Color.green, 3));
    }
}

however the circle stays in place (which is fairly logical since it's not really updated to follow the player).

I've tried to adjust the transform.position of the drawn circle with:

item.instance.transform.position = OnlineMapsTileSetControl.instance.GetWorldPosition(position);

with the position coming for the "OnLocationChanged" event.

What am I doing wrong? How should I go about changing the position of the draw circle to follow the player?
I've tried setting the parent of the circle to the PlayerMarker, yet this also gives some weird behaviour.

Re: Update position (lat,lng) of drawn OnlineMapsDrawingElement

Hello.

It doesn't work that way.
You need to update every point of the polygon, and call map.Redraw.

Kind Regards,
Infinity Code Team.

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

Re: Update position (lat,lng) of drawn OnlineMapsDrawingElement

I got it, thank you so much for your help and sorry if my questions are noob-ish.