<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Using a single Online Maps for multiple maps]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1891&amp;type=atom" />
	<updated>2022-01-27T17:51:00Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=1891</id>
		<entry>
			<title type="html"><![CDATA[Re: Using a single Online Maps for multiple maps]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8065#p8065" />
			<content type="html"><![CDATA[<p>I just tested this and have no exceptions.<br />It is possible that you have exceptions because you have modified the code.</p><p>Thanks for the bug report.<br />The issue with Zoom Mode - Center has been fixed.</p><p>Camera.main is only used in 3D controls if activeCamera is null.<br />Other controls can use Camera.main directly because they don&#039;t have a camera reference. I just don&#039;t see the point in making a reference to the camera, but if anyone ever gives me a reasonable reason to do so, I&#039;ll add the ability to specify the camera.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2022-01-27T17:51:00Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8065#p8065</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Using a single Online Maps for multiple maps]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8063#p8063" />
			<content type="html"><![CDATA[<p>I think you should be able to see it in your project too, if you remove the try-catch. I tried it in an (almost) empty project with the Tileset example scene.</p><p>Sounds great that you&#039;ll release a new version!</p><br /><br /><p>There&#039;s also another problem, zooming with OnlineMapsZoomMode.center:<br />&nbsp; 1. Move to the top of the map at zoom level around 5.<br />&nbsp; 2. Zoom out to level 1<br />&nbsp; 3. Map will be halfway outside the screen<br />&nbsp; 4. Start dragging map<br />&nbsp; 5. Map pops into center</p><p>I fixed it temporarily in SmoothZoomOnMouseEvents.UpdateZoom(), and 3 other places:<br /></p><div class="codebox"><pre><code>            if (control.zoomMode == OnlineMapsZoomMode.center) control.ZoomOnPoint(z - map.floatZoom, new Vector2(Screen.width * 0.5f, Screen.height * 0.5f)); // PREVIOUSLY: map.floatZoom = z;
            else control.ZoomOnPoint(z - map.floatZoom, inputPosition);</code></pre></div><br /><br /><p>I actually kind of liked the mode where you can be at the edge of the map even when zoomed out. But then it shouldn&#039;t snap to the center when starting a drag. That way I can zoom in and out freely without fear changing the position in center zoom mode. Is there a switch to enable that?<br />I could kind of get it to work by disabling this line in OnlineMaps.SetPosition:<br />&nbsp; &nbsp; &nbsp; &nbsp; if (modified) projection.TileToCoordinates(tpx, tpy, zoom, out lng, out lat);<br />But I didn&#039;t really know what I was doing.</p><br /><br /><p>Also when looking closer into what happens when zooming, I also found some calls to &quot;Camera.main&quot;, in Camera.main.ScreenPointToRay(). Most are using activeCamera.ScreenPointToRay() though. Just thought I would mention it.</p><p>Thanks for all the help!</p>]]></content>
			<author>
				<name><![CDATA[hanni78]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1793</uri>
			</author>
			<updated>2022-01-27T10:53:16Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8063#p8063</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Using a single Online Maps for multiple maps]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8059#p8059" />
			<content type="html"><![CDATA[<p>Unfortunately, I don&#039;t know why this happened in your case. To understand this, I need to debug your project.</p><p>I optimized OnlineMapsThreadManager.ExecuteMainThreadActions and added an extra check to fix this exception.<br />The next version will most likely be released today (January 27) in my local time.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2022-01-26T23:07:43Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8059#p8059</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Using a single Online Maps for multiple maps]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8055#p8055" />
			<content type="html"><![CDATA[<p>Ah, you&#039;re right. It wasn&#039;t the tileSize that caused the errors. It was simply that when I changed tileSize, tiles started loading from network instead of cache. Map loading from network stopped working completely.</p><p>The error showed itself when I rewrote ExecuteMainThreadActions to invoke only one action per frame:<br /></p><div class="codebox"><pre><code>            if (mainThreadActions.Count != 0)
            {
                mainThreadActions[0].Invoke();
                mainThreadActions.RemoveAt(0);
            }</code></pre></div><p>If I add the try-catch like in the previous implementation, the error is hidden, and map loading works again:<br /></p><div class="codebox"><pre><code>            if (mainThreadActions.Count != 0)
            {
                try
                {
                    mainThreadActions[0].Invoke();
                }
                catch { }
                mainThreadActions.RemoveAt(0);
            }</code></pre></div><p>But if I Debug.Log() inside the catch { } I see that the error occurs sporadically. Maps are still loaded though and everything works.</p><br /><p><strong>But do you know where the error comes from? And is it possible to fix, to avoid Exceptions and improve performance?</strong></p><p>System.NullReferenceException: Object reference not set to an instance of an object<br />&nbsp; at OnlineMapsCache.LoadTile (OnlineMapsTile tile, System.Byte[] bytes) [0x00009] in \Online maps\Scripts\Cache\OnlineMapsCache.File.cs:205 <br />&nbsp; at OnlineMapsCache+&lt;&gt;c__DisplayClass40_1.&lt;TryLoadFromFileCache&gt;b__1 () [0x00000] in \Online maps\Scripts\Cache\OnlineMapsCache.File.cs:283 <br />&nbsp; at OnlineMapsThreadManager.ExecuteMainThreadActions () [0x0001d] in \Online maps\Scripts\Threading\OnlineMapsThreadManager.cs:110</p><p>205:&nbsp; &nbsp; &nbsp; &nbsp; if (!map.control.resultIsTexture || tempTexture == null) // map is null</p>]]></content>
			<author>
				<name><![CDATA[hanni78]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1793</uri>
			</author>
			<updated>2022-01-26T11:35:56Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8055#p8055</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Using a single Online Maps for multiple maps]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8000#p8000" />
			<content type="html"><![CDATA[<p>I am glad that you were able to solve your problems.</p><p>Thank you for reporting that ExecuteMainThreadActions can cause freezes.<br />I will rework this method so that it doesn&#039;t cause problems.</p><p>You cannot reduce size of OnlineMapsUtils.tileSize.<br />This will do nothing good, and can cause problems in any unexpected place of the asset.<br />Also, it will increase memory usage.<br />But I don&#039;t think NullReferenceExceptions are related to tile size.<br />Most likely this is due to the creation or loading of tiles in some other place in the scripts.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2022-01-07T08:08:29Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8000#p8000</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Using a single Online Maps for multiple maps]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=7999#p7999" />
			<content type="html"><![CDATA[<p>It wasn&#039;t difficult to change out the code in<br />- OnlineMapsThreadManager.ExecuteMainThreadActions() to just invoke a single action per frame, which removed most of the stuttering.</p><p>- Also in OnlineMapsCache.OnPreloadTiles(), I had to reduce the time it&#039;s allowed to run.<br />from:&nbsp; &nbsp;if (Time.realtimeSinceStartup - start &gt; 0.02) return;<br />to:&nbsp; &nbsp; &nbsp; &nbsp;if (Time.realtimeSinceStartup - start &gt; 0.004) return;</p><br /><p>- I also tried to change the tile size in OnlineMapsUtils.tileSize from 256 to 64 to reduce loading and texture creation even further, but that started spamming NullReferenceExceptions on this line in OnlineMapsCache.LoadTile():<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!map.control.resultIsTexture || tempTexture == null)<br />Apparently &quot;map&quot; is null here.</p>]]></content>
			<author>
				<name><![CDATA[hanni78]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1793</uri>
			</author>
			<updated>2022-01-07T00:46:46Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=7999#p7999</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Using a single Online Maps for multiple maps]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=7998#p7998" />
			<content type="html"><![CDATA[<p>Okay so I already got further by switching out the &quot;TextureControl&quot; for a &quot;Tileset + Render Texture&quot; like you mentioned in an earlier post.<br />Now I&#039;m able to load maps completely, and the script that prevents loading empty tiles works now!</p><p>Now for the hopefully last problem:<br />- When tiles are loaded from network, the game performance isn&#039;t affected at all. Everything runs smooth.<br />- But when tiles are loaded from the file cache, there is stuttering in the game.</p><p>Is it possible to slow down the file reading when loading from cache, perhaps just loading one tile per frame?</p>]]></content>
			<author>
				<name><![CDATA[hanni78]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1793</uri>
			</author>
			<updated>2022-01-06T23:49:23Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=7998#p7998</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Using a single Online Maps for multiple maps]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=7996#p7996" />
			<content type="html"><![CDATA[<p>Hi, I&#039;ve started looking into this now.</p><p>I&#039;m not sure I quite followed your explanation. Not sure how to &quot;Iterate all tiles in a range&quot;. What range? Can the tile corners give me that range? Searched through all the code in the plugin for &quot;GetTileCorners&quot; but I couldn&#039;t find a similar use-case.</p><br /><p>Instead I tried creating an OnlineMaps GameObject with a TextureControl and let it download the maps into textures in the background.</p><p>In my test project, I simulate the loading of maps while moving a cube smoothly over the screen to see if any janks are occuring.<br />And I found that the graphics performance wasn&#039;t degraded at all from loading textures, great!</p><p>The test code I&#039;m using to feed new Textures into OnlineMaps below works great:<br /></p><div class="codebox"><pre><code>IEnumerator LoadMaps()
{
  for (int i = 0; i &lt; 10; i++)
  {
    Texture2D t = new Texture2D(512, 512, TextureFormat.RGB24, true);
    generatedTextures.Add(t);
  }
  Random.InitState(1234);
  for (int i = 0; i &lt; 10; i++)
  {
    yield return new WaitForSeconds(2.0f);  
    onlineMaps.SetTexture(generatedTextures[i]);
    onlineMaps.SetPosition(15 + Random.Range(-15, 15), 40 + Random.Range(-15, 15));
  }
}</code></pre></div><br /><p>But the problem:<br />I would really like to make sure that the generated textures don&#039;t contain empty tiles because of zoom level. But instead use tiles from a lower zoom level, and scale them up.</p><p>The script you recommended in another thread using the OnTileLoaded() callback works great for TilesetControl, but doesn&#039;t receive any tile texture at all to the callback when using TextureControl:</p><p>OnTileLoaded: &#039;18x131070x100183&#039;, Tile texture: &#039;&#039;<br />OnTileLoaded: &#039;18x131070x100184&#039;, Tile texture: &#039;&#039;<br />OnTileLoaded: &#039;18x131070x100185&#039;, Tile texture: &#039;&#039;</p><p>Is there a way to ensure this in OnlineMaps Texture mode?</p><p>Thanks!</p>]]></content>
			<author>
				<name><![CDATA[hanni78]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1793</uri>
			</author>
			<updated>2022-01-06T15:37:55Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=7996#p7996</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Using a single Online Maps for multiple maps]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=7967#p7967" />
			<content type="html"><![CDATA[<p>This is not a built-in behavior, but you can achieve it using the API.</p><p>How would I do it:<br />When starting the application, load the tiles for each area with a zoom - 2 (current zoom minus two). <br />- To do this, set the center position and zoom as if you had clicked on the page. <br />- Get the tile position of the corners (OnlineMaps.GetTileCorners for zoom minus 2). <br />- Iterate all tiles in a range. <br />- Check if the tiles exists (OnlineMapsTileManager.GetTile). <br />- if it is missing, create it (new OnlineMapsRasterTile).<br />- Block them from unloading (OnlineMapsTile.Block).<br />- Repeat this for each page.</p><p>When you open the page, you will have the tiles already loaded, which will immediately show the map.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2021-12-13T20:08:26Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=7967#p7967</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Using a single Online Maps for multiple maps]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=7966#p7966" />
			<content type="html"><![CDATA[<p>Hi, thanks for the explanation.</p><p>I think I want to go with one instance of the map for all the pages.<br />Each page only shows a static map of a location set by the user.<br />The location can be changed by the user in another scene, with an interactive OnlineMaps.</p><p>So my wish would be to have an invisible OnlineMaps that loads all the location maps slowly in the background when entering this part of the app.</p><p>Ideally, when the user enters page 1:<br />- OnlineMaps sequentially downloads maps for all the pages in the background and renders each to a Texture.<br />- User can freely scroll to the other pages without any lag due to rendering maps.<br />- After a few seconds the map pops up on page 1, and after a few more it&#039;s ready for page 2 etc.<br />- At any point, the user can click on one of the maps, to open the second scene with an interactive map, and navigate to a new position. That position will then be replicated on the postcard later when returning.</p><p>* It it possible to have OnlineMaps work in a more on-demand manner? So that I can ask for it to download the tiles I need and render to texture?<br />* And currently when I enable the OnlineMaps component, my app UI starts jerking for half a second. Is it possible to have this downloading smoother and unnoticable?</p><p>Thanks!</p>]]></content>
			<author>
				<name><![CDATA[hanni78]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1793</uri>
			</author>
			<updated>2021-12-13T01:21:04Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=7966#p7966</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Using a single Online Maps for multiple maps]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=7964#p7964" />
			<content type="html"><![CDATA[<p>Hello.</p><p>Ideally, if possible, you should use one instance of the map.<br />Every next instance will greatly increase the memory / CPU / GPU usage.<br />And it definitely shouldn&#039;t be 5+ instances.</p><p>It is best to only use Tileset Control because it has better performance, less memory usage, and has exclusive features.<br />When you need to show the map on UI, use Tileset + Render Texture + Touch Forwarder (if it needs to be interactive).</p><p>Yes, you can cache Render Texture and show it until the map is fully loaded.<br />In addition, you can cache tiles in your areas so that the map loads tiles from local sources, which will be much faster than downloading them from the Internet.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2021-12-10T19:01:27Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=7964#p7964</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Using a single Online Maps for multiple maps]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=7962#p7962" />
			<content type="html"><![CDATA[<p>I&#039;m creating a game where you set 5-10 GPS positions on map. Each GPS position is shown on its own page.</p><p>You can see each map position you have set by swiping to that page. So each page needs to have a texture with the positioned map. Each map on the 5-10 pages currently use OnlineMaps with an &quot;OnlineMapsTextureControl&quot;.</p><p>You can also go into each map, which opens a new scene additively, to edit the position. The map in that editor uses &quot;OnlineMapsTilemapControl&quot;.</p><p>1) Do you suggest doing all this with just a single instance of OnlineMaps?<br />2) Or should I have two, one for all the textures on pages, and one for editing?<br />3) Or should I have all 11, and disable/enable them appropriately as user navigates?</p><p>if 1) Should I then have an OnlineMaps that contains both the &quot;TextureControl&quot; (for the page mode) and the &quot;TilemapControl&quot; (for the edit mode), and enable/disable either component based on user navigation?</p><p>if 1) or 2) Can I create a texture for OnlineMaps to write to, and then create a new one in runtime, so that I can cache each GPS position&#039;s texture when user leaves page, allowing user to smoothly swipe between pages when all textures are cached?<br />And should I disable the OnlineMaps object that isn&#039;t currently used when in edit mode or page mode?</p><p>if 3) Should all of them have the location service running at the same time, or should it be enabled/disabled based on navigation?</p><p>Thanks</p>]]></content>
			<author>
				<name><![CDATA[hanni78]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1793</uri>
			</author>
			<updated>2021-12-10T15:01:41Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=7962#p7962</id>
		</entry>
</feed>
