<?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 — How to reduce time of the map update during zoom (download textures)?]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=647</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=647&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in How to reduce time of the map update during zoom (download textures)?.]]></description>
		<lastBuildDate>Thu, 14 Sep 2017 13:26:35 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: How to reduce time of the map update during zoom (download textures)?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=2800#p2800</link>
			<description><![CDATA[<p>I fixed a few minor bugs and added extra features:<br /></p><div class="codebox"><pre><code>using UnityEngine;

public class TilePreloader:MonoBehaviour
{
    // Number of tiles at the current zoom level.
    // If you do not want to load extra tiles on the sides of the map, this should be Width / 256 and Height / 256.
    public int countTilesX = 4;
    public int countTilesY = 4;

    public int countParentZoom = 3;
    public int countNextZoom = 1;

    private void Start()
    {
        OnlineMaps.instance.OnMapUpdated += PreloadTiles;
    }

    private void PreloadTiles()
    {
        foreach (OnlineMapsTile tile in OnlineMapsTile.tiles) tile.used = false;

        int countX = countTilesX * (1 &lt;&lt; countNextZoom);
        int countY = countTilesY * (1 &lt;&lt; countNextZoom);

        int cz = OnlineMaps.instance.zoom + countNextZoom;
        if (cz &gt; OnlineMaps.MAXZOOM)
        {
            countX /= 1 &lt;&lt; (cz - OnlineMaps.MAXZOOM);
            countY /= 1 &lt;&lt; (cz - OnlineMaps.MAXZOOM);
            cz = OnlineMaps.MAXZOOM;
        }

        double tx, ty;
        OnlineMaps.instance.GetTilePosition(out tx, out ty, cz);

        tx -= countX / 2;
        ty -= countY / 2;
        int sx = (int) tx;
        int sy = (int) ty;
        int ex = sx + countX;
        int ey = sy + countY;

        int max = 1 &lt;&lt; cz;

        if (sx &lt; 0)
        {
            sx += max;
            ex += max;
        }
        if (sy &lt; 0) sy = 0;
        if (ey &gt; max) ey = max;

        bool needRedraw = false;

        for (int z = Mathf.Max(OnlineMaps.instance.zoom - countParentZoom, 3); z &lt;= cz; z++)
        {
            int zoff = cz - z;
            int coof = 1 &lt;&lt; zoff;
            int csx = sx / coof;
            int csy = sy / coof;
            int cex = ex / coof;
            int cey = ey / coof;
            int cmax = max / coof;

            for (int x = csx; x &lt;= cex; x++)
            {
                int cx = x;
                if (cx &gt;= cmax) cx -= cmax;

                for (int y = csy; y &lt;= cey; y++)
                {
                    OnlineMapsTile t;
                    OnlineMapsTile parent;
                    OnlineMapsTile.dTiles.TryGetValue(OnlineMapsTile.GetTileKey(z, cx, y), out t);
                    if (t != null)
                    {
                        if (!t.isBlocked) t.Block(this);
                        t.used = true;
                        continue;
                    }

                    OnlineMapsTile.dTiles.TryGetValue(OnlineMapsTile.GetTileKey(z - 1, cx / 2, y / 2), out parent);

                    t = new OnlineMapsTile(cx, y, z, OnlineMaps.instance, parent);
                    t.Block(this);
                    t.used = true;
                    needRedraw = true;
                }
            }
        }

        foreach (OnlineMapsTile tile in OnlineMapsTile.tiles) if (!tile.used) tile.Unblock(this);
        if (needRedraw) OnlineMaps.instance.Redraw();
    }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Thu, 14 Sep 2017 13:26:35 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=2800#p2800</guid>
		</item>
		<item>
			<title><![CDATA[Re: How to reduce time of the map update during zoom (download textures)?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=2799#p2799</link>
			<description><![CDATA[<p>Something like:<br /></p><div class="codebox"><pre><code>using UnityEngine;

public class TilePreloader:MonoBehaviour
{
    // Number of tiles at the current zoom level.
    // If you do not want to load extra tiles on the sides of the map, this should be Width / 256 and Height / 256.
    public int countTilesX = 4;
    public int countTilesY = 4;

    private void Start()
    {
        OnlineMaps.instance.OnMapUpdated += PreloadTiles;
    }

    private void PreloadTiles()
    {
        foreach (OnlineMapsTile tile in OnlineMapsTile.tiles) tile.used = false;

        int countX = countTilesX * 2;
        int countY = countTilesY * 2;

        int cz = OnlineMaps.instance.zoom + 1;
        if (cz &gt; OnlineMaps.MAXZOOM)
        {
            cz = OnlineMaps.MAXZOOM;
            countX /= 2;
            countY /= 2;
        }

        double tx, ty;
        OnlineMaps.instance.GetTilePosition(out tx, out ty, cz);

        tx -= countX / 2;
        ty -= countY / 2;
        int sx = (int) tx;
        int sy = (int) ty;
        int ex = sx + countX;
        int ey = sy + countY;

        int max = 1 &lt;&lt; cz;

        if (sx &lt; 0)
        {
            sx += max;
            ex += max;
        }
        if (sy &lt; 0) sy = 0;
        if (ey &gt; max) ey = max;

        bool needRedraw = false;

        for (int z = cz; z &gt;= Mathf.Max(OnlineMaps.instance.zoom - 3, 3); z--)
        {
            int zoff = cz - z;
            int coof = 1 &lt;&lt; zoff;
            int csx = sx / coof;
            int csy = sy / coof;
            int cex = ex / coof;
            int cey = ey / coof;
            int cmax = max / coof;

            for (int x = csx; x &lt; cex; x++)
            {
                int cx = x;
                if (cx &gt;= cmax) cx -= cmax;

                for (int y = csy; y &lt; cey; y++)
                {
                    OnlineMapsTile t;
                    OnlineMapsTile.dTiles.TryGetValue(OnlineMapsTile.GetTileKey(z, cx, y), out t);
                    if (t != null)
                    {
                        if (!t.isBlocked) t.Block(this);
                        t.used = true;
                        continue;
                    }

                    OnlineMapsTile parent;
                    OnlineMapsTile.dTiles.TryGetValue(OnlineMapsTile.GetTileKey(z - 1, cx / 2, y / 2), out parent);

                    t = new OnlineMapsTile(cx, y, z, OnlineMaps.instance, parent);
                    t.Block(this);
                    t.used = true;
                    needRedraw = true;
                }
            }
        }

        foreach (OnlineMapsTile tile in OnlineMapsTile.tiles) if (!tile.used) tile.Unblock(this);
        if (needRedraw) OnlineMaps.instance.Redraw();
    }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Thu, 14 Sep 2017 12:07:56 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=2799#p2799</guid>
		</item>
		<item>
			<title><![CDATA[Re: How to reduce time of the map update during zoom (download textures)?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=2794#p2794</link>
			<description><![CDATA[<p>Thank you so much, Alex Vertax, for a fantastic script! It works perfectly, it is a very convenient and useful tool!</p><p>In case of the whole city, downloaded tiles for each zoom level takes too much space (it&#039;s millions of tiles). You mentioned &quot;Preloader&quot; as an additional option, how can it be used?</p>]]></description>
			<author><![CDATA[null@example.com (Rumata)]]></author>
			<pubDate>Wed, 13 Sep 2017 18:19:42 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=2794#p2794</guid>
		</item>
		<item>
			<title><![CDATA[Re: How to reduce time of the map update during zoom (download textures)?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=2785#p2785</link>
			<description><![CDATA[<p>Thank you very much, Alex Vertax! <br />I would really appreciate if You could share the script with me, the letter sent.</p><p>Thank you!</p>]]></description>
			<author><![CDATA[null@example.com (Rumata)]]></author>
			<pubDate>Tue, 12 Sep 2017 21:38:43 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=2785#p2785</guid>
		</item>
		<item>
			<title><![CDATA[Re: How to reduce time of the map update during zoom (download textures)?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=2784#p2784</link>
			<description><![CDATA[<p>Hello.</p><p>To speed up the update of the map, you need to speed up the loading of tiles.<br />There are two ways:<br />1. Preloader, that will download tiles, which can be required in the near future.<br />2. Offline tiles.<br />Loading tiles from a local source is much faster than downloading from an online server.<br />You can download tiles for the area using GMapCatcher, and place them in Resources folder.<br />Or I have my own script to download tiles.<br />I will not publish this on the forum.<br />But, if you need I&#039;ll send it to you, just write in support (support@infinity-code.com).<br />Yes, if you have all the required tiles, you can use the map offline.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Tue, 12 Sep 2017 20:57:26 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=2784#p2784</guid>
		</item>
		<item>
			<title><![CDATA[How to reduce time of the map update during zoom (download textures)?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=2782#p2782</link>
			<description><![CDATA[<p>Hello,<br />When I zooming in it takes some time for the map to load new map texture with more details. This delay looks a bit laggy. </p><p>1) The only way to reduce the time required for updating the map texture is to download the map texture for all zoom levels, right?</p><p>2) I&#039;m going to limit the map area using OnlineMapsPositionRange, is it possible to download the map texture for all zoom levels only for this particular map area, not the entire planet?</p><p>3) Am I right that in this case, I can use the map offline, since it&#039;s already downloaded?</p><p>Thank you in advance!</p>]]></description>
			<author><![CDATA[null@example.com (Rumata)]]></author>
			<pubDate>Tue, 12 Sep 2017 20:31:22 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=2782#p2782</guid>
		</item>
	</channel>
</rss>
