示例#1
0
        /// <summary>
        /// Updates this layer (background)
        /// </summary>
        public virtual void Update(DrawArgs drawArgs)
        {
            if (m_isResetingCache)
            {
                return;
            }

            try {
                double tileSize = North - South;

                if (!isInitialized)
                {
                    if (DrawArgs.Camera.ViewRange * 0.5f < Angle.FromDegrees(QuadTileSet.TileDrawDistance * tileSize) && MathEngine.SphericalDistance(CenterLatitude, CenterLongitude, DrawArgs.Camera.Latitude, DrawArgs.Camera.Longitude) < Angle.FromDegrees(QuadTileSet.TileDrawSpread * tileSize * 1.25f) &&
                        DrawArgs.Camera.ViewFrustum.Intersects(BoundingBox))
                    {
                        Initialize();
                    }
                }

                if (isInitialized && World.Settings.VerticalExaggeration != verticalExaggeration || m_CurrentOpacity != QuadTileSet.Opacity ||
                    QuadTileSet.RenderStruts != renderStruts)
                {
                    CreateTileMesh();
                }

                if (isInitialized)
                {
                    if (DrawArgs.Camera.ViewRange < Angle.FromDegrees(QuadTileSet.TileDrawDistance * tileSize) && MathEngine.SphericalDistance(CenterLatitude, CenterLongitude, DrawArgs.Camera.Latitude, DrawArgs.Camera.Longitude) < Angle.FromDegrees(QuadTileSet.TileDrawSpread * tileSize) &&
                        DrawArgs.Camera.ViewFrustum.Intersects(BoundingBox))
                    {
                        if (northEastChild == null || northWestChild == null || southEastChild == null ||
                            southWestChild == null)
                        {
                            ComputeChildren(drawArgs);
                        }

                        if (northEastChild != null)
                        {
                            northEastChild.Update(drawArgs);
                        }

                        if (northWestChild != null)
                        {
                            northWestChild.Update(drawArgs);
                        }

                        if (southEastChild != null)
                        {
                            southEastChild.Update(drawArgs);
                        }

                        if (southWestChild != null)
                        {
                            southWestChild.Update(drawArgs);
                        }
                    }
                    else
                    {
                        if (northWestChild != null)
                        {
                            northWestChild.Dispose();
                            northWestChild = null;
                        }

                        if (northEastChild != null)
                        {
                            northEastChild.Dispose();
                            northEastChild = null;
                        }

                        if (southEastChild != null)
                        {
                            southEastChild.Dispose();
                            southEastChild = null;
                        }

                        if (southWestChild != null)
                        {
                            southWestChild.Dispose();
                            southWestChild = null;
                        }
                    }
                }

                if (isInitialized)
                {
                    if (DrawArgs.Camera.ViewRange / 2 > Angle.FromDegrees(QuadTileSet.TileDrawDistance * tileSize * 1.5f) ||
                        MathEngine.SphericalDistance(CenterLatitude, CenterLongitude, DrawArgs.Camera.Latitude, DrawArgs.Camera.Longitude) > Angle.FromDegrees(QuadTileSet.TileDrawSpread * tileSize * 1.5f))
                    {
                        if (Level != 0 ||
                            (Level == 0 && !QuadTileSet.AlwaysRenderBaseTiles))
                        {
                            this.Dispose();
                        }
                    }
                }
            }
            catch {}
        }
