Topic: Creating a sphere of 1km radius on the map

Hey,

One of the Game-play mechanics requires me to - Affect players with a set range(in Km), So I wanted to ask you if there is a quick way to create a sphere on the map at any given time whose radius is about 1 kilometers, can I convert unity's scale units into the actual distance on the map?
Right now I am thinking I will instantiate a sphere and use collision to detect how many objects are actually inside it. I'm not sure if my question made sense, I can describe it in a more detail if you want me to.

Thanks,

Cheers,
Mridul

Re: Creating a sphere of 1km radius on the map

Hello.

Example drawing cylinder with specified radius is attached.
This example can be easily modified to work with the sphere.

Post's attachments

Attachment icon DrawCircleWithRadius.cs 905 b, 115 downloads since 2016-09-11 

Re: Creating a sphere of 1km radius on the map

Thanks

Re: Creating a sphere of 1km radius on the map

Hello Alex, Can you please update the DrawCircle script.  OnlineMaps.instance.tilesetSize doesnt exist anymore.

Re: Creating a sphere of 1km radius on the map

Mridul wrote:

Hello Alex, Can you please update the DrawCircle script.  OnlineMaps.instance.tilesetSize doesnt exist anymore.

Hello, I've recently wrote this, which works for me:

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));
    }
}

It's placed on a 3DMarker that's being placed on the map by the LocationServices script (which is the users location).
Hope this helps you!

Re: Creating a sphere of 1km radius on the map

Hello.

Mridul, here's an actual example:
https://infinity-code.com/atlas/online- … arker.html

jarne, thanks for sharing your script.
I think this will be useful for someone looking for an example on the forum.

Re: Creating a sphere of 1km radius on the map

Alex Vertax wrote:

Hello.

Mridul, here's an actual example:
https://infinity-code.com/atlas/online- … arker.html

jarne, thanks for sharing your script.
I think this will be useful for someone looking for an example on the forum.

Hello, thanks for this sample, but I am looking for a way to keep the item at the correct real world size after zooming the map, really what I need is a method that can convert a km value into a worldspace value based of zoom. The intended use is so that when a map zooms out the objects get smaller.

Best

Steve

Re: Creating a sphere of 1km radius on the map

Unfortunately, I didn't understand what you mean.
The example you quoted creates a circle that always has the specified horizontal radius in km, no matter what zoom the map has.

Re: Creating a sphere of 1km radius on the map

Alex Vertax wrote:

Unfortunately, I didn't understand what you mean.
The example you quoted creates a circle that always has the specified horizontal radius in km, no matter what zoom the map has.

Hello, I am making and managing my own map elements, so I needed a scaling function for their OnMapMoved event handlers, One where I can input their real world size, say 5 meters and use Infinity map tools to work out how big in world space that is based on map scale.

Re: Creating a sphere of 1km radius on the map

Your own elements are just GameObjects, not 3D markers, right?
See OnlineMapsMarker3D.cs line: 400 for an example.