예제 #1
0
 private static Stream GetTileStream(TileIndex tileIndex)
 {
     var path = string.Format(@"Mapsui.Tests.Common.Resources.SampleTiles.{0}_{1}_{2}.png", tileIndex.Level, tileIndex.Col, tileIndex.Row);
     var data = typeof(Utilities).Assembly.GetManifestResourceStream(path);
     if (data == null) throw new Exception("Resource could not be found: " + path);
     return data;
 }
예제 #2
0
 private static Stream GetTileStream(TileIndex index)
 {
     var path = $"Mapsui.Tests.Common.Resources.SampleTiles.{index.Level}_{index.Col}_{index.Row}.png";
     var data = typeof(Utilities).GetTypeInfo().Assembly.GetManifestResourceStream(path);
     if (data == null) throw new Exception($"Resource could not be found: {path}");
     return data;
 }
예제 #3
0
파일: TileIndex.cs 프로젝트: bertt/BruTile
 public int CompareTo(TileIndex index)
 {
     if (_col < index._col) return -1;
     if (_col > index._col) return 1;
     if (_row < index._row) return -1;
     if (_row > index._row) return 1;
     return String.Compare(_level, index._level, StringComparison.Ordinal);
 }
예제 #4
0
 public int CompareTo(TileIndex index)
 {
     if (col < index.col) return -1;
     if (col > index.col) return 1;
     if (row < index.row) return -1;
     if (row > index.row) return 1;
     if (level < index.level) return -1;
     if (level > index.level) return 1;
     return 0;
 }
예제 #5
0
 public int CompareTo(TileIndex index)
 {
     if (_col < index._col) return -1;
     if (_col > index._col) return 1;
     if (_row < index._row) return -1;
     if (_row > index._row) return 1;
     if (_level < index._level) return -1;
     if (_level > index._level) return 1;
     return 0;
 }
예제 #6
0
        private static byte[] GetTile(ITileSource tileSource, string level, int col, int row)
        {
            try
            {
                var tileInfo = new TileInfo();
                var tileIndex = new TileIndex(col, row, level);
                tileInfo.Index = tileIndex;

                return tileSource.Provider.GetTile(tileInfo);
            }
            catch (WebException)
            {
                // intented: do nothing
                return null;
            }
        }
예제 #7
0
        public override Bitmap GetBitmap(int x, int y, Envelope envelope, int zoom)
        {
            var ts = TileSource;
            if (ts == null) return null;

            var zoomS = zoom.ToString(CultureInfo.InvariantCulture);
            try
            {
                var index = new TileIndex(x, y, zoom.ToString(CultureInfo.InvariantCulture));
                var tc = TileCache;
                var bytes = tc != null ? tc.Find(index) : null;
                if (bytes == null)
                {
                    var mapVertices = new[]
                    {
                        envelope.TopLeft().X, envelope.TopLeft().Y,
                        envelope.BottomRight().X, envelope.BottomRight().Y
                    };
                    double[] viewExtentZ = { 0.0, 0.0 };
                    Reproject.ReprojectPoints(mapVertices, viewExtentZ, Wgs84Proj, _data.CrsProjectionInfo, 0, mapVertices.Length / 2);
                    var geogEnv = new Envelope(mapVertices[0], mapVertices[2], mapVertices[1], mapVertices[3]);
                    bytes = ts.Provider.GetTile(new TileInfo {Extent = ToBrutileExtent(geogEnv), Index = index});
                    var bm = new Bitmap(new MemoryStream(bytes));
                    if (tc != null)
                    {
                        tc.Add(index, bytes);
                    }
                    return bm;
                }
                return new Bitmap(new MemoryStream(bytes));
            }
            catch (Exception ex)
            {
                if (ex is WebException ||
                    ex is TimeoutException)
                {
                    return ExceptionToBitmap(ex, TileSource.Schema.GetTileWidth(zoomS), TileSource.Schema.GetTileHeight(zoomS));
                }
                Debug.WriteLine(ex.Message);
            }
            return null;
        }
예제 #8
0
        public override Bitmap GetBitmap(int x, int y, Envelope envelope, int zoom)
        {
            var ts = TileSource;
            if (ts == null) return null;

            var zoomS = zoom.ToString(CultureInfo.InvariantCulture);
            try
            {
                var index = new TileIndex(x, y, zoomS);
                var tc = TileCache;
                var bytes = tc != null ? tc.Find(index) : null;
                if (bytes == null)
                {
                    var extent = ToBrutileExtent(envelope);
                    var tileInfo = ts.Schema.GetTilesInView(extent, zoomS).FirstOrDefault();
                    if (tileInfo == null)
                    {
                        return null;
                    }
                    tileInfo.Index = index;
                    bytes = ts.Provider.GetTile(tileInfo);
                    var bm = new Bitmap(new MemoryStream(bytes));
                    if (tc != null)
                    {
                        tc.Add(index, bytes);
                    }
                    return bm;
                }
                return new Bitmap(new MemoryStream(bytes));
            }
            catch (Exception ex)
            {
                if (ex is WebException ||
                    ex is TimeoutException)
                {
                    return ExceptionToBitmap(ex, TileSource.Schema.GetTileWidth(zoomS), TileSource.Schema.GetTileHeight(zoomS));
                }
                Debug.WriteLine(ex.Message);
            }
            return null;
        }
