<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — How to draw a circle on the map?!]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=232&amp;type=atom" />
	<updated>2023-03-17T19:46:27Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=232</id>
		<entry>
			<title type="html"><![CDATA[Re: How to draw a circle on the map?!]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8908#p8908" />
			<content type="html"><![CDATA[<p>Post #6 explains how to scale 2D markers.<br />But I would use 3D markers. At least because it has the inbuilt ability to have the size in metres.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2023-03-17T19:46:27Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8908#p8908</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: How to draw a circle on the map?!]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8907#p8907" />
			<content type="html"><![CDATA[<p>Well before you replied, i already checked the 2dtexture marker, but issue is i want to draw that circle on a specific radius. like the drawing circle functionality do, <br />I want my custom circle to be drawed to the whole radius. when i zoom the map, that marker is also zoomed. And in drawed circle functionality, the circle is not zoomed. It is still there where the boundaries are.</p>]]></content>
			<author>
				<name><![CDATA[uneebkari]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2520</uri>
			</author>
			<updated>2023-03-17T19:38:40Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8907#p8907</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: How to draw a circle on the map?!]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8906#p8906" />
			<content type="html"><![CDATA[<p>Hello.</p><p>For the way in post #2 to have filling see documentation (Troubleshooting / Known Issues section).</p><p>Or use the way in post #6.</p><p>Or you can use a 3D marker with a circle prefab.</p><p>Or you can use TilesetOverlayExample (see example atlas), where the overlay will contain a circle texture.</p><p>Or you can write a custom map shader that will draw circles. It&#039;s not very complicated, but you will be able to have a limited number of circles.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2023-03-17T18:49:11Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8906#p8906</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: How to draw a circle on the map?!]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8905#p8905" />
			<content type="html"><![CDATA[<p>Hi<br />I check your circle drawing, it just draws a bordered circle, what am i look is draw a custom circle with a center filler with 40% opacity and thick border.<br />Can anyone please help me in drawing such circle.</p>]]></content>
			<author>
				<name><![CDATA[uneebkari]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2520</uri>
			</author>
			<updated>2023-03-17T13:24:07Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8905#p8905</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: How to draw a circle on the map?!]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1055#p1055" />
			<content type="html"><![CDATA[<p>That explains it. Thanks!</p>]]></content>
			<author>
				<name><![CDATA[kalaki]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=215</uri>
			</author>
			<updated>2016-08-05T18:14:52Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1055#p1055</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: How to draw a circle on the map?!]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1054#p1054" />
			<content type="html"><![CDATA[<p>Because these methods has been added in Online Maps v2.4.<br />For Online Maps v2.3 use OnlineMapsUtils.LatLongToTiled, OnlineMapsUtils.TileToLatLong, OnlineMapsMarkerBase.position.<br />Or just update Online Maps through the built-in update system.</p><p>How to open the built-in update system:<br />Online Maps / Help / Check Updates.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2016-08-05T17:16:46Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1054#p1054</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: How to draw a circle on the map?!]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1052#p1052" />
			<content type="html"><![CDATA[<p>This is probably a silly question but when I try use the code in post #2 I get errors:<br />OnlineMapsProjection&nbsp; &lt;-- class is missing<br />OnlineMapsMarker.GetPosition&nbsp; &lt;-- GetPoistion is missing <br />OnlineMaps.projection&nbsp; &lt;-- projection is missing</p><p>OnlineMaps.version == &quot;2.3.0.18&quot;</p>]]></content>
			<author>
				<name><![CDATA[kalaki]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=215</uri>
			</author>
			<updated>2016-08-05T15:50:06Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1052#p1052</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: How to draw a circle on the map?!]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1051#p1051" />
			<content type="html"><![CDATA[<p>Thanks for the tip, you are absolutely correct!</p>]]></content>
			<author>
				<name><![CDATA[SweetTooth]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=213</uri>
			</author>
			<updated>2016-08-05T14:01:10Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1051#p1051</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: How to draw a circle on the map?!]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1050#p1050" />
			<content type="html"><![CDATA[<p>Actually better to use OnChangePosition and OnChangeZoom, to reduce the number of calculations and do not position GameObject each frame.<br />This example is quite old, and I do not remember why I used Update.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2016-08-05T13:03:37Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1050#p1050</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: How to draw a circle on the map?!]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1049#p1049" />
			<content type="html"><![CDATA[<p>Actually you are absolutely right, the circle mesh solution is just perfect! Although I should note that if you include it into API examples, please replace Update method with the LateUpdate, so that there would be no visible delay when the map is being scrolled.</p><p>And thank you very much for the distance limitation example, that&#039;s just what we need!</p>]]></content>
			<author>
				<name><![CDATA[SweetTooth]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=213</uri>
			</author>
			<updated>2016-08-05T12:54:39Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1049#p1049</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: How to draw a circle on the map?!]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1048#p1048" />
			<content type="html"><![CDATA[<p>Both solutions (post 2, 6) reach your goals.<br />Please explain more detail why you can not use it?</p><p>Example how to limit the distance of the map from the marker:<br /></p><div class="codebox"><pre><code>using System;
using UnityEngine;

public class LimitPositionWithRadius:MonoBehaviour
{
    public float raduis = 1.5f; // km
    private OnlineMapsMarker playerMarker;
    private float sqrRadius;
    private OnlineMaps map;
    private bool ignoreEvent;

    private void Start()
    {
        sqrRadius = raduis * raduis;
        map = OnlineMaps.instance;
        map.OnChangePosition += OnChangePosition;
        map.OnChangeZoom += OnChangePosition;
        playerMarker = map.AddMarker(map.position, &quot;Player&quot;);
    }

    private void OnChangePosition()
    {
        if (ignoreEvent) return;

        double mx, my;
        playerMarker.GetPosition(out mx, out my);

        double px, py;
        map.GetPosition(out px, out py);

        double dx, dy;
        OnlineMapsUtils.DistanceBetweenPoints(px, py, mx, my, out dx, out dy);
        double sqrR = dx * dx + dy * dy;
        if (sqrR &gt; sqrRadius)
        {
            double tx1, ty1, tx2, ty2;
            map.projection.CoordinatesToTile(px, py, map.zoom, out tx1, out ty1);
            map.projection.CoordinatesToTile(mx, my, map.zoom, out tx2, out ty2);

            double scale = raduis / Math.Sqrt(sqrR);
            double ntx = tx2 + (tx1 - tx2) * scale;
            double nty = ty2 + (ty1 - ty2) * scale;
            map.projection.TileToCoordinates(ntx, nty, map.zoom, out ntx, out nty);
            ignoreEvent = true;
            map.SetPosition(ntx, nty);
            ignoreEvent = false;

            OnlineMapsUtils.DistanceBetweenPoints(ntx, nty, mx, my, out dx, out dy);
            Debug.Log(&quot;New distance: &quot; + Math.Sqrt(dx * dx + dy * dy));
        }
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2016-08-05T12:38:22Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1048#p1048</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: How to draw a circle on the map?!]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1044#p1044" />
			<content type="html"><![CDATA[<p>I&#039;m very sorry for so many questions, pleae bear with me...</p><p>Actually I also need to limit, how far the map can be scrolled - for example, no further than 1.5 kilometers from current player position... And it seems that in order to do this (in order to calculate OnlineMapsPositionRange), I have to basically solve the same problem - to find points in (lat, long), which would have a distance of 1500 meters between them and a player position. Can you please tell me, how can I do this?</p>]]></content>
			<author>
				<name><![CDATA[SweetTooth]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=213</uri>
			</author>
			<updated>2016-08-05T11:34:48Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1044#p1044</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: How to draw a circle on the map?!]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1043#p1043" />
			<content type="html"><![CDATA[<p>Thank you very much, Alex!</p><p>I&#039;m sorry for any confusion I caused... You see, we have objects (markers) on the map and want to show a circle around player marker, which should explain to player which objects can be interacted with (since they are considered visible) and which can&#039;t (the player should reach them first)... So on the one hand we need a solution, which would look physically correct (the circle should overlap the visible markers and match the distance to objects, which is also being displayed) and on the other hand everything should scale like markers when zoom level is changed...</p><p>Can you please help us understand, how to do this?</p>]]></content>
			<author>
				<name><![CDATA[SweetTooth]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=213</uri>
			</author>
			<updated>2016-08-05T11:25:19Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1043#p1043</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: How to draw a circle on the map?!]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1042#p1042" />
			<content type="html"><![CDATA[<p>To make a circle more accurate increase segments.</p><p>Yes, you can place the mesh on the map.<br />Actually, it would be a much better solution.<br />The example below.<br />Just your original question was about poly.<br />Use OnlineMapsTileSetControl.GetWorldPosition, to convert coordinates in Unity World Space position.<br /><a href="http://infinity-code.com/doxygen/online-maps/classOnlineMapsTileSetControl.html#adcfdea4962fd10c64683602992c6e097">http://infinity-code.com/doxygen/online … 2992c6e097</a></p><p>Yes, you can convert the radius in meters to pixels.<br />If you really need it, I can give an example.<br />But keep in mind a few things:<br />1. The radius in pixels (R) is different at different zoom level.<br />2. R is different at different latitudes.<br />3. R left == R right.<br />4. R left != R up.<br />5. R up != R down.</p><p>Example of drawing a circle using mesh:<br /></p><div class="codebox"><pre><code>using UnityEngine;

public class DrawCircleWithRadius : MonoBehaviour
{
    public GameObject circle;
    public float diameterInKM = 0.5f;
    public float sizeY = 0.02f;

    private OnlineMapsMarker marker;

    private void Start()
    {
        marker = OnlineMaps.instance.AddMarker(OnlineMaps.instance.position, &quot;Marker&quot;);
    }

    private void Update ()
    {
        circle.transform.position = OnlineMapsTileSetControl.instance.GetWorldPosition(marker.position);

        OnlineMaps api = OnlineMaps.instance;

        Vector2 distance = OnlineMapsUtils.DistanceBetweenPoints(api.topLeftPosition, api.bottomRightPosition);

        float scaleX = diameterInKM / distance.x * api.tilesetSize.x;
        float scaleY = diameterInKM / distance.y * api.tilesetSize.y;
        float scale = (scaleX + scaleY) / 2;

        circle.transform.localScale = new Vector3(scale, sizeY, scale);
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2016-08-05T11:10:22Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1042#p1042</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: How to draw a circle on the map?!]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1040#p1040" />
			<content type="html"><![CDATA[<p>Also, can you please tell me, how can I convert real-life radius in meters to pixels?</p>]]></content>
			<author>
				<name><![CDATA[SweetTooth]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=213</uri>
			</author>
			<updated>2016-08-05T10:17:25Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1040#p1040</id>
		</entry>
</feed>
