<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Creating a sphere of 1km radius on the map]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=275&amp;type=atom" />
	<updated>2020-09-30T09:14:18Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=275</id>
		<entry>
			<title type="html"><![CDATA[Re: Creating a sphere of 1km radius on the map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=6715#p6715" />
			<content type="html"><![CDATA[<p>Your own elements are just GameObjects, not 3D markers, right?<br />See OnlineMapsMarker3D.cs line: 400 for an example.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2020-09-30T09:14:18Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=6715#p6715</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Creating a sphere of 1km radius on the map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=6714#p6714" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Alex Vertax wrote:</cite><blockquote><p>Unfortunately, I didn&#039;t understand what you mean.<br />The example you quoted creates a circle that always has the specified horizontal radius in km, no matter what zoom the map has.</p></blockquote></div><p>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.</p>]]></content>
			<author>
				<name><![CDATA[clueduppstephen]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1169</uri>
			</author>
			<updated>2020-09-30T07:58:33Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=6714#p6714</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Creating a sphere of 1km radius on the map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=6710#p6710" />
			<content type="html"><![CDATA[<p>Unfortunately, I didn&#039;t understand what you mean.<br />The example you quoted creates a circle that always has the specified horizontal radius in km, no matter what zoom the map has.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2020-09-29T18:26:39Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=6710#p6710</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Creating a sphere of 1km radius on the map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=6708#p6708" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Alex Vertax wrote:</cite><blockquote><p>Hello.</p><p>Mridul, here&#039;s an actual example:<br /><a href="https://infinity-code.com/atlas/online-maps/pages/DrawCircleAroundMarker.html">https://infinity-code.com/atlas/online- … arker.html</a></p><p>jarne, thanks for sharing your script.<br />I think this will be useful for someone looking for an example on the forum.</p></blockquote></div><p>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.</p><p>Best</p><p>Steve</p>]]></content>
			<author>
				<name><![CDATA[clueduppstephen]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1169</uri>
			</author>
			<updated>2020-09-29T13:33:09Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=6708#p6708</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Creating a sphere of 1km radius on the map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=6537#p6537" />
			<content type="html"><![CDATA[<p>Hello.</p><p>Mridul, here&#039;s an actual example:<br /><a href="https://infinity-code.com/atlas/online-maps/pages/DrawCircleAroundMarker.html">https://infinity-code.com/atlas/online- … arker.html</a></p><p>jarne, thanks for sharing your script.<br />I think this will be useful for someone looking for an example on the forum.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2020-08-08T11:22:11Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=6537#p6537</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Creating a sphere of 1km radius on the map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=6536#p6536" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Mridul wrote:</cite><blockquote><p>Hello Alex, Can you please update the DrawCircle script.&nbsp; OnlineMaps.instance.tilesetSize doesnt exist anymore.</p></blockquote></div><p>Hello, I&#039;ve recently wrote this, which works for me:</p><div class="codebox"><pre><code>using System;
using UnityEngine;

public class DrawCircleAroundPlayer : MonoBehaviour
{
    /// &lt;summary&gt;
    /// Radius of the circle
    /// &lt;/summary&gt;
    public float radiusKM = 0.1f;

    /// &lt;summary&gt;
    /// Number of segments
    /// &lt;/summary&gt;
    public int segments = 32;

    private OnlineMapsMarker3DInstance onlineMapsMarker;
    private OnlineMaps map;

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

    /// &lt;summary&gt;
    /// Draw circle around player with set radius
    /// &lt;/summary&gt;
    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 &lt; 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));
    }
}</code></pre></div><p>It&#039;s placed on a 3DMarker that&#039;s being placed on the map by the LocationServices script (which is the users location).<br />Hope this helps you!</p>]]></content>
			<author>
				<name><![CDATA[jarne]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1355</uri>
			</author>
			<updated>2020-08-08T06:17:50Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=6536#p6536</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Creating a sphere of 1km radius on the map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=6535#p6535" />
			<content type="html"><![CDATA[<p>Hello Alex, Can you please update the DrawCircle script.&nbsp; OnlineMaps.instance.tilesetSize doesnt exist anymore.</p>]]></content>
			<author>
				<name><![CDATA[Mridul]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=225</uri>
			</author>
			<updated>2020-08-08T03:06:42Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=6535#p6535</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Creating a sphere of 1km radius on the map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1239#p1239" />
			<content type="html"><![CDATA[<p>Thanks</p>]]></content>
			<author>
				<name><![CDATA[Mridul]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=225</uri>
			</author>
			<updated>2016-09-11T17:21:11Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1239#p1239</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Creating a sphere of 1km radius on the map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1237#p1237" />
			<content type="html"><![CDATA[<p>Hello.</p><p>Example drawing cylinder with specified radius is attached.<br />This example can be easily modified to work with the sphere.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2016-09-11T11:41:51Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1237#p1237</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Creating a sphere of 1km radius on the map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1235#p1235" />
			<content type="html"><![CDATA[<p>Hey,</p><p>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&#039;s scale units into the actual distance on the map? <br />Right now I am thinking I will instantiate a sphere and use collision to detect how many objects are actually inside it. I&#039;m not sure if my question made sense, I can describe it in a more detail if you want me to.</p><p>Thanks,</p><p>Cheers,<br />Mridul</p>]]></content>
			<author>
				<name><![CDATA[Mridul]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=225</uri>
			</author>
			<updated>2016-09-11T04:20:26Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1235#p1235</id>
		</entry>
</feed>
