Dynamic change of provider and map type

Back
Tags:
Provider
Map type
Example how to get the available providers and to change the current provider.
Usage instructions:
Add this script to map GameObject and start the scene.
In console will display a name of available map types.
Then the map type will be changed to Google Satellite.
Then the map type will be changed to the first type for ArcGIS.
ChangeProviderAndTypeExample.cs
/*         INFINITY CODE         */
/*   https://infinity-code.com   */

using UnityEngine;

namespace InfinityCode.OnlineMapsExamples
{
    /// <summary>
    /// Example how to get the available providers and to change the current provider.
    /// </summary>
    [AddComponentMenu("Infinity Code/Online Maps/Examples (API Usage)/ChangeProviderAndTypeExample")]
    public class ChangeProviderAndTypeExample : MonoBehaviour
    {
        /// <summary>
        /// Reference to the map. If not specified, the current instance will be used.
        /// </summary>
        public OnlineMaps map;
        
        /// <summary>
        /// Logs providers id and map types
        /// </summary>
        private void LogTypeList()
        {
            // Gets all providers
            OnlineMapsProvider[] providers = OnlineMapsProvider.GetProviders();
            foreach (OnlineMapsProvider provider in providers)
            {
                Debug.Log(provider.id);
                foreach (OnlineMapsProvider.MapType type in provider.types)
                {
                    Debug.Log(type);
                }
            }
        }

        private void Start()
        {
            // If map is not specified, use the current instance.
            if (map == null) map = OnlineMaps.instance;
            
            // Show full provider list
            LogTypeList();

            // Select Google Satellite
            map.mapType = "google.satellite"; // providerID.typeID

            // Select the first type for ArcGIS.
            map.mapType = "arcgis"; // providerID
        }
    }
}