Пример #1
0
 public void Dispose()
 {
     //LibSys.StatusBar.Trace("Tile:Dispose() baseName=" + m_baseName);
     if(m_tileBackdrop != null)
     {
         TileCache.BackdropMarkUnused(m_baseName);
         m_tileBackdrop = null;
     }
     if(m_tileFeatures != null)
     {
         TileCache.FeaturesMarkUnused(m_baseName);
         m_tileFeatures = null;
     }
 }
Пример #2
0
        public void init()
        {
            GeoCoord topLeft = m_topLeft.Clone();
            topLeft.Normalize();
            GeoCoord bottomRight = m_bottomRight.Clone();
            bottomRight.Normalize();

            int iLat = (int)Math.Ceiling(topLeft.Lat);
            int iLng = (int)Math.Floor(topLeft.Lng);
            m_siLng = iLng;
            m_siLat = iLat;
            if(m_tileScale.Equals("z"))
            {
                // HACK:
                // compensate for the shift in z-level tiles
                // (their names point to the center, not the top left corner:
                iLat -= 2;
                iLng += 2;
            }
            string latDir = iLat < 0 ? "s" : "n";
            string lngDir = iLng < 0 ? "w" : "e";
            iLat = Math.Abs(iLat);
            iLng = Math.Abs(iLng);

            switch(m_tileScale)
            {
                case "w":
                    m_level = 0;
                    m_baseName = "world_good";
                    break;
                case "y":
                    m_level = 1;
                    if(iLat == 60 && latDir.Equals("s"))
                    {
                        m_tileBackdrop = null;
                        return;
                    }
                    else
                    {
                        string sLng = ("" + iLng).PadLeft(3,'0');
                        string sLat = "" + iLat;
                        m_baseName = m_tileScale + sLng + lngDir + sLat + latDir;
                    }
                    break;
                case "x":
                    m_level = 2;
                    m_baseName = m_tileScale + iLng + lngDir + iLat + latDir;
                    break;
                case "z":
                    m_level = 3;
                    m_baseName = m_tileScale + iLng + lngDir + iLat + latDir;
                    break;
                default:
                    m_level = 4;
                    iLat = (int)Math.Floor(bottomRight.Lat);
                    iLng = (int)Math.Ceiling(bottomRight.Lng);
                    if(iLng == -180)
                    {
                        // edge correction needed around Lng=180
                        iLng = 180;
                    }
                    latDir = iLat < 0 ? "s" : "n";
                    lngDir = iLng <= 0 ? "w" : "e";
                    m_siLng = iLng;
                    m_siLat = iLat;
                    iLat = Math.Abs(iLat);
                    iLng = Math.Abs(iLng);
                    m_baseName = m_tileScale + iLng + lngDir + iLat + latDir;
                    break;
                case "a":
                    m_level = 5;
                    iLat = (int)Math.Floor(bottomRight.Lat);
                    iLng = (int)Math.Ceiling(bottomRight.Lng);
                    if(iLng == -180)
                    {
                        // edge correction needed around Lng=180
                        iLng = 180;
                    }
                    latDir = iLat < 0 ? "s" : "n";
                    lngDir = iLng <= 0 ? "w" : "e";
                    m_siLng = iLng;
                    m_siLat = iLat;
                    iLat = Math.Abs(iLat);
                    iLng = Math.Abs(iLng);
                    // figure out quadrant and correct the tile scale letter:
                    double ty = topLeft.Lat - Math.Floor(topLeft.Lat);
                    double tx = topLeft.Lng - Math.Floor(topLeft.Lng);

                    if(ty > 0.01d && tx > 0.01d)
                    {
                        m_tileScale = "d";
                        m_aShiftX = 1;
                        m_aShiftY = 1;
                    }
                    else if(tx > 0.01d)
                    {
                        m_tileScale = "b";
                        m_aShiftX = 1;
                    }
                    else if(ty > 0.01d)
                    {
                        m_tileScale = "c";
                        m_aShiftY = 1;
                    }
                    m_baseName = m_tileScale + iLng + lngDir + iLat + latDir;
                    break;
            }

            if(MayUseSubstitute)
            {
                // calculate substitute backdrop parameters, just in case real backdrop will be missing:
                int substLat = (int)Math.Floor(bottomRight.Lat);
                if(substLat >= 0)
                {
                    substLat = substLat / 10 + 1;
                }
                else if(substLat < 0 && substLat >= -10)
                {
                    substLat = 0;
                    latDir = "n";
                }
                else
                {
                    substLat = (int)Math.Ceiling(bottomRight.Lat + 0.0001d);
                    substLat = substLat / 10;
                }
                substLat = substLat * 10;

                int substLng = (int)Math.Ceiling(bottomRight.Lng);
                if(substLng > 0)
                {
                    substLng = (int)Math.Floor(topLeft.Lng);
                    substLng = substLng / 10;
                }
                else if(substLng == 0)
                {
                    // edge correction needed around Lng=0
                    substLng = 1;
                }
                else if(substLng == -180)
                {
                    // edge correction needed around Lng=180
                    substLng = 17;
                }
                else
                {
                    substLng = substLng / 10 - 1;
                }
                substLng = substLng * 10;

                m_substLng = substLng;
                m_substLat = substLat;
                substLat = Math.Abs(substLat);
                substLng = Math.Abs(substLng);
                m_substituteName = "x" + substLng + lngDir + substLat + latDir;
            #if DEBUG
                LibSys.StatusBar.Trace("Tile::init() m_substituteName=" + m_substituteName);
                LibSys.StatusBar.Trace("siLng=" + m_siLng + " m_substLng=" + m_substLng + " siLat=" + m_siLat + " m_substLat=" + m_substLat);
            #endif
            }

            //LibSys.StatusBar.Trace("Tile:init() baseName=" + m_baseName);
            m_tileBackdrop = TileCache.getBackdrop(this, m_baseName);		// may be Empty, never null
            if(m_tileBackdrop.IsEmpty)
            {
                // unlikely, but we may know immediately that we need to use substitute, if feasible:
                if(MayUseSubstitute)
                {
                    // get substitute backdrop:
                    m_useSubstitute = true;
                    //LibSys.StatusBar.Trace("Tile::init() - requesting backdrop substitute " + m_substituteName);
                    m_tileBackdrop = TileCache.getBackdrop(this, m_substituteName);	// may be Empty, never null
                    if(m_tileBackdrop.IsEmpty)
                    {
                        m_isEmpty = true;
                    }
                    else if(m_tileBackdrop.HasImage)
                    {
                        CalculateSubstituteRectangle();  // may instead set IsEmpty
                    }
                    // else wait for arrival...
                }
                else
                {
                    m_isEmpty = true;
                }
            }
            m_tileFeatures = TileCache.getFeatures(this, m_baseName);		// may be Empty, never null
            if(m_tileFeatures.IsEmpty)
            {
                // unlikely, but we may know immediately that we need to use substitute, if feasible:
                if(MayUseSubstitute)
                {
                    // get substitute features:
            #if DEBUG
                    LibSys.StatusBar.Trace("Tile::init() - requesting features substitute " + m_substituteName);
            #endif
                    m_tileFeatures = TileCache.getFeatures(this, m_substituteName);	// may be Empty, never null
                    if(m_tileFeatures.HasLoaded)
                    {
                        CreateFeaturesSubset();
                        ProvokeFeaturesPutOnMap();		// provoke PutOnMap on the next Tile_Paint()
                    }
                    else
                    {
            #if DEBUG
                        LibSys.StatusBar.Trace("Tile::init() - " + m_baseName + " - features hasn't loaded -  nothing to copy...");
            #endif
                    }
                    // wait for arrival...
                }
            }
            else
            {
                ProvokeFeaturesPutOnMap();		// provoke PutOnMap on the next Tile_Paint()
            }
        }
