Exemplo n.º 1
0
        protected override void RequestTile(int tileX, int tileY, int roundedZoom, Tile tile)
        {
            if (db == null)
            {
                throw new NullReferenceException("db");
            }

            DataTable dt = db.ExecuteQuery("SELECT tile_data FROM tiles WHERE zoom_level=" + roundedZoom + " AND tile_column=" + tileX + " AND tile_row=" + tileY);

            if (dt.Rows.Count == 0)
            {
#if DEBUG_LOG
                Debug.LogWarning("WARNING: no rows in MBTiles db for tile: " + tileX + "," + tileY + "," + roundedZoom);
#endif
                return;
            }

            Texture2D tex = new Texture2D((int)Map.TileResolution, (int)Map.TileResolution);
            if (tex.LoadImage((byte[])dt.Rows[0]["tile_data"]))
            {
                tile.SetTexture(tex);
            }
            else
            {
#if DEBUG_LOG
                Debug.LogError("ERROR: MBTilesLayer.RequestTile: couldn't load image for: " + tileX + "," + tileY + "," + roundedZoom);
#endif
            }
        }
Exemplo n.º 2
0
            private IEnumerator DownloadCoroutine()
            {
                WWW    www = null;
                string ext = Path.GetExtension(url);

                if (ext.Contains("?"))
                {
                    ext = ext.Substring(0, ext.IndexOf('?'));
                }
#if !UNITY_WEBPLAYER
                if (cached && File.Exists(Application.temporaryCachePath + "/" + this.guid + ext))
                {
                    www = new WWW("file:///" + Application.temporaryCachePath + "/" + this.guid + ext);
#if DEBUG_LOG
                    Debug.Log("DEBUG: TileDownloader.DownloadCoroutine: loading tile from cache: url: " + www.url);
#endif
                }
                else
#endif
                {
                    www = new WWW(url);
#if DEBUG_LOG
                    Debug.Log("DEBUG: TileDownloader.DownloadCoroutine: loading tile from provider: url: " + www.url
#if !UNITY_WEBPLAYER
                              + "(cached: " + cached + ")"
#endif
                              );
#endif
                }

                yield return(www);

#if DEBUG_PROFILE
                UnitySlippyMap.Profiler.Begin("TileDownloader.TileEntry.DownloadCoroutine");
#endif

#if DEBUG_PROFILE
                UnitySlippyMap.Profiler.Begin("www error test");
#endif
                if (String.IsNullOrEmpty(www.error) && www.text.Contains("404 Not Found") == false)
                {
#if DEBUG_PROFILE
                    UnitySlippyMap.Profiler.End("www error test");
#endif
#if DEBUG_PROFILE
                    UnitySlippyMap.Profiler.Begin("www.texture");
#endif

                    Texture2D texture = new Texture2D(1, 1, TextureFormat.ARGB32, true);
                    www.LoadImageIntoTexture(texture);

#if DEBUG_PROFILE
                    UnitySlippyMap.Profiler.End("www.texture");
#endif

#if DEBUG_PROFILE
                    UnitySlippyMap.Profiler.Begin("is cached?");
#endif
#if !UNITY_WEBPLAYER
                    if (this.cached == false)
                    {
#if DEBUG_PROFILE
                        UnitySlippyMap.Profiler.End("is cached?");
#endif

#if DEBUG_PROFILE
                        UnitySlippyMap.Profiler.Begin("set TileEntry members");
#endif

                        byte[] bytes = www.bytes;

                        this.size = bytes.Length;
                        this.guid = Guid.NewGuid().ToString();
#if DEBUG_PROFILE
                        UnitySlippyMap.Profiler.End("set TileEntry members");
#endif

#if DEBUG_PROFILE
                        UnitySlippyMap.Profiler.Begin("new FileStream & FileStream.BeginWrite");
#endif
                        FileStream fs = new FileStream(Application.temporaryCachePath + "/" + this.guid + ext, FileMode.Create, FileAccess.Write, FileShare.None, 4096, true);
                        fs.BeginWrite(bytes, 0, bytes.Length, new AsyncCallback(EndWriteCallback), new AsyncInfo(this, fs));
#if DEBUG_PROFILE
                        UnitySlippyMap.Profiler.End("new FileStream & FileStream.BeginWrite");
#endif

#if DEBUG_LOG
                        Debug.Log("DEBUG: TileEntry.DownloadCoroutine: done loading: " + www.url + ", writing to cache: " + fs.Name);
#endif
                    }
                    else
                    {
#if DEBUG_PROFILE
                        UnitySlippyMap.Profiler.End("is cached?");
#endif
#if DEBUG_LOG
                        Debug.Log("DEBUG: TileEntry.DownloadCoroutine: done loading from cache: " + www.url + " [" + url + "]");
#endif
                    }

                    this.timestamp = (DateTime.Now - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds;
#endif

#if DEBUG_PROFILE
                    UnitySlippyMap.Profiler.Begin("Tile.SetTexture");
#endif
                    tile.SetTexture(texture);
#if DEBUG_PROFILE
                    UnitySlippyMap.Profiler.End("Tile.SetTexture");
#endif
                }
                else
                {
#if DEBUG_PROFILE
                    UnitySlippyMap.Profiler.End("www error test");
#endif
                    this.error = true;
#if DEBUG_LOG
                    Debug.LogError("ERROR: TileEntry.DownloadCoroutine: done downloading: " + www.url + " with error: " + www.error);
#endif
                }

#if DEBUG_PROFILE
                UnitySlippyMap.Profiler.End("TileDownloader.TileEntry.DownloadCoroutine");
#endif
            }
Exemplo n.º 3
0
	protected override void RequestTile(int tileX, int tileY, int roundedZoom, Tile tile)
	{
		if (db == null)
		{
			throw new NullReferenceException("db");
		}
		
		DataTable dt = db.ExecuteQuery("SELECT tile_data FROM tiles WHERE zoom_level=" + roundedZoom + " AND tile_column=" + tileX + " AND tile_row=" + tileY);
		if (dt.Rows.Count == 0)
		{
#if DEBUG_LOG
			Debug.LogWarning("WARNING: no rows in MBTiles db for tile: " + tileX + "," + tileY + "," + roundedZoom);
#endif
			return ;
		}
		
		Texture2D tex = new Texture2D((int)Map.TileResolution, (int)Map.TileResolution);
		if (tex.LoadImage((byte[])dt.Rows[0]["tile_data"]))
			tile.SetTexture(tex);
		else
		{
#if DEBUG_LOG
			Debug.LogError("ERROR: MBTilesLayer.RequestTile: couldn't load image for: " + tileX + "," + tileY + "," + roundedZoom);
#endif
		}
	}