Topic: Tutorials

Could someone please point me to the tutorials for the google maps styling stuff? I can't seem to find them anywhere sad

Re: Tutorials

Rather, I found the tutorial to add a custom map style, however, I would like to know if there is anyway to change the custom map style runtime?

Re: Tutorials

Hello.

Yes, you can change the style at runtime.
Example:

using UnityEngine;

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

    private bool useFirstStyle = true;

    private void OnGUI()
    {
        if (GUILayout.Button("Change Style"))
        {
            useFirstStyle = !useFirstStyle;
            OnlineMaps.instance.customProviderURL = useFirstStyle? style1: style2;
            foreach (OnlineMapsTile tile in OnlineMapsTile.tiles) tile.Dispose();
            OnlineMapsTile.tiles.Clear();
            OnlineMaps.instance.Redraw();
        }
    }

    private void Start()
    {
        OnlineMaps.instance.customProviderURL = style1;
    }
}

But keep in mind, this way will not work with Online Maps Cache.

This is not the only way.
There are many ways, each of which will have its advantages and disadvantages.

Kind Regards,
Infinity Code Team.

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

Re: Tutorials

Thanks so much for the reply.

Sorry to be a bother, but how would I do it with the cache. For my project it is important that the cache updates as well.

Re: Tutorials

Do I just need to clear the cache?

Re: Tutorials

No, it is not enough to clear the cache.

Another way is to create your own provider:

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";
    }
}

Note: the current version of Online Maps (2.5.17) does not have a good way to create your own provider, so I implemented this through reflection.
In Online Maps v2.5.18 we will add a way to dynamically create providers and map types.
So I showed you both ways.

Kind Regards,
Infinity Code Team.

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