Пример #3
0
 public void backdropArrived(Backdrop backdrop)
 {
     // the backdrop may arrive when this tile has been phased out due to TileSet.ReTile()
     // this tile then hangs around as a means to pass backdrop to TileSet, which is supposed
     // to find appropriate location for the backdrop.
     #if DEBUG
     LibSys.StatusBar.Trace("Tile::backdropArrived() - backdrop=" + backdrop);
     #endif
     m_tileBackdrop = backdrop;
     if(m_tileBackdrop.IsEmpty)
     {
         // more likely, need to use substitute is discovered here.
         if(MayUseSubstitute && !UseSubstitute)
         {
             // get substitute backdrop:
             m_useSubstitute = true;
     #if DEBUG
             LibSys.StatusBar.Trace("Tile::backdropArrived() - requesting substitute " + m_substituteName);
     #endif
             m_tileBackdrop = TileCache.getBackdrop(this, m_substituteName);	// may be Empty, never null
             if(m_tileBackdrop.IsEmpty)
             {
     #if DEBUG
                 LibSys.StatusBar.Trace("Tile::backdropArrived() - got empty substitute " + m_substituteName);
     #endif
                 m_isEmpty = true;
             }
             else if(m_tileBackdrop.HasImage)
             {
     #if DEBUG
                 LibSys.StatusBar.Trace("Tile::backdropArrived() - got good substitute " + m_tileBackdrop);
     #endif
                 CalculateSubstituteRectangle();  // may instead set IsEmpty
             }
             else
             {
     #if DEBUG
                 LibSys.StatusBar.Trace("Tile::backdropArrived() - will wait for substitute ");
     #endif
                 return;		// waiting for substitute backdrop image to arrive
             }
         }
         else
         {
             m_isEmpty = true;
         }
     }
     else if(UseSubstitute && m_tileBackdrop.HasImage)
     {
         CalculateSubstituteRectangle();  // may instead set IsEmpty
     }
     m_tileSet.tileBackdropArrived(this);
 }
