public override byte[] renderSegmentThreadSafe(int x, int y, int z) { //Debug.Log("BING_MAP_RENDER"); var qpath = GISparser.getQuadPath(x, y, z); string qpaths = ""; foreach (var ele in qpath) { qpaths += ele.ToString(); } //Debug.Log("BING_MAP_RENDER qpaths"); string url = @"http://t.ssl.ak.dynamic.tiles.virtualearth.net/comp/ch/" + qpaths + @"?mkt=pl-PL&it=A,G,RL&shading=hill&n=z&og=268&c4w=1"; string name = "BING." + z + "." + x + "." + y + ".png"; string filePath = GISparser.webImagesPath + name; byte[] fileData = null; //Debug.Log("BING_MAP_RENDER WebClient next"); using (WebClient client = new WebClient()) { if (File.Exists(filePath)) { //Debug.Log("BING_MAP_RENDER Exists: "+ filePath); fileData = GISlayer.bingPath(filePath); //Debug.Log("BING_MAP_RENDER Exists: udalo sie"); } else { //Debug.Log("BING_MAP_RENDER not exists"); //client.DownloadFile(new Uri(url), filePath);//tu jest problem //Debug.Log("BING_MAP_RENDER after download"); try { client.DownloadFile(new Uri(url), filePath); } catch (Exception ex) { Debug.Log(ex.Message); if (File.Exists(filePath)) { File.Delete(filePath); } } if (File.Exists(filePath)) { //Debug.Log("BING_MAP_RENDER exists now"); fileData = GISlayer.bingPath(filePath); } else { Debug.Log("Błąd sieci, nie można pobrać pliku png"); } } } //Debug.Log("BING_MAP_RENDER koniec"); return(fileData); }
/*private void ExecuteInForeground(Thread main) * { * while(true) * { * try * { * if (main.ThreadState == ThreadState.AbortRequested) { Debug.Log("AbortRequested - Aplikacja zamknieta"); return; } * * Vector3Int element; * try * { * element = toProcessChunks[0]; * } catch * { * continue; * } * toProcessChunks.RemoveAt(0); * //_pool.Release(); * if (element.x >= ch1.x && element.y >= ch1.y && element.x < ch2.x && element.y < ch2.y) * { * int size = (1 << zoom); * double length = 256.0 / (double)size; * var tex = generateTexture(element.x, element.y,zoom); * //_pool.WaitOne(); * toAddChunks.Add(new textureContainer(element,tex)); * //_pool.Release(); * } * } catch * { * } * } * }*/ private Texture2D generateTexture(int cx, int cy, int z) { Texture2D tex = new Texture2D(256, 256); var path = GISparser.getQuadPath(new Vector2Int(cx, cy), z); var waysList = qt.getObjects(path); //return GISparser.downloadBINGpng(cx,cy,z); Vector2d chunkLow = new Vector2d(((double)(cx) / (double)(1 << z)) * 256.0, ((double)(cy) / (double)(1 << z)) * 256.0); Vector2d chunkHigh = new Vector2d(((double)(cx + 1) / (double)(1 << z)) * 256.0, ((double)(cy + 1) / (double)(1 << z)) * 256.0); var c = Color.white; for (int x = 0; x < 256; ++x) { for (int y = 0; y < 256; ++y) { tex.SetPixel(x, y, c); } } foreach (var way in waysList) { //lineChecker(Vector2d l1, Vector2d l2, Vector2d p, float thickness); //drawWay(ref tex, way, chunkLow, chunkHigh); drawWayOptimal(ref tex, way, chunkLow, chunkHigh); } if (false) { Color bor = Color.gray; for (int i = 0; i < 256; ++i) { tex.SetPixel(0, i, bor); tex.SetPixel(255, i, bor); tex.SetPixel(i, 0, bor); tex.SetPixel(i, 255, bor); } } return(tex); }
// Use this for initialization void Start() { rend = GetComponent <SpriteRenderer>(); _pool = new Semaphore(1, 1); int x = 0; int y = 0; int z = 1; var qpath = GISparser.getQuadPath(x, y, z); string qpaths = ""; foreach (var ele in qpath) { qpaths += ele.ToString(); } string url = @"http://t.ssl.ak.dynamic.tiles.virtualearth.net/comp/ch/" + qpaths + @"?mkt=pl-PL&it=A,G,RL&shading=hill&n=z&og=268&c4w=1"; string name = "BING." + z + "." + x + "." + y + ".png"; string filePath = GISparser.webImagesPath + name; byte[] fileData; using (WebClient client = new WebClient()) { if (File.Exists(filePath)) { //fileData = File.ReadAllBytes(filePath); Bitmap original = new Bitmap(filePath); Bitmap clone = new Bitmap(original.Width, original.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); //var arr = GISlayer.ImageToByte2(clone); //var arr = GISlayer.getImageRasterBytes(clone, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); Texture2D tex = new Texture2D(256, 256, TextureFormat.RGBA32, false); //Texture2D tex = new Texture2D(16, 16, TextureFormat.PVRTC_RGBA4, false); /*for (int xx = 0; xx < tex.width; ++xx) * { * for (int yy = 0; yy < tex.height; ++yy) * { * tex.SetPixel(xx, yy, randomColor()); * } * } * tex.SetPixel(0, 0, UnityEngine.Color.black); * tex.SetPixel(1, 0, UnityEngine.Color.black); * tex.SetPixel(2, 0, UnityEngine.Color.black); * tex.filterMode = FilterMode.Point;*/ var arr2 = GISlayer.bingPath(filePath); tex.LoadRawTextureData(arr2); tex.filterMode = FilterMode.Point; tex.Apply(); /*fileData = File.ReadAllBytes(filePath); * tex = new Texture2D(2, 2); * tex.LoadImage(fileData);*/ Sprite newSprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0, 0)); rend.sprite = newSprite; Debug.Log("obrazek"); //tex.LoadImage(fileData); } else { Debug.Log("Błąd sieci, nie można pobrać pliku png"); } } }