示例#2
0
        public override void Update(DrawArgs drawArgs)
        {
            if (!isInitialized)
            {
                Initialize(drawArgs);
            }

            if (m_effectPath != null && m_effect == null)
            {
                string errs = string.Empty;
                m_effect = Effect.FromFile(DrawArgs.Device, m_effectPath, null, "", ShaderFlags.None, m_effectPool, out errs);

                if (errs != null && errs != string.Empty)
                {
                    Log.Write(Log.Levels.Warning, "Could not load effect " + m_effectPath + ": " + errs);
                    Log.Write(Log.Levels.Warning, "Effect has been disabled.");
                    m_effectPath = null;
                    m_effect     = null;
                }
            }

            if (ImageStores[0].LevelZeroTileSizeDegrees < 180)
            {
                // Check for layer outside view
                double vrd          = DrawArgs.Camera.ViewRange.Degrees;
                double latitudeMax  = DrawArgs.Camera.Latitude.Degrees + vrd;
                double latitudeMin  = DrawArgs.Camera.Latitude.Degrees - vrd;
                double longitudeMax = DrawArgs.Camera.Longitude.Degrees + vrd;
                double longitudeMin = DrawArgs.Camera.Longitude.Degrees - vrd;
                if (latitudeMax < m_south || latitudeMin > m_north || longitudeMax < m_west || longitudeMin > m_east)
                {
                    return;
                }
            }

            if (DrawArgs.Camera.ViewRange * 0.5f >
                Angle.FromDegrees(TileDrawDistance * ImageStores[0].LevelZeroTileSizeDegrees))
            {
                lock (m_topmostTiles.SyncRoot)
                {
                    foreach (QuadTile qt in m_topmostTiles.Values)
                    {
                        qt.Dispose();
                    }
                    m_topmostTiles.Clear();
                    ClearDownloadRequests();
                }

                return;
            }

            RemoveInvisibleTiles(DrawArgs.Camera);
            try
            {
                int middleRow = MathEngine.GetRowFromLatitude(DrawArgs.Camera.Latitude, ImageStores[0].LevelZeroTileSizeDegrees);
                int middleCol = MathEngine.GetColFromLongitude(DrawArgs.Camera.Longitude, ImageStores[0].LevelZeroTileSizeDegrees);

                double middleSouth = -90.0f + middleRow * ImageStores[0].LevelZeroTileSizeDegrees;
                double middleNorth = -90.0f + middleRow * ImageStores[0].LevelZeroTileSizeDegrees + ImageStores[0].LevelZeroTileSizeDegrees;
                double middleWest  = -180.0f + middleCol * ImageStores[0].LevelZeroTileSizeDegrees;
                double middleEast  = -180.0f + middleCol * ImageStores[0].LevelZeroTileSizeDegrees + ImageStores[0].LevelZeroTileSizeDegrees;

                double middleCenterLat = 0.5f * (middleNorth + middleSouth);
                double middleCenterLon = 0.5f * (middleWest + middleEast);

                int tileSpread = 4;
                for (int i = 0; i < tileSpread; i++)
                {
                    for (double j = middleCenterLat - i * ImageStores[0].LevelZeroTileSizeDegrees; j < middleCenterLat + i * ImageStores[0].LevelZeroTileSizeDegrees; j += ImageStores[0].LevelZeroTileSizeDegrees)
                    {
                        for (double k = middleCenterLon - i * ImageStores[0].LevelZeroTileSizeDegrees; k < middleCenterLon + i * ImageStores[0].LevelZeroTileSizeDegrees; k += ImageStores[0].LevelZeroTileSizeDegrees)
                        {
                            int  curRow = MathEngine.GetRowFromLatitude(Angle.FromDegrees(j), ImageStores[0].LevelZeroTileSizeDegrees);
                            int  curCol = MathEngine.GetColFromLongitude(Angle.FromDegrees(k), ImageStores[0].LevelZeroTileSizeDegrees);
                            long key    = ((long)curRow << 32) + curCol;

                            QuadTile qt = (QuadTile)m_topmostTiles[key];
                            if (qt != null)
                            {
                                qt.Update(drawArgs);
                                continue;
                            }

                            // Check for tile outside layer boundaries
                            double west = -180.0f + curCol * ImageStores[0].LevelZeroTileSizeDegrees;
                            if (west > m_east)
                            {
                                continue;
                            }

                            double east = west + ImageStores[0].LevelZeroTileSizeDegrees;
                            if (east < m_west)
                            {
                                continue;
                            }

                            double south = -90.0f + curRow * ImageStores[0].LevelZeroTileSizeDegrees;
                            if (south > m_north)
                            {
                                continue;
                            }

                            double north = south + ImageStores[0].LevelZeroTileSizeDegrees;
                            if (north < m_south)
                            {
                                continue;
                            }

                            qt = new QuadTile(south, north, west, east, 0, this);
                            if (DrawArgs.Camera.ViewFrustum.Intersects(qt.BoundingBox))
                            {
                                lock (m_topmostTiles.SyncRoot)
                                    m_topmostTiles.Add(key, qt);
                                qt.Update(drawArgs);
                            }
                        }
                    }
                }
            }
            catch (System.Threading.ThreadAbortException)
            {
            }
            catch (Exception caught)
            {
                Log.Write(caught);
            }
        }
