<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Scale OnlineMapsDrawingPoly After Creation]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1823&amp;type=atom" />
	<updated>2021-08-26T14:41:59Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=1823</id>
		<entry>
			<title type="html"><![CDATA[Re: Scale OnlineMapsDrawingPoly After Creation]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=7661#p7661" />
			<content type="html"><![CDATA[<p>Thank you. Got it working! Regards,</p><p>Jürgen</p>]]></content>
			<author>
				<name><![CDATA[negruj0w1tsch]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1428</uri>
			</author>
			<updated>2021-08-26T14:41:59Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=7661#p7661</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Scale OnlineMapsDrawingPoly After Creation]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=7660#p7660" />
			<content type="html"><![CDATA[<p>Hello.</p><p>Something like that:<br /></p><div class="codebox"><pre><code>/*         INFINITY CODE         */
/*   https://infinity-code.com   */

using System;
using System.Collections.Generic;
using UnityEngine;

namespace InfinityCode.OnlineMapsExamples
{
    /// &lt;summary&gt;
    /// Example how to draw a circle around a marker
    /// &lt;/summary&gt;
    public class BouncingCircle : MonoBehaviour
    {
        private static BouncingCircle instance;

        public AnimationCurve curve = AnimationCurve.EaseInOut(0, 0, 1, 1);
        public float duration = 3;

        /// &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 List&lt;BoundingItem&gt; items;

        /// &lt;summary&gt;
        /// This method is called when a user clicks on a map
        /// &lt;/summary&gt;
        private void OnMapClick()
        {
            // Get the coordinates under cursor
            double lng, lat;
            OnlineMapsControlBase.instance.GetCoords(out lng, out lat);
            OnlineMapsVector2d center = new OnlineMapsVector2d(lng, 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
            OnlineMapsDrawingPoly poly = new OnlineMapsDrawingPoly(points, Color.red, 3);
            OnlineMapsDrawingElementManager.AddItem(poly);

            if (items == null) items = new List&lt;BoundingItem&gt;();

            items.Add(new BoundingItem
            {
                points = points,
                center = center
            });
        }

        /// &lt;summary&gt;
        /// This method is called when the script starts
        /// &lt;/summary&gt;
        private void Start()
        {
            instance = this;

            // Subscribe to click on map event
            OnlineMapsControlBase.instance.OnMapClick += OnMapClick;
        }

        private void Update()
        {
            if (items == null || items.Count == 0) return;

            items.RemoveAll(i =&gt; i.Update());

            OnlineMaps.instance.Redraw();
        }

        public class BoundingItem
        {
            public OnlineMapsVector2d[] points;
            public bool finished;
            public OnlineMapsVector2d center;
            private float progress;

            public bool Update()
            {
                progress += Time.deltaTime / instance.duration;
                if (progress &gt;= 1)
                {
                    progress = 1;
                    finished = true;
                }

                float radius = instance.radiusKM * instance.curve.Evaluate(progress);

                double nlng, nlat;
                OnlineMapsUtils.GetCoordinateInDistance(center.x, center.y, radius, 90, out nlng, out nlat);

                double tx1, ty1, tx2, ty2;

                OnlineMaps map = OnlineMaps.instance;

                // Convert the coordinate under cursor to tile position
                map.projection.CoordinatesToTile(center.x, center.y, 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;

                int segments = points.Length;

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

                double lng, lat;

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

                return finished;
            }
        }
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2021-08-26T11:41:58Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=7660#p7660</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Scale OnlineMapsDrawingPoly After Creation]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=7658#p7658" />
			<content type="html"><![CDATA[<p>Hello,</p><p>I followed this tutorial to draw a circle on the map:</p><p><a href="http://infinity-code.com/atlas/online-maps/pages/DrawCircleAroundMarker.html">http://infinity-code.com/atlas/online-m … arker.html</a></p><p>What is the best way to scale this circle after it was created? I would like to make it bounce for a second when certain events happen in the app.</p><p>Thanks and cheers,</p><p>Jürgen</p>]]></content>
			<author>
				<name><![CDATA[negruj0w1tsch]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1428</uri>
			</author>
			<updated>2021-08-26T10:43:43Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=7658#p7658</id>
		</entry>
</feed>