예제 #9
0
        private static List<IFeature> TileIndexToFeatures(TileIndex[] tileIndexes, ITileSource tileSource)
        {
            var features = new List<IFeature>();
            foreach (var tileIndex in tileIndexes)
            {
                var tileInfo = new TileInfo
                {
                    Index = tileIndex,
                    Extent = TileTransform.TileToWorld(
                        new TileRange(tileIndex.Col, tileIndex.Row), tileIndex.Level, tileSource.Schema)
                };

                var feature = new Feature
                {
                    Geometry = new Raster(new MemoryStream(
                        tileSource.GetTile(tileInfo)), tileInfo.Extent.ToBoundingBox())
                };

                features.Add(feature);
            }
            return features;
        }
예제 #10
0
            public bool ReachedMax(TileIndex index)
            {
                if (_threadId != Thread.CurrentThread.ManagedThreadId) throw new Exception(CrossThreadExceptionMessage);

                var retryCount = (!_retries.Keys.Contains(index)) ? 0 : _retries[index];
                return retryCount > _maxRetries;
            }
예제 #11
0
 private void AddTile(TileIndex tileIndex)
 {
     _dictionary[tileIndex] = ReadFully(GetTileStream(tileIndex));
 }
예제 #12
0
 public bool Equals(TileIndex index)
 {
     return(Col == index.Col && Row == index.Row && Level == index.Level);
 }
예제 #13
0
        private Bitmap GetViaBrutile(int x, int y, int zoom, IEnvelope envelope)
        {
            if (_tileSource == null) return null;

            try
            {
                // try cache first
                var index = new TileIndex(x, y, zoom.ToString(CultureInfo.InvariantCulture));
                var bytes = TileCache.Find(index);
                if (bytes == null)
                {
                    var extent = ToBrutileExtent(new Data.Extent(envelope));
                    var tileInfo = _tileSource.Schema.GetTilesInView(extent, zoom).First();
                    tileInfo.Index = index;
                    bytes = _tileSource.Provider.GetTile(tileInfo);
                    TileCache.Add(index, bytes);
                }
                return new Bitmap(new MemoryStream(bytes));
            }
            catch (Exception ex)
            {
                if (ex is WebException ||
                    ex is TimeoutException)
                {
                    using (var bitmap = new Bitmap(_tileSource.Schema.Width, _tileSource.Schema.Height))
                    {
                        using (var graphics = Graphics.FromImage(bitmap))
                        {
                            graphics.DrawString(ex.Message, new Font(FontFamily.GenericSansSerif, 12), new SolidBrush(Color.Black), 
                                new RectangleF(0, 0, _tileSource.Schema.Width, _tileSource.Schema.Height));
                        }

                        using (var m = new MemoryStream())
                        {
                            bitmap.Save(m, ImageFormat.Png);
                            return new Bitmap(m);
                        }
                    }
                }
                Debug.WriteLine(ex.Message);
            }
            return null;
        }
예제 #14
0
 public bool Equals(TileIndex index)
 {
     return(col == index.col && row == index.row && level == index.level);
 }
예제 #15
0
            public void PlusOne(TileIndex index)
            {
                if (_threadId != Thread.CurrentThread.ManagedThreadId) throw new Exception(CrossThreadExceptionMessage);

                if (!_retries.Keys.Contains(index)) _retries.Add(index, 0);
                else _retries[index]++;
            }
예제 #16
0
        public override Bitmap GetBitmap(int x, int y, Envelope envelope, int zoom)
        {
            var ts = TileSource;
            if (ts == null) return null;

            Bitmap bitMap = null;
            var zoomS = zoom.ToString(CultureInfo.InvariantCulture);
            var extent = ToBrutileExtent(envelope);
            var tileInfo = ts.Schema.GetTilesInView(extent, zoomS).FirstOrDefault();

            try
            {
                var index = new TileIndex(x, y, zoomS);
                var tc = TileCache;
                var bytes = tc != null ? tc.Find(index) : null;
                if (bytes == null)
                {
                    if (tileInfo == null)
                    {
                        return null;
                    }
                    tileInfo.Index = index;
                    bytes = ts.Provider.GetTile(tileInfo);
                    bitMap = new Bitmap(new MemoryStream(bytes));
                    if (tc != null)
                    {
                        tc.Add(index, bytes);
                    }
                    return bitMap;
                }
                return new Bitmap(new MemoryStream(bytes));
            }
            catch (Exception ex)
            {
                if (ex is WebException ||
                    ex is TimeoutException)
                {
                    bitMap = ExceptionToBitmap(ex, TileSource.Schema.GetTileWidth(zoomS), TileSource.Schema.GetTileHeight(zoomS));
                }
                else
                    Debug.WriteLine(ex.Message);
            }

            // Esri Hyro Base Map Fix, the server doesn't put image in the response header.
            if (ts is ArcGisTileSource)
            {
                try
                {
                    string str = (ts as ArcGisTileSource).BaseUrl + "/tile/{zoom}/{y}/{x}";
                    if (str != null)
                    {
                        if (!str.Contains("{key}"))
                        {
                            str = str.Replace("{zoom}", zoomS);
                            str = str.Replace("{x}", x.ToString());
                            str = str.Replace("{y}", y.ToString());

                            Stream stream = (new WebClient()).OpenRead(str);
                            if (stream != null)
                            {
                                bitMap = new Bitmap(stream);
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                }
            }

            return bitMap;
        }
예제 #17
0
 public bool Equals(TileIndex index)
 {
     return _col == index._col && _row == index._row && _level == index._level;
 }
예제 #18
0
 public bool Equals(TileIndex index)
 {
     return col == index.col && row == index.row && level == index.level;
 }
예제 #19
0
 public bool Equals(TileIndex index)
 {
     return(_col == index._col && _row == index._row && _level == index._level);
 }