Пример #4
0
 public static void AddBackdrop(string baseName, Backdrop b)
 {
     try
     {
         m_backdropCache.Add(baseName, b);
     }
     catch (Exception e)
     {
     }
 }
Пример #5
0
        public static Backdrop getBackdrop(Tile tile, string baseName)
        {
            string imageFileName = Path.Combine(m_mapsPath, baseName + imageExt);

            Backdrop ret = null;
            try
            {
                if(m_backdropCache.ContainsKey(baseName))
                {
                    ret = (Backdrop)m_backdropCache[baseName];	// may be IsEmpty, if proven that can't download
                    ret.MarkUsed();
            #if DEBUG
                    LibSys.StatusBar.Trace("OK: TileCache:getBackdrop() - tile '" + baseName + "' - found in cache - " + ret);
            #endif
                    return ret;
                }

                bool loadedFromFile = false;
                if(!Project.reloadRefresh && File.Exists(imageFileName))
                {
                    try
                    {
                        ret = new Backdrop(imageFileName, baseName, true);
            #if DEBUG
                        LibSys.StatusBar.Trace("OK: TileCache:getBackdrop() - tile '" + baseName + "' - loaded from file");
            #endif
                        AddBackdrop(baseName, ret);
                        loadedFromFile = true;
                    }
                    catch {}
                }

                if(!loadedFromFile && m_mappingServers.Count > 0)
                {
                    string imageUrl = getFileUrl(tile, baseName, imageFileName);

                    if(imageUrl == null)
                    {
                        ret = new Backdrop(null, baseName, true);	// doFill with null name makes it Empty
                        AddBackdrop(baseName, ret);
                        return ret;
                    }

                    if(!m_backdropCache.ContainsKey(baseName))
                    {
                        ret = new Backdrop(imageFileName, baseName, false);		// fill later
                        AddBackdrop(baseName, ret);
                        DownloadThread dt = new DownloadThread();
                        dt.DownloadUrl = imageUrl;
                        dt.tile = tile;
                        dt.baseName = baseName;
                        dt.fileName = imageFileName;
                        dt.CompleteCallback += new DownloadCompleteHandler( imageDownloadCompleteCallback );
                        dt.ProgressCallback += new DownloadProgressHandler( imageDownloadProgressCallback );
                        dt.addMonitoredMethod = new AddMonitoredMethod(ProgressMonitor.addMonitored);

                        //add dt worker method to the thread pool / queue a task
                        //Project.threadPool.PostRequest (new WorkRequestDelegate (dt.Download));
                        ThreadPool2.QueueUserWorkItem (new WaitCallback (dt.Download), baseName);

            #if DEBUG
                        LibSys.StatusBar.Trace("OK: TileCache:getBackdrop() - tile '" + baseName + "' - loading remote from " + imageUrl);
            #endif
                    }
            #if DEBUG
                    else
                    {
                        LibSys.StatusBar.Trace("OK: TileCache:getBackdrop() - tile '" + baseName + "' - already in cache");
                    }
            #endif
                }
            }
            catch (Exception e)
            {
                LibSys.StatusBar.Error("file '" + imageFileName + "' failed to load: " + e.Message);
            }

            // whatever happened before, returning null is not an option.
            if(ret == null)
            {
                ret = new Backdrop(null, baseName, true);	// doFill with null name makes it Empty
                AddBackdrop(baseName, ret);
            }
            return ret;
        }
Пример #6
0
 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;
     }
 }
Пример #7
0
 public void backdropArrived(Backdrop backdrop)
 {
     // the backdrop may arrive when this tile has been phased out due to TileSet.ReTile()
     // this tile then hangs around as a means to pass backdrop to TileSet, which is supposed
     // to find appropriate location for the backdrop.
     #if DEBUG
     LibSys.StatusBar.Trace("Tile::backdropArrived() - backdrop=" + backdrop);
     #endif
     m_tileBackdrop = backdrop;
     if(m_tileBackdrop.IsEmpty)
     {
         m_isEmpty = true;
     }
     m_tileSet.tileBackdropArrived(this);
 }