<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Transparent overlay]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=2389&amp;type=atom" />
	<updated>2025-09-25T18:58:38Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=2389</id>
		<entry>
			<title type="html"><![CDATA[Re: Transparent overlay]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9895#p9895" />
			<content type="html"><![CDATA[<p>Hi.</p><p>The example is attached. <br />This is a port script from v3.</p><div class="codebox"><pre><code>using System.Collections.Generic;
using System.Text.RegularExpressions;
using OnlineMaps;
using UnityEngine;
using Cache = OnlineMaps.Cache;

namespace InfinityCode.OnlineMapsSupport
{
    public class CustomWMTSOverlay : MonoBehaviour
    {
        /// &lt;summary&gt;
        /// URL pattern of WMTS tiles
        /// &lt;/summary&gt;
        public string url = &quot;https://services.arcgisonline.com/arcgis/rest/services/Reference/World_Boundaries_and_Places/MapServer/tile/{z}/{y}/{x}&quot;;

        /// &lt;summary&gt;
        /// Overlay download queue
        /// &lt;/summary&gt;
        private Queue&lt;Tile&gt; downloadQueue = new Queue&lt;Tile&gt;();

        /// &lt;summary&gt;
        /// The tile that is downloading now
        /// &lt;/summary&gt;
        private Tile activeTile;

        /// &lt;summary&gt;
        /// Adds a tile to the overlay download queue
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;tile&quot;&gt;Tile&lt;/param&gt;
        private void AddTileToQueue(Tile tile)
        {
            // Set the count of retry
            tile[&quot;countRetry&quot;] = 3;
            downloadQueue.Enqueue(tile);
            TryStartNextDownload();
        }

        /// &lt;summary&gt;
        /// Called when overlay is downloaded
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;www&quot;&gt;Instance of request&lt;/param&gt;
        private void OnDownloadComplete(WebRequest www)
        {
            activeTile = null;

            // Get the tile from a request
            Tile tile = www[&quot;tile&quot;] as Tile;

            // If the tile is null or disposed, try to download next one
            if (tile == null || tile.status == TileStatus.disposed)
            {
                TryStartNextDownload();
                return;
            }

            // Get tile texture
            Texture2D texture = new Texture2D(1, 1);
            texture.LoadImage(www.bytes);

            // If the texture is the wrong size
            if (texture.width == 8)
            {
                // Destroy the texture to avoid memory leak and try downloading again
                Destroy(texture);
                int countRetry = (int)tile[&quot;countRetry&quot;];
                if (countRetry &gt; 0)
                {
                    tile[&quot;countRetry&quot;] = countRetry - 1;
                    AddTileToQueue(tile);
                }
            }
            else
            {
                // Set WMS texture to back overlay
                tile.overlayBackTexture = texture;
                texture.wrapMode = TextureWrapMode.Clamp;
                tile.map.Redraw();
            }

            TryStartNextDownload();
        }

        /// &lt;summary&gt;
        /// Called when a tile is loaded from cache
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;tile&quot;&gt;Tile&lt;/param&gt;
        private void OnLoadedFromCache(Tile tile)
        {
            AddTileToQueue(tile);
        }

        /// &lt;summary&gt;
        /// Called when a tile is being downloaded from the internet
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;tile&quot;&gt;Tile&lt;/param&gt;
        private void OnStartDownloadTile(Tile tile)
        {
            TileManager.StartDownloadTile(tile);
            AddTileToQueue(tile);
        }

        private void Start()
        {
            TileManager.OnStartDownloadTile += OnStartDownloadTile;
            if (Cache.instance) Cache.instance.OnLoadedFromCache += OnLoadedFromCache;
        }

        /// &lt;summary&gt;
        /// Starts downloading the overlay for the tile
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;tile&quot;&gt;Tile&lt;/param&gt;
        private void StartDownloadOverlay(Tile tile)
        {
            string _url = Regex.Replace(url, @&quot;{\w+}&quot;, match =&gt;
            {
                string v = match.Value.ToLower().Trim(&#039;{&#039;, &#039;}&#039;);

                if (v == &quot;zoom&quot; || v == &quot;z&quot;) return tile.zoom.ToString();
                if (v == &quot;x&quot;) return tile.x.ToString();
                if (v == &quot;y&quot;) return tile.y.ToString();
                return &quot;{&quot; + v + &quot;}&quot;;
            });

            // Start download
            WebRequest www = new WebRequest(_url);
            www[&quot;tile&quot;] = tile;
            www.OnComplete += OnDownloadComplete;
        }

        /// &lt;summary&gt;
        /// Tries to start the next download
        /// &lt;/summary&gt;
        private void TryStartNextDownload()
        {
            // If the overlay is already loading, do nothing
            if (activeTile != null) return;

            // While there are tiles in the queue
            while (downloadQueue.Count &gt; 0)
            {
                // Get the first tile from the queue
                Tile tile = downloadQueue.Dequeue();

                // If the tile is not disposed, start downloading
                if (tile.status != TileStatus.disposed)
                {
                    activeTile = tile;
                    StartDownloadOverlay(tile);
                    return;
                }
            }
        }
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2025-09-25T18:58:38Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9895#p9895</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Transparent overlay]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9894#p9894" />
			<content type="html"><![CDATA[<p>What is the proper way to combine two layers (satellite imagery + transparent streets) to create a hybrid map?<br />I’m trying to use a back and front overlay approach, but I haven’t had any success so far.</p><p>Here&#039;s ab example for the transparent layer:<br /><a href="https://services.arcgisonline.com/arcgis/rest/services/Reference/World_Boundaries_and_Places/MapServer/tile/{z}/{y}/{x}">https://services.arcgisonline.com/arcgi … z}/{y}/{x}</a></p>]]></content>
			<author>
				<name><![CDATA[galdalali]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=26974</uri>
			</author>
			<updated>2025-09-25T13:52:18Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9894#p9894</id>
		</entry>
</feed>
