<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Infinity Code Forum — Setting access token when changing mapType dynamically]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=2380</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=2380&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Setting access token when changing mapType dynamically.]]></description>
		<lastBuildDate>Tue, 29 Jul 2025 14:46:31 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Setting access token when changing mapType dynamically]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=9865#p9865</link>
			<description><![CDATA[<p>Thanks a lot, that did the trick. When using the debugger, I saw that the ExtraField property was null. Probably put a breakpoint too soon, so I didn&#039;t look into the ExtraField. Thanks again !</p>]]></description>
			<author><![CDATA[null@example.com (matteo_enki)]]></author>
			<pubDate>Tue, 29 Jul 2025 14:46:31 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=9865#p9865</guid>
		</item>
		<item>
			<title><![CDATA[Re: Setting access token when changing mapType dynamically]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=9864#p9864</link>
			<description><![CDATA[<p>Hi.</p><p>Unfortunately, you didn&#039;t specify which version of Online Maps you are using.<br />Here is an example for Online Maps v4. It can be easily ported for v3.<br /></p><div class="codebox"><pre><code>using System.Linq;
using OnlineMaps;
using UnityEngine;

public class DynamicToken : MonoBehaviour
{
    public Map map;
    public string mapboxAccessToken;

    public string[] mapTypes = {
        &quot;osm.mapnik&quot;,
        &quot;mapbox.satellite&quot;,
    };
    
    private void OnGUI()
    {
        for (int i = 0; i &lt; mapTypes.Length; i++)
        {
            string mapType = mapTypes[i];
            if (GUILayout.Button(mapType))
            {
                SetMapType(mapType);
            }
        }
    }
    
    private void Start()
    {
        if (!map) map = GetComponent&lt;Map&gt;();
        if (string.IsNullOrEmpty(mapboxAccessToken))
        {
            Debug.LogError(&quot;Mapbox Access Token is required.&quot;);
            return;
        }

        SetMapType(mapTypes[0]);
    }

    private void SetMapType(string mapType)
    {
        map.mapType = mapType;
        if (!mapType.StartsWith(&quot;mapbox.&quot;)) return;
        
        TileProvider.ExtraField tokenField = TileSources.mapbox.extraFields.FirstOrDefault(f =&gt;
        {
            TileProvider.ExtraField ef = f as TileProvider.ExtraField;
            return ef != null &amp;&amp; ef.title == &quot;Access Token&quot;;
        }) as TileProvider.ExtraField;

        if (tokenField != null) tokenField.value = mapboxAccessToken;
    }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Tue, 29 Jul 2025 14:32:24 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=9864#p9864</guid>
		</item>
		<item>
			<title><![CDATA[Setting access token when changing mapType dynamically]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=9863#p9863</link>
			<description><![CDATA[<p>Hi ! I just got this asset yesterday, and it&#039;s pretty great.</p><p>However, I&#039;ve got a problem with the access token for MapBox.</p><p>What I&#039;m doing is changing map.mapType between osm.mapnik and mapbox.satellite with the press of a UI button. The change works, but the problem is that I can&#039;t seem to be able to set the access token for mapbox this way. The field doesn&#039;t stay serialized and I can&#039;t find a property of method to set it from the code when switching to it.</p><p>How could I achieve this behaviour ?</p><p>Thanks in advance</p>]]></description>
			<author><![CDATA[null@example.com (matteo_enki)]]></author>
			<pubDate>Tue, 29 Jul 2025 14:08:31 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=9863#p9863</guid>
		</item>
	</channel>
</rss>