示例#3
0
        public override void Update(DrawArgs drawArgs)
        {
            if (!isInitialized)
                Initialize(drawArgs);

            if (m_effectPath != null && m_effect == null)
            {
                string errs = string.Empty;
                m_effect = Effect.FromFile(DrawArgs.Device, m_effectPath, null, "", ShaderFlags.None, m_effectPool, out errs);

                if (errs != null && errs != string.Empty)
                {
                    Log.Write(Log.Levels.Warning, "Could not load effect " + m_effectPath + ": " + errs);
                    Log.Write(Log.Levels.Warning, "Effect has been disabled.");
                    m_effectPath = null;
                    m_effect = null;
                }
            }

            if (ImageStores[0].LevelZeroTileSizeDegrees < 180)
            {
                // Check for layer outside view
                double vrd = DrawArgs.Camera.ViewRange.Degrees;
                double latitudeMax = DrawArgs.Camera.Latitude.Degrees + vrd;
                double latitudeMin = DrawArgs.Camera.Latitude.Degrees - vrd;
                double longitudeMax = DrawArgs.Camera.Longitude.Degrees + vrd;
                double longitudeMin = DrawArgs.Camera.Longitude.Degrees - vrd;
                if (latitudeMax < m_south || latitudeMin > m_north || longitudeMax < m_west || longitudeMin > m_east)
                    return;
            }

            if (DrawArgs.Camera.ViewRange * 0.5f >
                    Angle.FromDegrees(TileDrawDistance * ImageStores[0].LevelZeroTileSizeDegrees))
            {
                lock (m_topmostTiles.SyncRoot)
                {
                    foreach (QuadTile qt in m_topmostTiles.Values)
                        qt.Dispose();
                    m_topmostTiles.Clear();
                    ClearDownloadRequests();
                }

                return;
            }

            RemoveInvisibleTiles(DrawArgs.Camera);
            try
            {
                int middleRow = MathEngine.GetRowFromLatitude(DrawArgs.Camera.Latitude, ImageStores[0].LevelZeroTileSizeDegrees);
                int middleCol = MathEngine.GetColFromLongitude(DrawArgs.Camera.Longitude, ImageStores[0].LevelZeroTileSizeDegrees);

                double middleSouth = -90.0f + middleRow * ImageStores[0].LevelZeroTileSizeDegrees;
                double middleNorth = -90.0f + middleRow * ImageStores[0].LevelZeroTileSizeDegrees + ImageStores[0].LevelZeroTileSizeDegrees;
                double middleWest = -180.0f + middleCol * ImageStores[0].LevelZeroTileSizeDegrees;
                double middleEast = -180.0f + middleCol * ImageStores[0].LevelZeroTileSizeDegrees + ImageStores[0].LevelZeroTileSizeDegrees;

                double middleCenterLat = 0.5f * (middleNorth + middleSouth);
                double middleCenterLon = 0.5f * (middleWest + middleEast);

                int tileSpread = 4;
                for (int i = 0; i < tileSpread; i++)
                {
                    for (double j = middleCenterLat - i * ImageStores[0].LevelZeroTileSizeDegrees; j < middleCenterLat + i * ImageStores[0].LevelZeroTileSizeDegrees; j += ImageStores[0].LevelZeroTileSizeDegrees)
                    {
                        for (double k = middleCenterLon - i * ImageStores[0].LevelZeroTileSizeDegrees; k < middleCenterLon + i * ImageStores[0].LevelZeroTileSizeDegrees; k += ImageStores[0].LevelZeroTileSizeDegrees)
                        {
                            int curRow = MathEngine.GetRowFromLatitude(Angle.FromDegrees(j), ImageStores[0].LevelZeroTileSizeDegrees);
                            int curCol = MathEngine.GetColFromLongitude(Angle.FromDegrees(k), ImageStores[0].LevelZeroTileSizeDegrees);
                            long key = ((long)curRow << 32) + curCol;

                            QuadTile qt = (QuadTile)m_topmostTiles[key];
                            if (qt != null)
                            {
                                qt.Update(drawArgs);
                                continue;
                            }

                            // Check for tile outside layer boundaries
                            double west = -180.0f + curCol * ImageStores[0].LevelZeroTileSizeDegrees;
                            if (west > m_east)
                                continue;

                            double east = west + ImageStores[0].LevelZeroTileSizeDegrees;
                            if (east < m_west)
                                continue;

                            double south = -90.0f + curRow * ImageStores[0].LevelZeroTileSizeDegrees;
                            if (south > m_north)
                                continue;

                            double north = south + ImageStores[0].LevelZeroTileSizeDegrees;
                            if (north < m_south)
                                continue;

                            qt = new QuadTile(south, north, west, east, 0, this);
                            if (DrawArgs.Camera.ViewFrustum.Intersects(qt.BoundingBox))
                            {
                                lock (m_topmostTiles.SyncRoot)
                                    m_topmostTiles.Add(key, qt);
                                qt.Update(drawArgs);
                            }
                        }
                    }
                }
            }
            catch (System.Threading.ThreadAbortException)
            {
            }
            catch (Exception caught)
            {
                Log.Write(caught);
            }
        }
