Example #1
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);
        }
Example #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()
            }
        }