<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Circle Points from DrawCircleAroundMarker.cs Atlas is null]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1981&amp;type=atom" />
	<updated>2022-06-16T16:46:07Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=1981</id>
		<entry>
			<title type="html"><![CDATA[Re: Circle Points from DrawCircleAroundMarker.cs Atlas is null]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8396#p8396" />
			<content type="html"><![CDATA[<p>The map is not immediately redrawn and an instance will be created on the next redraw.</p><p>If you really need an instance right away, call drawingElement.DrawOnTileset method.<br />This will cause the element to be drawn and create an instance.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2022-06-16T16:46:07Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8396#p8396</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Circle Points from DrawCircleAroundMarker.cs Atlas is null]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8392#p8392" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Alex Vertax wrote:</cite><blockquote><p>Hello.</p><p>The problem is that in DrawCircle method you are creating OnlineMapsVector2d[], and in OnCircleClick method you are trying to cast it to Vector2[].<br />In OnCircleClick method, you also need to use OnlineMapsVector2d[].</p></blockquote></div><p>Hi, sorry again I wanted to ask about element.instance</p><p>Why can&#039;t I immediately get the instance of the drawing each time it is created?</p><p>Script Example<br /></p><div class="codebox"><pre><code>         if(Input.GetMouseButtonUp(0))
        {
            if(poly != null &amp;&amp; poly.name == &quot;Rect&quot;)
            {
                Vector2[] vertices2D = new Vector2[]{pointRect[0], pointRect[1], pointRect[2], pointRect[3]};

                poly.Dispose();

                if(warna.value == 0)
                polygon = new OnlineMapsDrawingPoly(vertices2D, Color.blue, 1, Color.blue);
                else
                polygon = new OnlineMapsDrawingPoly(vertices2D, Color.red, 1, Color.red);

                poly = OnlineMapsDrawingElementManager.AddItem(polygon);
                poly.name = &quot;Rect&quot;;

                if(poly != null)
                OnlineMaps.instance.Redraw();
                
                poly.OnClick += OnElementClick;
                poly.OnPress += OnElementPress;
                poly.OnRelease += OnElementRelease;

                Debug.Log(poly.instance.name);

                poly = null;
                onlineMaps.blockAllInteractions = false;
                isDragging = false;
                isDrawingSquare = false;
                n = 0;
            }
        }</code></pre></div><p>In the script above, whenever I try to immediately check the instance of the drawing (In this case the instance.name), it always showed an error in which the object I referenced is not there.</p><div class="codebox"><pre><code>NullReferenceException: Object reference not set to an instance of an object
DrawArrow.DrawKotak () (at Assets/Scripts/DrawArrow.cs:404)
DrawArrow.IsDrawing () (at Assets/Scripts/DrawArrow.cs:278)
DrawArrow.Update () (at Assets/Scripts/DrawArrow.cs:82)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[moonflow123]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1980</uri>
			</author>
			<updated>2022-06-16T08:40:49Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8392#p8392</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Circle Points from DrawCircleAroundMarker.cs Atlas is null]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8372#p8372" />
			<content type="html"><![CDATA[<p>Ah that&#039;s why, thank you for that. Let me test it.</p>]]></content>
			<author>
				<name><![CDATA[moonflow123]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1980</uri>
			</author>
			<updated>2022-06-14T01:49:11Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8372#p8372</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Circle Points from DrawCircleAroundMarker.cs Atlas is null]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8369#p8369" />
			<content type="html"><![CDATA[<p>Hello.</p><p>The problem is that in DrawCircle method you are creating OnlineMapsVector2d[], and in OnCircleClick method you are trying to cast it to Vector2[].<br />In OnCircleClick method, you also need to use OnlineMapsVector2d[].</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2022-06-13T19:22:51Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8369#p8369</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Circle Points from DrawCircleAroundMarker.cs Atlas is null]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8366#p8366" />
			<content type="html"><![CDATA[<p>Hi, I tried using one of your Atlas example for drawing circle and noticed that there&#039;s a kind of bug whenever I created the circle.<br />The bug is whenever I clicked on the poly circle, it will not display its points. It did display its poly.name though.</p><p>For the atlas example I&#039;m using is the DrawCircleAroundMarker.cs.</p><p>Keep in mind that the only thing that I added in the DrawCircleAroundMarker.cs is the OnCircleClick function and also a bool so I can only create the marker and the circle when the bool is true;</p><p>Here&#039;s the code</p><div class="codebox"><pre><code> public class DrawCircleAroundMarker : 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 = 64;
        public Vector2[] circlePoint;
        public bool drawCircle;

        /// &lt;summary&gt;
        /// This method is called when a user clicks on a map
        /// &lt;/summary&gt;
        private void DrawCircle()
        {
            if(Input.GetMouseButtonDown(0))
            {
                // Get the coordinates under cursor
                double lng, lat;
                OnlineMapsControlBase.instance.GetCoords(out lng, out lat);

                // Create a new marker under cursor
                OnlineMapsMarkerManager.CreateItem(lng, lat, &quot;Marker &quot; + OnlineMapsMarkerManager.CountItems);

                OnlineMaps map = OnlineMaps.instance;

                // 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
                OnlineMapsDrawingElement poly = OnlineMapsDrawingElementManager.AddItem
                (new OnlineMapsDrawingPoly(points, Color.red, 3, Color.red));
                poly.OnClick += OnCircleClick;
            }
        }

        /// &lt;summary&gt;
        /// This method is called when the script starts
        /// &lt;/summary&gt;
        private void Start()
        {
            // Subscribe to click on map event
        }

        private void Update()
        {
            if(drawCircle)
            DrawCircle();
        }

        private void OnCircleClick(OnlineMapsDrawingElement element)
        {
            OnlineMapsDrawingPoly poly = element as OnlineMapsDrawingPoly;

            circlePoint = poly.points as Vector2[];
            Debug.Log(poly.name);

            if(circlePoint == null || circlePoint.Length == 0)
            Debug.LogError(&quot;Cannot See The Circle Points!!!&quot;);
        }
    }</code></pre></div>]]></content>
			<author>
				<name><![CDATA[moonflow123]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1980</uri>
			</author>
			<updated>2022-06-13T04:04:27Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8366#p8366</id>
		</entry>
</feed>
