Ejemplo n.º 1
0
 /// <summary>
 /// Called when downloading has ended.
 /// </summary>
 /// <param name="wd">The download.</param>
 private static void OnDownloadEnded(WebDownloadWithReferer wd)
 {
     if (DownloadEnded != null) {
         DownloadEnded(wd);
     }
 }
Ejemplo n.º 2
0
        public void GetTexture(DrawArgs drawArgs)
        {
            this.drawArgs = drawArgs;

            /*if(debug) {
                //generate a DEBUG tile with metadata
                MemoryStream ms;
                //debug
                Bitmap b = new Bitmap(GeoportailTilesLayer.PixelsPerTile,
                                      GeoportailTilesLayer.PixelsPerTile);
                System.Drawing.Imaging.ImageFormat imageFormat;

                alMetaData.Add("ww rowXcol : " + row.ToString() + "x" + col.ToString());
                alMetaData.Add("geoLevel : " + level.ToString());

                imageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
                b = DecorateBitmap(b, font, brush, alMetaData);

                ms = new MemoryStream();
                b.Save(ms, imageFormat);
                ms.Position = 0;
                this.texture = TextureLoader.FromStream(drawArgs.device, ms);
                ms.Close();
                ms = null;
                b.Dispose();
                b = null;
            }
            else {*/
                //load a tile from file OR download it if not cached
                //Change that to have a territory/Layer/level tree instead
                string territoryDir = CreateTerritoryDir(geoForm.WorldWindow.Cache.CacheDirectory,layer.Territory.Name);
                string layerDir = CreateLayerDir(territoryDir, layer.Name);
                string levelDir = CreateLevelDir(layerDir,level.Level);

                textureName = GetTextureName(levelDir, row, col);

                if(File.Exists(textureName) == true) {
                    this.texture = TextureLoader.FromFile(drawArgs.device, textureName);
                }
                else {
                    string textureUrl = "http://cimg.geoportail.fr/ImageX/ImageX.dll?image?cache=true&transparent=true&type=jpg&l=" + level.Level.ToString() + "&tx=" + col.ToString() + "&ty=" + row.ToString() + "&ts=384&fill=ffffff&quality=60&layers=" + formatComponents() + layer.CopyrightNoticeUrl;

                    download = new WebDownloadWithReferer(textureUrl);
                    download.DownloadType = DownloadType.Unspecified;
                    download.SavedFilePath = textureName + ".tmp"; //?
                    download.CompleteCallback += new DownloadCompleteHandler(DownloadComplete);
                    download.BackgroundDownloadFile();
                }
            //}
        }
Ejemplo n.º 3
0
        private void DownloadComplete(WebDownloadWithReferer downloadInfo)
        {
            try {
                downloadInfo.Verify();

                // Rename temp file to real name
                File.Delete(textureName);
                File.Move(downloadInfo.SavedFilePath, textureName);

                this.texture = TextureLoader.FromFile(drawArgs.device, textureName);
            }
            catch(System.Net.WebException caught) {
                System.Net.HttpWebResponse response = caught.Response as System.Net.HttpWebResponse;
                if(response!=null && response.StatusCode==System.Net.HttpStatusCode.NotFound) {
                    using(File.Create(textureName + ".txt")) {
                     }
                    return;
                }

            }
            catch {
                using(File.Create(textureName + ".txt")) {
                 }
                if(File.Exists(downloadInfo.SavedFilePath))
                    File.Delete(downloadInfo.SavedFilePath);
            }
            finally {
                download.IsComplete = true;
            }
        }
Ejemplo n.º 4
0
 public void Dispose()
 {
     if(texture != null) {
         texture.Dispose();
         texture = null;
     }
     if(download != null) {
         download.Dispose();
         download = null;
     }
     if(vertices != null) {
         vertices = null;
     }
     if(indices != null) {
         indices = null;
     }
     if(downloadRectangle != null) {
         downloadRectangle = null;
     }
     GC.SuppressFinalize(this);
 }