public static event DownloadProgressHandler ProgressCallback; // needed for WebDownload, stays empty here public static void setMappingCacheLocation(string path) { Project.setMappingCacheLocation(path); m_mapsPath = Project.GetMapsTempPath(); TileCache.Clear(); // release all files TerraserverCache.setMappingCacheLocation(); }
public void init() { //LibSys.StatusBar.Trace("Tile:init() baseName=" + m_baseName); m_tileBackdrop = TerraserverCache.getBackdrop(this, m_baseName); // may be Empty, never null if (m_tileBackdrop.IsEmpty) { m_isEmpty = true; } }
public static void setMappingCacheLocation() { TerraserverCache.Clear(); m_landmarksDbFileName = Path.Combine(Project.GetTerraserverMapsBasePath(), "landmarksdb.xml"); }
/// <summary> /// this is somewhat cut-and-paste from its namesake from the TileSetTerra.cs keep them in sync /// </summary> /// <param name="obj"></param> private void _queryDisconnected(object obj) { int xStart = 0; int yStart = 0; int xEnd = 0; int yEnd = 0; int m_lastFactor = 0; GeoCoord covTL = m_coverageTopLeft; GeoCoord covBR = m_coverageBottomRight; double marginY = 0.0d; double marginX = 0.0d; double covTL_Lng = covTL.Lng - marginX; double covTL_Lat = covTL.Lat + marginY; double covBR_Lng = covBR.Lng + marginX; double covBR_Lat = covBR.Lat - marginY; int currentZone = TileSetTerra.getZone(m_coverageCenter); LonLatPt lonlat = new LonLatPt(); lonlat.Lat = covTL_Lat; lonlat.Lon = covTL_Lng; UtmPt utmptTL = Projection.LonLatPtToUtmNad83Pt(lonlat); // can be in other than currentZone lonlat.Lat = covBR_Lat; lonlat.Lon = covBR_Lng; UtmPt utmptBR = Projection.LonLatPtToUtmNad83Pt(lonlat); // can be in other than currentZone if (utmptTL.Zone != currentZone) { lonlat.Lat = m_coverageCenter.Lat; lonlat.Lon = m_coverageCenter.Lng; UtmPt utmptCam = Projection.LonLatPtToUtmNad83Pt(lonlat); // can be in other than currentZone double dX = utmptBR.X - utmptCam.X; utmptTL.X = utmptCam.X - dX; utmptTL.Zone = currentZone; } else if (utmptBR.Zone != currentZone) { lonlat.Lat = m_coverageCenter.Lat; lonlat.Lon = m_coverageCenter.Lng; UtmPt utmptCam = Projection.LonLatPtToUtmNad83Pt(lonlat); // can be in other than currentZone double dX = utmptCam.X - utmptTL.X; utmptBR.X = utmptCam.X + dX; utmptBR.Zone = currentZone; } int iScale = (int)m_tileScale; int metersPerPixel = (1 << ((int)iScale - 10)); int factor = 200 * metersPerPixel; if (xEnd - xStart == 0 || m_lastFactor == 0) { xStart = (int)Math.Floor(utmptTL.X / factor); yStart = (int)Math.Ceiling(utmptTL.Y / factor); xEnd = (int)Math.Ceiling(utmptBR.X / factor); yEnd = (int)Math.Floor(utmptBR.Y / factor); m_lastFactor = factor; } else { xStart = xStart * m_lastFactor / factor; yStart = yStart * m_lastFactor / factor; xEnd = xEnd * m_lastFactor / factor; yEnd = yEnd * m_lastFactor / factor; } int numTilesX = xEnd - xStart; int numTilesY = yStart - yEnd; int hCount = numTilesX; int vCount = numTilesY; UtmPt utmpt = new UtmPt(); utmpt.X = xStart * factor; utmpt.Y = yStart * factor; utmpt.Zone = currentZone; lonlat = Projection.UtmNad83PtToLonLatPt(utmpt); double topLeftLat = lonlat.Lat; double topLeftLng = lonlat.Lon; utmpt.X = (xStart + numTilesX) * factor; utmpt.Y = (yStart - numTilesY) * factor; lonlat = Projection.UtmNad83PtToLonLatPt(utmpt); double bottomRightLat = lonlat.Lat; double bottomRightLng = lonlat.Lon; int themeCode = getThemeCode(); int xx = (int)xStart; for (int hhh = 0; hhh < hCount; hhh++) { int yy = (int)yStart; for (int vvv = 0; vvv < vCount; vvv++) { utmpt.X = xx * factor; utmpt.Y = (yy) * factor; utmpt.Zone = currentZone; lonlat = Projection.UtmNad83PtToLonLatPt(utmpt); double tllat = lonlat.Lat; double tllng = lonlat.Lon; utmpt.X = (xx + 1) * factor; utmpt.Y = (yy - 1) * factor; lonlat = Projection.UtmNad83PtToLonLatPt(utmpt); double brlat = lonlat.Lat; double brlng = lonlat.Lon; GeoCoord tileTopLeft = new GeoCoord(tllng, tllat); GeoCoord tileBottomRight = new GeoCoord(brlng, brlat); String baseName = String.Format("T{0}-S{1}-Z{2}-X{3}-Y{4}", themeCode, (Int32)m_tileScale, currentZone, xx, (yy - 1)); if (TerraserverCache.TileNamesCollection != null) { if (!TerraserverCache.TileNamesCollection.ContainsKey(baseName)) { TerraserverCache.TileNamesCollection.Add(baseName, null); } } lock (m_duplicates) { if (!m_duplicates.ContainsKey(baseName)) { TerraserverCache.downloadIfMissing(baseName); m_duplicates.Add(baseName, null); } } #if DEBUG //LibSys.StatusBar.Trace("[" + vvv + "," + hhh + "] " + baseName); //LibSys.StatusBar.Trace(" -- topLeft=" + tileTopLeft + " bottomRight=" + tileBottomRight); #endif yy--; } xx++; } int totalCount = TileSetTerraLayout.DuplicatesCount; int newCount = ThreadPool2.WaitingCallbacks; if (newCount == 0) { LibSys.StatusBar.Trace("*Preload tiles: nothing to download - all " + totalCount + " tiles already in cache."); } else { if (newCount <= totalCount) { LibSys.StatusBar.Trace("*Preload tiles: trying to download " + newCount + " new of total " + totalCount + " tiles"); } else { LibSys.StatusBar.Trace("*Preload tiles: trying to download " + newCount + " new tiles"); } } }
private bool m_triedReload = false; // limits reload attempts public void Tile_Paint(object sender, PaintEventArgs e) { //LibSys.StatusBar.Trace("Tile_Paint(): " + m_baseName + " painting to " + e.ClipRectangle); try { Rectangle destRect = getFrameRectangle(); int www = 0; int hhh = 0; //LibSys.StatusBar.Trace("Tile_Paint(): tileImage=" + m_tileBackdrop); if (m_tileBackdrop != null && !m_tileBackdrop.IsEmpty && m_tileBackdrop.HasImage) { www = m_tileBackdrop.Width; hhh = m_tileBackdrop.Height; //LibSys.StatusBar.Trace("Tile_Paint(): tileImage w=" + www + " h=" + hhh); ImageAttributes imageAttr = new ImageAttributes(); ColorMatrix cm = new ColorMatrix(); Image image = m_tileBackdrop.Image; if (this.TileSet.isSecond && Project.makeWhitishTransparent) { Bitmap bmp = new Bitmap(image); // it takes way too long to make all whitish colors transparent. It may be possible to do it once and cache it though. // for (int r=253; r <= 255 ;r++) // { // for (int g=253; g <= 255 ;g++) // { // for (int b=253; b <= 255 ;b++) // { // make whitish areas transparent, so that aerial or color will be completely visible through the overlay: //bmp.MakeTransparent(Color.FromArgb(r, g, b)); bmp.MakeTransparent(Color.FromArgb(255, 255, 255)); // } // } // } image = bmp; } cm.Matrix00 = 1.0f; cm.Matrix11 = 1.0f; cm.Matrix22 = 1.0f; float opacity = (float)(TileSet.isSecond ? Project.terraLayerOpacity2 : Project.terraLayerOpacity); cm.Matrix33 = opacity; imageAttr.SetColorMatrix(cm); destRect = compensateForDraw(destRect); e.Graphics.DrawImage(image, destRect, 0, 0, www, hhh, System.Drawing.GraphicsUnit.Pixel, imageAttr); if (Project.drawGrid) { DrawGrid(e.Graphics, destRect, www, hhh, null); } } else if (m_isCottageCheese) { e.Graphics.DrawLine(Project.cameraPen, destRect.X, destRect.Y, destRect.X + destRect.Width, destRect.Y + destRect.Height); e.Graphics.DrawLine(Project.cameraPen, destRect.X + destRect.Width, destRect.Y, destRect.X, destRect.Y + destRect.Height); } else { if (m_tileBackdrop != null && m_tileBackdrop.ImageCorrupted) { DrawGrid(e.Graphics, destRect, www, hhh, "BAD JPG"); if (!m_triedReload) { m_triedReload = true; TerraserverCache.resetBackdrop(this, m_baseName); // try reloading } } else { DrawGrid(e.Graphics, destRect, www, hhh, "NOT LOADED"); } } } catch (Exception eee) { #if DEBUG LibSys.StatusBar.Error("TileTerra:Tile_Paint(): " + m_baseName + " " + eee); #endif } }