<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Infinity Code Forum — Ratio scale to zoom]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=1938</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1938&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Ratio scale to zoom.]]></description>
		<lastBuildDate>Thu, 14 Apr 2022 18:06:21 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Ratio scale to zoom]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=8208#p8208</link>
			<description><![CDATA[<p>Thank you this helped me a bunch!</p>]]></description>
			<author><![CDATA[null@example.com (nesw)]]></author>
			<pubDate>Thu, 14 Apr 2022 18:06:21 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=8208#p8208</guid>
		</item>
		<item>
			<title><![CDATA[Re: Ratio scale to zoom]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=8189#p8189</link>
			<description><![CDATA[<p>Hello.</p><p>Something like that:<br /></p><div class="codebox"><pre><code>using UnityEngine;

namespace InfinityCode.OnlineMapsSupport
{
    public class SetFloatZoomByScale : MonoBehaviour
    {
        private OnlineMaps map;

        private void OnGUI()
        {
            if (GUILayout.Button(&quot;1:200,000&quot;)) SetScale(200000);
            if (GUILayout.Button(&quot;1:150,000&quot;)) SetScale(150000);
            if (GUILayout.Button(&quot;1:100,000&quot;)) SetScale(100000);
            if (GUILayout.Button(&quot;1:50,000&quot;)) SetScale(50000);
            if (GUILayout.Button(&quot;1:25,000&quot;)) SetScale(25000);
            if (GUILayout.Button(&quot;1:10,000&quot;)) SetScale(10000);
        }

        private void Start()
        {
            map = GetComponent&lt;OnlineMaps&gt;();
        }

        private void SetScale(int scale)
        {
            float s = (float)scale / map.width * OnlineMapsUtils.tileSize;
            double prevDistance = 0;

            double lng, lat;
            map.GetPosition(out lng, out lat);

            for (int z = 2; z &lt; OnlineMaps.MAXZOOM; z++)
            {
                double tx, ty;
                map.projection.CoordinatesToTile(lng, lat, z, out tx, out ty);

                double lng1, lat1, lng2, lat2;
                map.projection.TileToCoordinates(0, (int)ty, z, out lng1, out lat1);
                map.projection.TileToCoordinates(1, (int)ty, z, out lng2, out lat2);

                double distance = OnlineMapsUtils.DistanceBetweenPoints(lng1, lat1, 0, lng2, lat2, 0) * 1000;
                if (distance &lt; s)
                {
                    Debug.Log($&quot;Z: {z}, Distance: {distance}, Prev Distance: {prevDistance}, Scale: {scale}, S: {s}&quot;);

                    map.floatZoom = z - (float)((s - distance) / (prevDistance - distance));
                    break;
                }

                prevDistance = distance;
            }

            ValidateZoom();
        }

        private void ValidateZoom()
        {
            const float equator = 40075000;
            float s;
            if (map.zoom &lt; 5) s = Mathf.RoundToInt(equator / (1 &lt;&lt; map.zoom) * map.zoomCoof * map.width / OnlineMapsUtils.tileSize);
            else
            {
                double lng, lat, lng1, lat1, lng2, lat2;
                map.GetPosition(out lng, out lat);
                map.GetTopLeftPosition(out lng1, out lat1);
                map.GetBottomRightPosition(out lng2, out lat2);
                s = Mathf.RoundToInt((float)OnlineMapsUtils.DistanceBetweenPoints(lng1, lat, 0, lng2, lat, 0) * 1000);
            }
            Debug.Log(s);

        }
    }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Wed, 30 Mar 2022 16:47:01 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=8189#p8189</guid>
		</item>
		<item>
			<title><![CDATA[Ratio scale to zoom]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=8188#p8188</link>
			<description><![CDATA[<p>Hi all,</p><p>I&#039;m trying to convert ratio scales (e.g. 1:20,000) to a float zoom level.</p><p>Is there a utility method for this within OnlineMaps? Or do we have a reference table?</p><p>For instance, how would I calculate the following scales into their respective zoom level?</p><p>1:200,000<br />1:150,000<br />1:100,000<br />1:50,000<br />1:25,000<br />1:10,000</p><p>Many thanks.</p>]]></description>
			<author><![CDATA[null@example.com (nesw)]]></author>
			<pubDate>Wed, 30 Mar 2022 12:37:45 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=8188#p8188</guid>
		</item>
	</channel>
</rss>