示例#4
0
        public override void Update(DrawArgs drawArgs)
        {
            if (!Inited) {
                Initialize(drawArgs);
            }

            if (ImageStore.LevelZeroTileSizeDegrees < 180) {
                // Check for layer outside view
                double vrd = DrawArgs.Camera.ViewRange.Degrees;
                double latitudeMax = DrawArgs.Camera.Latitude.Degrees + vrd;
                double latitudeMin = DrawArgs.Camera.Latitude.Degrees - vrd;
                double longitudeMax = DrawArgs.Camera.Longitude.Degrees + vrd;
                double longitudeMin = DrawArgs.Camera.Longitude.Degrees - vrd;
                if (latitudeMax < m_south || latitudeMin > m_north || longitudeMax < m_west
                    || longitudeMin > m_east) {
                    return;
                }
            }

            if (DrawArgs.Camera.ViewRange*0.5f
                > Angle.FromDegrees(TileDrawDistance*ImageStore.LevelZeroTileSizeDegrees)) {
                lock (m_topmostTiles.SyncRoot) {
                    foreach (QuadTile qt in m_topmostTiles.Values) {
                        qt.Dispose();
                    }
                    m_topmostTiles.Clear();
                    ClearDownloadRequests();
                }

                return;
            }

            RemoveInvisibleTiles(DrawArgs.Camera);
            try {
                int middleRow = MathEngine.GetRowFromLatitude(DrawArgs.Camera.Latitude, ImageStore.LevelZeroTileSizeDegrees);
                int middleCol = MathEngine.GetColFromLongitude(DrawArgs.Camera.Longitude, ImageStore.LevelZeroTileSizeDegrees);

                double middleSouth = -90.0f + middleRow*ImageStore.LevelZeroTileSizeDegrees;
                double middleNorth = -90.0f + middleRow*ImageStore.LevelZeroTileSizeDegrees + ImageStore.LevelZeroTileSizeDegrees;
                double middleWest = -180.0f + middleCol*ImageStore.LevelZeroTileSizeDegrees;
                double middleEast = -180.0f + middleCol*ImageStore.LevelZeroTileSizeDegrees + ImageStore.LevelZeroTileSizeDegrees;

                double middleCenterLat = 0.5f*(middleNorth + middleSouth);
                double middleCenterLon = 0.5f*(middleWest + middleEast);

                int tileSpread = 4;
                for (int i = 0; i < tileSpread; i++) {
                    for (double j = middleCenterLat - i*ImageStore.LevelZeroTileSizeDegrees; j < middleCenterLat + i*ImageStore.LevelZeroTileSizeDegrees; j += ImageStore.LevelZeroTileSizeDegrees) {
                        for (double k = middleCenterLon - i*ImageStore.LevelZeroTileSizeDegrees; k < middleCenterLon + i*ImageStore.LevelZeroTileSizeDegrees; k += ImageStore.LevelZeroTileSizeDegrees) {
                            int curRow = MathEngine.GetRowFromLatitude(Angle.FromDegrees(j), ImageStore.LevelZeroTileSizeDegrees);
                            int curCol = MathEngine.GetColFromLongitude(Angle.FromDegrees(k), ImageStore.LevelZeroTileSizeDegrees);
                            long key = ((long) curRow << 32) + curCol;

                            QuadTile qt = (QuadTile) m_topmostTiles[key];
                            if (qt != null) {
                                qt.Update(drawArgs);
                                continue;
                            }

                            // Check for tile outside layer boundaries
                            double west = -180.0f + curCol*ImageStore.LevelZeroTileSizeDegrees;
                            if (west > m_east) {
                                continue;
                            }

                            double east = west + ImageStore.LevelZeroTileSizeDegrees;
                            if (east < m_west) {
                                continue;
                            }

                            double south = -90.0f + curRow*ImageStore.LevelZeroTileSizeDegrees;
                            if (south > m_north) {
                                continue;
                            }

                            double north = south + ImageStore.LevelZeroTileSizeDegrees;
                            if (north < m_south) {
                                continue;
                            }

                            qt = new QuadTile(south, north, west, east, 0, this);
                            if (DrawArgs.Camera.ViewFrustum.Intersects(qt.BoundingBox)) {
                                lock (m_topmostTiles.SyncRoot)
                                    m_topmostTiles.Add(key, qt);
                                qt.Update(drawArgs);
                            }
                        }
                    }
                }
            }
            catch (ThreadAbortException) {}
            catch (Exception caught) {
                Log.Write(caught);
            }
        }