示例#1
0
        public ImageTileInfo GetImageTileInfo(int level, int row, int col, bool allowCache)
        {
            if (level >= m_numberLevels)
            {
                throw new ArgumentException("Level " + level.ToString() + " not available.");
            }

            string relativePath = String.Format(@"{0}\{1:D4}\{1:D4}_{2:D4}.{3}", level, row, col, m_imageFileExtension);

            if (m_dataDirectory != null)
            {
                // Search data directory first
                string rawFullPath = Path.Combine(m_dataDirectory, relativePath);
                if (File.Exists(rawFullPath))
                {
                    return(new ImageTileInfo(rawFullPath));
                }
            }

            // Try cache with default file extension
            string cacheFullPath = Path.Combine(m_cacheDirectory, relativePath);

            if (File.Exists(cacheFullPath))
            {
                return(new ImageTileInfo(cacheFullPath));
            }

            // Try cache but accept any valid image file extension
            const string ValidExtensions = ".bmp.dds.dib.hdr.jpg.jpeg.pfm.png.ppm.tga.gif.tif";

            if (allowCache)
            {
                string cacheSearchPath = Path.GetDirectoryName(cacheFullPath);
                if (Directory.Exists(cacheSearchPath))
                {
                    foreach (string imageFile in Directory.GetFiles(
                                 cacheSearchPath,
                                 Path.GetFileNameWithoutExtension(cacheFullPath) + ".*"))
                    {
                        string extension = Path.GetExtension(imageFile).ToLower();
                        if (ValidExtensions.IndexOf(extension) < 0)
                        {
                            continue;
                        }

                        if (m_imageTileService != null)
                        {
                            return(new ImageTileInfo(
                                       imageFile,
                                       m_imageTileService.GetImageTileServiceUri(level, row, col)));
                        }

                        if (m_wmsLayerAccessor != null)
                        {
                            double tileRange = m_levelZeroTileSizeDegrees * Math.Pow(0.5, level);
                            double west      = -180.0 + col * tileRange;
                            double south     = -90.0 + row * tileRange;

                            string fileUri = m_wmsLayerAccessor.GetWMSRequestUrl(
                                west, south, west + tileRange, south + tileRange,
                                m_textureSizePixels, m_textureSizePixels);

                            return(new ImageTileInfo(imageFile, fileUri));
                        }

                        return(new ImageTileInfo(imageFile));
                    }
                }
            }

            if (m_imageTileService != null)
            {
                return(new ImageTileInfo(
                           cacheFullPath,
                           m_imageTileService.GetImageTileServiceUri(level, row, col)));
            }

            if (m_wmsLayerAccessor != null)
            {
                double tileRange = m_levelZeroTileSizeDegrees * Math.Pow(0.5, level);
                double west      = -180.0 + col * tileRange;
                double south     = -90.0 + row * tileRange;

                string fileUri = m_wmsLayerAccessor.GetWMSRequestUrl(
                    west, south, west + tileRange, south + tileRange,
                    m_textureSizePixels, m_textureSizePixels);

                return(new ImageTileInfo(Path.Combine(m_cacheDirectory, relativePath), fileUri));
            }

            // No success, return our "duplicate" tile if any
            if (m_duplicateTexturePath != null && File.Exists(m_duplicateTexturePath))
            {
                return(new ImageTileInfo(m_duplicateTexturePath,
                                         Path.Combine(m_cacheDirectory, m_duplicateTexturePath)));
            }

            return(null);
            //throw new ApplicationException("No image access method available.");
        }