Ejemplo n.º 1
0
 public TileTerra(TileSetTerra ts, Scale tileScale, GeoCoord topLeft, GeoCoord bottomRight)
 {
     m_tileSet     = ts;
     m_tileScale   = tileScale;
     m_topLeft     = topLeft.Clone();
     m_bottomRight = bottomRight.Clone();
     //LibSys.StatusBar.Trace("TileTerra() topLeft=" + m_topLeft.ToString() + " bottomRight=" + m_bottomRight.ToString());
 }
Ejemplo n.º 2
0
        // Use index from TileSetTerra.m_scale to define desired scale.
        // if scaleIndexHint==-1 the elev is used to find the best matching scale. See TileSetTerra.calcScaleIndex for more.

        public TileSetTerraLayout(GeoCoord coverageTopLeft, GeoCoord coverageBottomRight, double elev, int scaleIndexHint, Theme theme, bool themeIsColor)
        {
            m_coverageTopLeft     = coverageTopLeft;
            m_coverageBottomRight = coverageBottomRight;
            m_curTheme            = theme;
            m_curThemeColor       = themeIsColor;

            double lng = (coverageTopLeft.Lng + coverageBottomRight.Lng) / 2;
            double lat = (coverageTopLeft.Lat + coverageBottomRight.Lat) / 2;

            m_coverageCenter = new GeoCoord(lng, lat);

            int   scaleIndex;
            Scale tileScale;

            isValid     = TileSetTerra.calcScaleIndex(m_curTheme, elev, scaleIndexHint, out scaleIndex, out tileScale);
            m_tileScale = tileScale;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// this is complete cut-and-paste from the above - keep them in sync
        /// </summary>
        /// <param name="obj"></param>
        private void listQueryDisconnected(Hashtable list)
        {
            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 (!list.ContainsKey(baseName))
                    {
                        list.Add(baseName, null);
                    }
#if DEBUG
                    //LibSys.StatusBar.Trace("[" + vvv + "," + hhh + "]  " + baseName);
                    //LibSys.StatusBar.Trace("        -- topLeft=" + tileTopLeft + " bottomRight=" + tileBottomRight);
#endif
                    yy--;
                }
                xx++;
            }
        }
Ejemplo n.º 4
0
        /// <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");
                }
            }
        }