Topic: Change map type

Hi

I want to offer the possibility to the user to select the provider and type of map he wants.

I'm using this example :

http://infinity-code.com/atlas/online-m … ample.html

So far so good, i'm dynamically loading all the providers in a dropdown menu, with a second dropdown just for the type of map.
It's working well with several providers, but not all of them. The reason is, i believe, that some of the providers need an api key and other don't.

I looked into the doc:

http://infinity-code.com/doxygen/online … vider.html

but couldn't find a way to check if a key is needed / to provide the key. Could you point me a way to achieve that ?


Thanks,
Thibault

Re: Change map type

Hello.

You can set keys in this way:

using UnityEngine;

public class SwitchToProviderWithKey : MonoBehaviour
{
    private void OnGUI()
    {
        if (GUILayout.Button("Set DigitalGlobe"))
        {
            string mapTypeID = "digitalglobe.satellite";

            OnlineMaps.instance.mapType = mapTypeID;

            OnlineMapsProvider.MapType mapType = OnlineMapsProvider.FindMapType(mapTypeID);
            OnlineMapsProvider.ExtraField field = GetExtraField(mapType.extraFields, "accesstoken");
            if (field == null) field = GetExtraField(mapType.provider.extraFields, "accesstoken");

            if (field != null) field.value = "My DigitalGlobe Token";
        }
    }

    private static OnlineMapsProvider.ExtraField GetExtraField(OnlineMapsProvider.IExtraField[] extraFields, string token)
    {
        if (extraFields == null) return null;
        foreach (var field in extraFields)
        {
            if (field is OnlineMapsProvider.ExtraField)
            {
                OnlineMapsProvider.ExtraField f = field as OnlineMapsProvider.ExtraField;
                if (f.token == token) return f;
            }
            else if (field is OnlineMapsProvider.ToggleExtraGroup)
            {
                var res = GetExtraField((field as OnlineMapsProvider.ToggleExtraGroup).fields, token);
                if (res != null) return res;
            }
        }

        return null;
    }
}

Which tokens are needed for providers you can see in OnlineMapsProvider.InitProviders method.

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!