Topic: How to reduce time of the map update during zoom (download textures)?

Hello,
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.

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?

2) I'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?

3) Am I right that in this case, I can use the map offline, since it's already downloaded?

Thank you in advance!

Re: How to reduce time of the map update during zoom (download textures)?

Hello.

To speed up the update of the map, you need to speed up the loading of tiles.
There are two ways:
1. Preloader, that will download tiles, which can be required in the near future.
2. Offline tiles.
Loading tiles from a local source is much faster than downloading from an online server.
You can download tiles for the area using GMapCatcher, and place them in Resources folder.
Or I have my own script to download tiles.
I will not publish this on the forum.
But, if you need I'll send it to you, just write in support (support@infinity-code.com).
Yes, if you have all the required tiles, you can use the map offline.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: How to reduce time of the map update during zoom (download textures)?

Thank you very much, Alex Vertax!
I would really appreciate if You could share the script with me, the letter sent.

Thank you!

Re: How to reduce time of the map update during zoom (download textures)?

Thank you so much, Alex Vertax, for a fantastic script! It works perfectly, it is a very convenient and useful tool!

In case of the whole city, downloaded tiles for each zoom level takes too much space (it's millions of tiles). You mentioned "Preloader" as an additional option, how can it be used?

Re: How to reduce time of the map update during zoom (download textures)?

Something like:

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 > 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 << cz;

        if (sx < 0)
        {
            sx += max;
            ex += max;
        }
        if (sy < 0) sy = 0;
        if (ey > max) ey = max;

        bool needRedraw = false;

        for (int z = cz; z >= Mathf.Max(OnlineMaps.instance.zoom - 3, 3); z--)
        {
            int zoff = cz - z;
            int coof = 1 << 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 < cex; x++)
            {
                int cx = x;
                if (cx >= cmax) cx -= cmax;

                for (int y = csy; y < 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();
    }
}
Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: How to reduce time of the map update during zoom (download textures)?

I fixed a few minor bugs and added extra features:

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 << countNextZoom);
        int countY = countTilesY * (1 << countNextZoom);

        int cz = OnlineMaps.instance.zoom + countNextZoom;
        if (cz > OnlineMaps.MAXZOOM)
        {
            countX /= 1 << (cz - OnlineMaps.MAXZOOM);
            countY /= 1 << (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 << cz;

        if (sx < 0)
        {
            sx += max;
            ex += max;
        }
        if (sy < 0) sy = 0;
        if (ey > max) ey = max;

        bool needRedraw = false;

        for (int z = Mathf.Max(OnlineMaps.instance.zoom - countParentZoom, 3); z <= cz; z++)
        {
            int zoff = cz - z;
            int coof = 1 << 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 <= cex; x++)
            {
                int cx = x;
                if (cx >= cmax) cx -= cmax;

                for (int y = csy; y <= 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();
    }
}
Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.