Exemplo n.º 1
0
 protected virtual void OnTileLoaded(TileCoord tileCoord)
 {
     if (this.TileLoaded != null)
     {
         TileLoaded(this, tileCoord);
     }
 }
        public override string GetRequestUrl(TileCoord tileCoord)
        {
            Extent tileExtent = _tileGrid.GetTileExtent(tileCoord);
            string url        = this._url;

            if (!url.EndsWith("?"))
            {
                url += "?";
            }
            var paras = new Dictionary <string, object>();

            _paras.ToList().ForEach(keyValue =>
            {
                paras.Add(keyValue.Key, keyValue.Value);
            });

            paras["TRANSPARENT"] = true;
            paras.Add("WIDTH", this._tileGrid.TileSize.Width);
            paras.Add("HEIGHT", this._tileGrid.TileSize.Height);
            paras.Add("BBOX", tileExtent);
            foreach (KeyValuePair <string, object> item in paras)
            {
                url += (item.Key + "=" + item.Value.ToString() + "&");
            }
            //Console.WriteLine(string.Format("x:{0},y:{1},zoom:{2},bbox:{3},url:{4}",tileCoord.X,tileCoord.Y,
            //    tileCoord.Zoom,tileExtent,url));
            return(url);
        }
Exemplo n.º 3
0
 public void Insert(TileCoord tile)
 {
     try
     {
         var sql = @"insert into FailTile(Zoom,X,Y) values(@Zoom,@X,@Y);";
         int ret = 0;
         using (var conn = new SQLiteConnection(_sqliteConnectionString))
         {
             ret = conn.Execute(sql, new
             {
                 Zoom = tile.Zoom,
                 X    = tile.X,
                 Y    = tile.Y
             });
         }
         if (ret > 0)
         {
             System.Threading.Interlocked.Increment(ref Count);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Exemplo n.º 4
0
        protected override string GetRequestUrl(TileCoord tileCoord)
        {
            string url = this._url;

            url = string.Format(url, tileCoord.Zoom, Math.Abs(tileCoord.Y), Math.Abs(tileCoord.X));
            return(url);
        }
        protected virtual string GetRequestUrl(TileCoord tileCoord)
        {
            Extent tileExtent = _tileGrid.GetTileExtent(tileCoord);
            string url        = this._url;

            if (!url.EndsWith("?"))
            {
                url += "?";
            }
            var paras = new Dictionary <string, object>();

            _paras.ToList().ForEach(keyValue =>
            {
                paras.Add(keyValue.Key, keyValue.Value);
            });

            //paras["TRANSPARENT"] = true;
            //paras.Add("WIDTH", this._tileGrid.TileSize.Width);
            //paras.Add("HEIGHT", this._tileGrid.TileSize.Height);
            //paras.Add("BBOX", tileExtent);
            //foreach (KeyValuePair<string, object> item in paras)
            //{
            //    url += (item.Key + "=" + item.Value.ToString() + "&");
            //}
            url += "&x=" + tileCoord.X.ToString();
            url += "&y=" + tileCoord.Y.ToString();
            url += "&z=" + tileCoord.Zoom.ToString();
            return(url);
        }
Exemplo n.º 6
0
 protected virtual void OnTileLoaded(TileCoord tileCoord)
 {
     Interlocked.Increment(ref _successTileIndex);
     if (this.TileLoaded != null)
     {
         TileLoaded(this, tileCoord);
     }
 }
        public override string GetRequestUrl(TileCoord tileCoord)
        {
            string url = this._url;

            url = url.Replace("{z}", (_offsetZoom + tileCoord.Zoom).ToString());
            url = url.Replace("{y}", tileCoord.Y.ToString());
            url = url.Replace("{x}", tileCoord.X.ToString());
            return(url);
        }
Exemplo n.º 8
0
        public virtual string GetRequestUrl(TileCoord tileCoord)
        {
            //http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x=" + x + "&y=" + y + "&z=" + z
            string url = this._url;

            url = url.Replace("{z}", (_offsetZoom + tileCoord.Zoom).ToString());
            url = url.Replace("{x}", Math.Abs(tileCoord.X).ToString());
            url = url.Replace("{y}", Math.Abs(tileCoord.Y).ToString());
            return(url);
        }
Exemplo n.º 9
0
        public Extent GetTileExtent(TileCoord tileCoord)
        {
            var origin     = this._origin;
            var resolution = this._resolutions[tileCoord.Zoom];
            var tileSize   = this._tileSize;
            var minX       = origin.X + tileCoord.X * tileSize.Width * resolution;
            var minY       = origin.Y + tileCoord.Y * tileSize.Height * resolution;
            var maxX       = minX + tileSize.Width * resolution;
            var maxY       = minY + tileSize.Height * resolution;

            return(new Extent(new double[] { minX, minY, maxX, maxY }));
        }
        public override string GetRequestUrl(TileCoord tileCoord)
        {
            var x = 'C' + padLeft(Convert.ToInt32(tileCoord.X), 8, 16);
            var y = 'R' + padLeft(Convert.ToInt32(tileCoord.Y), 8, 16);//WMTS
            //var y = 'R' + padLeft(Convert.ToInt32(-1 * tileCoord.Y -1), 8, 16);//TMS
            var z = 'L' + padLeft(Convert.ToInt32(tileCoord.Zoom) + offsetZoom, 2, 10);

            string url = this._url;

            url = url.Replace("{z}", z);
            url = url.Replace("{y}", y);
            url = url.Replace("{x}", x);
            return(url);
        }
Exemplo n.º 11
0
        public virtual OutputTile GetOutputTile(TileCoord input, int zoomOffset)
        {
            double x = input.X,
                   y = input.Y;

            if (input.X < 0)
            {
                x = Math.Abs(input.X);
            }
            if (input.Y < 0)
            {
                y = Math.Abs(input.Y);
            }
            return(new OutputTile((input.Zoom + zoomOffset).ToString(), x.ToString(), y.ToString()));
        }
Exemplo n.º 12
0
        public override OutputTile GetOutputTile(TileCoord input, int zoomOffset)
        {
            string x = input.X.ToString(),
                   y = input.Y.ToString();

            if (input.X < 0)
            {
                x = "M" + Math.Abs(input.X).ToString();
            }
            if (input.Y < 0)
            {
                y = "M" + Math.Abs(input.Y).ToString();
            }
            return(new OutputTile((input.Zoom + zoomOffset).ToString(), x.ToString(), y.ToString()));
        }
Exemplo n.º 13
0
        public string BuildTilePath(TileCoord tileCoord)
        {
            string x = tileCoord.X.ToString(),
                   y = tileCoord.Y.ToString();

            if (tileCoord.X < 0)
            {
                x = "M" + Math.Abs(tileCoord.X).ToString();
            }
            if (tileCoord.Y < 0)
            {
                y = "M" + Math.Abs(tileCoord.Y).ToString();
            }
            string zoomFold = _zoomFolds[tileCoord.Zoom];

            return(Path.Combine(zoomFold, x + "_" + y + ".png"));
        }
Exemplo n.º 14
0
        public virtual void EnumerateTileRange(TileCoord beginTile /*为了实现续载功能,从上次失败的点开始继续*/,
                                               Action <TileCoord> getTileCallback)
        {
            List <Extent> fullTileRange = _tileGrid.TileRanges;

            int    minZoom = 0, index = 0;
            double minX = fullTileRange[minZoom].MinX;
            double minY = fullTileRange[minZoom].MinY;

            if (beginTile != null)
            {
                minZoom = beginTile.Zoom;//从失败的那一级别开始下载。
                minX    = beginTile.X;
                minY    = beginTile.Y;
            }


            for (double x = minX; x <= fullTileRange[minZoom].MaxX; ++x)
            {
                for (double y = minY; y <= fullTileRange[minZoom].MaxY; ++y)
                {
                    ++index;
                    var tile = new TileCoord(minZoom, x, y, index);
                    getTileCallback(tile);
                }
            }

            for (int z = minZoom + 1; z < fullTileRange.Count; z++)
            {
                //for (double x = minX; x <= fullTileRange[z].MaxX; ++x)
                for (double x = fullTileRange[z].MinX; x <= fullTileRange[z].MaxX; ++x)
                {
                    //for (double y = minY; y <= fullTileRange[z].MaxY; ++y)
                    for (double y = fullTileRange[z].MinY; y <= fullTileRange[z].MaxY; ++y)
                    {
                        ++index;
                        var tile = new TileCoord(z, x, y, index);
                        getTileCallback(tile);
                    }
                }
            }
        }
Exemplo n.º 15
0
        protected override string GetRequestUrl(TileCoord tileCoord)
        {
            string url = this._url;
            string x   = tileCoord.X.ToString();
            string y   = tileCoord.Y.ToString();

            if (tileCoord.X < 0)
            {
                x = "M" + Math.Abs(tileCoord.X);
            }
            if (tileCoord.Y < 0)
            {
                y = "M" + Math.Abs(tileCoord.Y);
            }
            url += "&x=" + tileCoord.X.ToString();
            url += "&y=" + tileCoord.Y.ToString();
            url += "&z=" + (offsetZoom + tileCoord.Zoom).ToString();
            //url = string.Format(url, tileCoord.Zoom, Math.Abs(tileCoord.Y), Math.Abs(tileCoord.X));
            return(url);
        }
Exemplo n.º 16
0
 public void Delete(TileCoord failTile)
 {
     try
     {
         var sql = @"delete from FailTile where [Index]=@Index;";
         int ret = 0;
         using (var conn = new SQLiteConnection(_sqliteConnectionString))
         {
             ret = conn.Execute(sql, new
             {
                 Index = failTile.Index
             });
         }
         System.Threading.Interlocked.Decrement(ref Count);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Exemplo n.º 17
0
        public override string BuildTilePath(TileCoord tileCoord)
        {
            string x = tileCoord.X.ToString(),
                   y = tileCoord.Y.ToString();

            if (tileCoord.X < 0)
            {
                x = "M" + Math.Abs(tileCoord.X).ToString();
            }
            if (tileCoord.Y < 0)
            {
                y = "M" + Math.Abs(tileCoord.Y).ToString();
            }
            string zoomFold = _zoomFolds[tileCoord.Zoom];
            string filePath = Path.Combine(zoomFold, x);

            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }
            return(Path.Combine(filePath, y + ".png"));
        }
Exemplo n.º 18
0
        public virtual void EnumerateTileRange(TileCoord lastTile, Action <int> getZoomCallback, Action <TileCoord> getTileCallback)
        {
            int minZoom = 0;

            if (lastTile != null)
            {
                minZoom = lastTile.Zoom;
            }
            List <Extent> fullTileRange = _tileGrid.TileRanges;

            for (int z = minZoom; z < fullTileRange.Count; z++)
            {
                getZoomCallback(z);
                for (double x = fullTileRange[z].MinX; x <= fullTileRange[z].MaxX; ++x)
                {
                    for (double y = fullTileRange[z].MinY; y <= fullTileRange[z].MaxY; ++y)
                    {
                        var tile = new TileCoord(z, x, y);
                        getTileCallback(tile);
                    }
                }
            }
        }
        public override string GetRequestUrl(TileCoord tileCoord)
        {
            string url = this._url;

            if (!url.EndsWith("?"))
            {
                url += "?";
            }
            var paras = new Dictionary <string, object>();

            _paras.ToList().ForEach(keyValue =>
            {
                paras.Add(keyValue.Key, keyValue.Value);
            });
            paras["TRANSPARENT"] = true;
            paras.Add("TileMatrix", tileCoord.Zoom + 1);
            paras.Add("TileRow", tileCoord.Y);
            paras.Add("TileCol", tileCoord.X);
            foreach (KeyValuePair <string, object> item in paras)
            {
                url += (item.Key + "=" + item.Value.ToString() + "&");
            }
            return(url);
        }
        public Stream GetTile(TileCoord tileCoord)
        {
            string url = GetRequestUrl(tileCoord);

            return(_tileLoad.GetTile(url));
        }
Exemplo n.º 21
0
        public void Start()
        {
            if (!_isStop)
            {
                _blockingQueue = new BlockingCollection <TileCoord>(_threadCount);
                _tokenSource   = new CancellationTokenSource();
                var token       = _tokenSource.Token;
                var taskFactory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.LongRunning);

                for (int i = 0; i < _threadCount; i++)
                {
                    Task workThread = taskFactory.StartNew(() =>
                    {
                        while (!_isStop)
                        {
                            token.ThrowIfCancellationRequested();

                            TileCoord tileCoord = null;
                            if (_blockingQueue.TryTake(out tileCoord, 100))
                            //tileCoord = _blockingQueue.Take();
                            //if (tileCoord != null)
                            {
                                using (Stream stream = _source.GetTile(tileCoord))
                                {
                                    string filePath = _tilePathBuilder.BuildTilePath(tileCoord);
                                    using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                                    {
                                        int ret       = 0;
                                        byte[] buffer = new byte[8192];//8K
                                        ret           = stream.Read(buffer, 0, buffer.Length);
                                        while (ret > 0)
                                        {
                                            fs.Write(buffer, 0, ret);
                                            ret = stream.Read(buffer, 0, buffer.Length);
                                        }
                                        OnTileLoaded(tileCoord);
                                    }
                                }
                            }
                            //else
                            //{
                            //    token.WaitHandle.WaitOne(100);
                            //}
                        }
                    }, token);
                }

                List <Extent> fullTileRange = _source.TileGrid.TileRanges;
                for (int z = 0; z < fullTileRange.Count; z++)
                {
                    _tilePathBuilder.BuildZoomFold(z, _offsetZoom);

                    for (double x = fullTileRange[z].MinX; x <= fullTileRange[z].MaxX; ++x)
                    {
                        for (double y = fullTileRange[z].MinY; y <= fullTileRange[z].MaxY; ++y)
                        {
                            var tile = new TileCoord(z, x, y);
                            //_blockingQueue.TryAdd(tile, 500);
                            _blockingQueue.Add(tile);
                        }
                    }
                }
            }
        }