<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Ratio scale to zoom]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1938&amp;type=atom" />
	<updated>2022-04-14T18:06:21Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=1938</id>
		<entry>
			<title type="html"><![CDATA[Re: Ratio scale to zoom]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8208#p8208" />
			<content type="html"><![CDATA[<p>Thank you this helped me a bunch!</p>]]></content>
			<author>
				<name><![CDATA[nesw]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1950</uri>
			</author>
			<updated>2022-04-14T18:06:21Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8208#p8208</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Ratio scale to zoom]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8189#p8189" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2022-03-30T16:47:01Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8189#p8189</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Ratio scale to zoom]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8188#p8188" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[nesw]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1950</uri>
			</author>
			<updated>2022-03-30T12:37:45Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8188#p8188</id>
		</entry>
</feed>
