<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — restrict max zoom to real map]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=716&amp;type=atom" />
	<updated>2017-12-08T04:08:36Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=716</id>
		<entry>
			<title type="html"><![CDATA[Re: restrict max zoom to real map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=3127#p3127" />
			<content type="html"><![CDATA[<p>Hi Alex,<br />I tried your code above but found 2 problems, my call back to OnTileLoaded is not consistant and rarely (never?) gets called when going to zoom level 20.<br />It does go up to about 17 if using mouse wheel in editor and up to 19 if manually put in zoom in inspector while running. <br />If I try to print out the pixel colors manually, Finding the correct format for getting the texture shown on the screen is doing my head in, and unfortunately other mapping functionality has become a higher priority, so the max zoom feature will have to wait for a week or so. Thankyou so much for a great product, I am still in love with it.</p><p>PS, suggestion to put in your notes if using a &quot;longPress&quot;, also need to change the startDrag to a much bigger number (than 4;) or the long press never gets called.</p><p>//when using long press also increase startDrag&nbsp; <br />marker.OnLongPress += OnMarkerLongPress; <br />OnlineMapsControlBase.startDragDistance = 40;</p>]]></content>
			<author>
				<name><![CDATA[kingsleyz]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=604</uri>
			</author>
			<updated>2017-12-08T04:08:36Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=3127#p3127</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: restrict max zoom to real map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=3119#p3119" />
			<content type="html"><![CDATA[<p>I made a script (below) that works for me (Provider - ArcGIS / WorldImagery).<br />OnChangeZoom works on all zoom levels (including 19 and 20).<br />If you use another provider, just change the colors.</p><p>But this requires a slight modification of the source code Online Maps.<br />OnlineMapsTileSetControl.cs (line: 1600) from:<br /></p><div class="codebox"><pre><code>OnlineMapsTile currentTile = tile;</code></pre></div><p>to:<br /></p><div class="codebox"><pre><code>OnlineMapsTile currentTile = tile;
if (currentTile != null &amp;&amp; currentTile.status != OnlineMapsTileStatus.loaded) currentTile = null;</code></pre></div><p>OnlineMapsBuffer.cs (line: 421) from:<br /></p><div class="codebox"><pre><code>if (!tile.hasColors)</code></pre></div><p>to:<br /></p><div class="codebox"><pre><code>if (!tile.hasColors || tile.status != OnlineMapsTileStatus.loaded)</code></pre></div><p>I give you changes so that you do not wait for the new version to be available.<br />The next version of Online Maps will contain these changes.</p><p>Script:<br /></p><div class="codebox"><pre><code>using UnityEngine;

public class DetectNoDataTiles:MonoBehaviour
{
    private Color32 c1 = new Color32(204, 204, 204, 255);
    private Color32 c2 = new Color32(201, 201, 201, 255);

    private void Start()
    {
        OnlineMaps.instance.OnChangeZoom += OnChangeZoom;
        OnlineMapsTile.OnTileDownloaded += OnTileLoaded;
        OnlineMapsCache.instance.OnLoadedFromCache += OnTileLoaded;
    }

    public void OnTileLoaded(OnlineMapsTile tile)
    {
        Color32 p1, p2, p3;
        if (OnlineMaps.instance.target == OnlineMapsTarget.tileset)
        {
            p1 = tile.texture.GetPixelBilinear(0, 0);
            p2 = tile.texture.GetPixelBilinear(0.5f, 0.5f);
            p3 = tile.texture.GetPixelBilinear(1, 1);
        }
        else
        {
            p1 = tile.colors[0];
            p2 = tile.colors[32896];
            p3 = tile.colors[65535];
        }
        

        if (ColorEqual(p1, c1) &amp;&amp;
            ColorEqual(p2, c2) &amp;&amp;
            ColorEqual(p3, c1)) tile.status = OnlineMapsTileStatus.error;
    }

    public static bool ColorEqual(Color32 c1, Color32 c2)
    {
        if (c1.r != c2.r) return false;
        if (c1.g != c2.g) return false;
        if (c1.b != c2.b) return false;
        if (c1.a != c2.a) return false;
        return true;
    }

    public void OnChangeZoom()
    {
        Debug.Log(&quot;zoom&quot; + OnlineMaps.instance.zoom);
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2017-12-07T01:45:39Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=3119#p3119</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: restrict max zoom to real map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=3118#p3118" />
			<content type="html"><![CDATA[<p>Now running 2.25.1 no major change.<br />the calls to OnTileDownloaded &amp; OnLoadedFromCache are consistantly called when reducing the zoom from 20 to 19, but are never called when zooming in from 19 to 20.</p>]]></content>
			<author>
				<name><![CDATA[kingsleyz]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=604</uri>
			</author>
			<updated>2017-12-06T22:26:52Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=3118#p3118</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: restrict max zoom to real map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=3117#p3117" />
			<content type="html"><![CDATA[<p>Have struggled to make this work.<br />I can detect pixel color (only tried 1 pixel) but do not get call to downloaded or cache functions when map shows &quot;no map data&quot; image.<br />In the area I am working, zoom level 20 shows no data.<br />But zoom level 20 never gets to Tile or cache functions<br />Code and output below:</p><p>As a side note, I don&#039;t seem to be getting zoom in completed notification either, related ?</p><p>void Start () {<br />&nbsp; &nbsp; &nbsp; &nbsp; //few other things<br />&nbsp; &nbsp; &nbsp; &nbsp; OnlineMapsLocationService locationService = OnlineMapsLocationService.instance; //used in other code<br />&nbsp; &nbsp; &nbsp; &nbsp; OnlineMaps.instance.OnChangeZoom += OnChangeZoom;<br />&nbsp; &nbsp; &nbsp; &nbsp; OnlineMapsTile.OnTileDownloaded += OnTileDownloaded;<br />&nbsp; &nbsp; &nbsp; &nbsp; OnlineMapsCache.instance.OnLoadedFromCache += OnLoadedFromCache;<br />//more stuff<br />}<br />&nbsp; &nbsp; public void OnTileDownloaded(OnlineMapsTile tile)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; Debug.Log(&quot;Tile DOwnloaded at zoom: &quot; + OnlineMaps.instance.zoom);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; Color colTextPix;<br />&nbsp; &nbsp; &nbsp; &nbsp; colTextPix = tile.texture.GetPixel(1, 1);<br />&nbsp; &nbsp; &nbsp; &nbsp; Debug.Log(&quot;colour of pixel downloaded&quot; + colTextPix);<br />&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; public void OnLoadedFromCache(OnlineMapsTile tile)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; Debug.Log(&quot;Tile from Cache zoom: &quot; + OnlineMaps.instance.zoom);<br />&nbsp; &nbsp; &nbsp; &nbsp; Color colTextPix;<br />&nbsp; &nbsp; &nbsp; &nbsp; colTextPix = tile.texture.GetPixel(1, 1);<br />&nbsp; &nbsp; &nbsp; &nbsp; Debug.Log(&quot;colour of pixel cached&quot; + colTextPix);<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; <br />&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;public void OnChangeZoom()<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; // When the zoom changes you will see in the console new zoom.<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Debug.Log(&quot;zoom&quot; + OnlineMaps.instance.zoom);<br />&nbsp; &nbsp; &nbsp; &nbsp; //debug never reports &quot;zoom&quot; change above<br />&nbsp; &nbsp; &nbsp; &nbsp;//code below not run<br />&nbsp; &nbsp; &nbsp; &nbsp; if (OnlineMaps.instance.zoom &gt; HZoomMax) OnlineMaps.instance.zoom = HZoomMax;<br />&nbsp; &nbsp; &nbsp; &nbsp; HZoomCurrent = OnlineMaps.instance.zoom;<br />&nbsp; &nbsp; &nbsp; &nbsp; testZoomedImage();<br />&nbsp; &nbsp; }</p><p>Output: note: zoom 20 has no output, but shows &quot;no data&quot; on screen and zoom 20 in &quot;map&quot; inside inspector:<br />Debug (shortened version, as get returns from several tiles each time moved or zoomed):</p><p>Tile from Cache zoom: 18<br />colour of pixel cachedRGBA(0.784, 0.753, 0.702, 1.000)<br />Tile from Cache zoom: 19<br />colour of pixel cachedRGBA(0.831, 0.820, 0.753, 1.000)</p><p>any suggestions greatly appreciated ?<br />PS will try again with new version from today</p>]]></content>
			<author>
				<name><![CDATA[kingsleyz]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=604</uri>
			</author>
			<updated>2017-12-06T21:33:06Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=3117#p3117</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: restrict max zoom to real map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=3106#p3106" />
			<content type="html"><![CDATA[<p>Brilliant Alex, appreciate the fast reply, will try these and report back.</p>]]></content>
			<author>
				<name><![CDATA[kingsleyz]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=604</uri>
			</author>
			<updated>2017-12-05T03:47:48Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=3106#p3106</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: restrict max zoom to real map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=3105#p3105" />
			<content type="html"><![CDATA[<p>Hello.</p><p>Yes, it is possible to implement, for example, in such ways (below).<br />The general idea is that all &quot;no map data&quot; tiles have the same image.</p><p>1. Intercept the request to download the tile, download the tile and check the checksum of the data. If the checksum matches the &quot;no map data&quot; tile, then set the status - error.<br /><a href="http://infinity-code.com/doxygen/online-maps/classOnlineMapsTile.html#a12c061f0e29b5600239abe5a04ae9f94">http://infinity-code.com/doxygen/online … 5a04ae9f94</a><br />2. Subscribe to OnlineMapsTile.OnTileDownloaded and OnlineMapsCache.OnLoadedFromCache. When the tile is loaded, check the colors of several pixels (for example, 3-5 pixels in different places of the image). If the colors of the image match the colors of &quot;no map data&quot; image, set the status - error.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2017-12-05T02:51:48Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=3105#p3105</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: restrict max zoom to real map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=3103#p3103" />
			<content type="html"><![CDATA[<p>Great question, I have longed for the same thing.&nbsp; Even a quick &#039;sanity check&#039; ROI option would be useful for manual trials, but an option to use a definitive index would be even better.</p><p>In a separate post, @Alex noted that providers differ in the data zoom levels supported.</p>]]></content>
			<author>
				<name><![CDATA[Kevin]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=501</uri>
			</author>
			<updated>2017-12-05T02:36:14Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=3103#p3103</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[restrict max zoom to real map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=3101#p3101" />
			<content type="html"><![CDATA[<p>Hi<br />Is there any way of detecting when a map is zoomed in so far that it says &quot; no available map data&quot; &quot;map data not yet available&quot; ... so that, we can sense then set the max zoom level (for this area) and restrict the user.</p><p>eg,<br />Currently:<br />user zooms in ... gets &quot;no map data page&quot; <br />User has to zoom out again to get map back.</p><p>Max zoom can be restricted but this is not dependent on the specific map location ... map areas (in the world) have different max zoom levels. Some are 15, some 18 etc.</p><p>Proposal:<br />user zooms in ... gets &quot;no map data&quot; page<br />Code detects &quot;no map data&quot; and automatically zooms out slightly.<br />code then restricts max zoom (existing function), so the &quot;no map data&quot; doesn&#039;t happen again while operating in this location.<br />User zooms in ... code puts map at max zoom available with map data.</p><p>PS, forgot to mention, fantastic product and great support with updates, you have solved many of my issues over the last 9 months via reading docs, examples and others forum posts.</p>]]></content>
			<author>
				<name><![CDATA[kingsleyz]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=604</uri>
			</author>
			<updated>2017-12-04T22:42:42Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=3101#p3101</id>
		</entry>
</feed>
