Topic: How can I reload the map?

I am using a custom tile source, and I would like to be able to change the URL within the application and reload the tiles, but I cannot find anything in the API that is obvious for this and the few things that I have tried (such as clearing the OnlineMapsTile.tiles collection) haven't worked.

Specifically: I can change the URL but cannot figure out how to tell the map to reload the tiles from the new source.  Any help you can provide would be appreciated!

Re: How can I reload the map?

Hello.

How to reload all tiles:

foreach (OnlineMapsTile tile in OnlineMapsTile.tiles) tile.Dispose();
OnlineMapsTile.tiles.Clear();
OnlineMaps.instance.Redraw();

But keep in mind - if you use the cache, then the texture that is already in the cache will be loaded.
You can read - the wrong textures will be loaded.

I recently made this script for another user.
Most likely you also want to do something like this:

using System;
using System.Reflection;
using UnityEngine;

public class ChangeCustomStyle2:MonoBehaviour
{
    public string style1;
    public string style2;

    private bool useFirstStyle = true;

    private void OnGUI()
    {
        if (GUILayout.Button("Change Style"))
        {
            useFirstStyle = !useFirstStyle;
            OnlineMaps.instance.mapType = "myprovider.style" + (useFirstStyle? "1": "2");
        }
    }

    private void Start()
    {
        // Online Maps v2.5.17 or less
        ConstructorInfo constructor = typeof(OnlineMapsProvider).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[]{typeof(string)}, null);
        OnlineMapsProvider provider = (OnlineMapsProvider)constructor.Invoke(new []{"myprovider"});

        OnlineMapsProvider.MapType[] types =
        {
            new OnlineMapsProvider.MapType("style1")
            {
                urlWithLabels = style1,
                provider = provider,
                fullID = "myprovider.style1"
            },
            new OnlineMapsProvider.MapType("style2")
            {
                urlWithLabels = style2,
                provider = provider,
                fullID = "myprovider.style2"
            }
        };

        OnlineMapsProvider[] providers = OnlineMapsProvider.GetProviders();
        Array.Resize(ref providers, providers.Length + 1);
        providers[providers.Length - 1] = provider;

        typeof(OnlineMapsProvider).GetField("_types", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(provider, types);
        typeof(OnlineMapsProvider).GetField("providers", BindingFlags.NonPublic | BindingFlags.Static).SetValue(null, providers);

        // Online Maps v2.5.18+
        /*OnlineMapsProvider.Create("myprovider").AppendTypes(
            new OnlineMapsProvider.MapType("style1") { urlWithLabels = style1, },
            new OnlineMapsProvider.MapType("style2") { urlWithLabels = style2, }
        );*/

        OnlineMaps.instance.mapType = "myprovider.style1";
    }
}
Kind Regards,
Infinity Code Team.

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