public override PointLatLng FromPixelToLatLng(long x, long y, int zoom)
        {
            GSize s = GetTileMatrixSizePixel(zoom);

            double mapSizeX = s.Width;
            double mapSizeY = s.Height;

            double a     = 6378137;
            double c1    = 0.00335655146887969;
            double c2    = 0.00000657187271079536;
            double c3    = 0.00000001764564338702;
            double c4    = 0.00000000005328478445;
            double z1    = (23 - zoom);
            double mercX = (x * Math.Pow(2, z1)) / 53.5865938 - 20037508.342789;
            double mercY = 20037508.342789 - (y * Math.Pow(2, z1)) / 53.5865938;

            double g = Math.PI / 2 - 2 * Math.Atan(1 / Math.Exp(mercY / a));
            double z = g + c1 * Math.Sin(2 * g) + c2 * Math.Sin(4 * g) + c3 * Math.Sin(6 * g) + c4 * Math.Sin(8 * g);

            PointLatLng ret = PointLatLng.Empty;

            ret.Lat = z * RAD_DEG;
            ret.Lng = mercX / a * RAD_DEG;

            return(ret);
        }
Esempio n. 2
0
        /// <summary>
        /// gets matrix size in tiles
        /// </summary>
        /// <param name="zoom"></param>
        /// <returns></returns>
        public virtual GSize GetTileMatrixSizeXY(int zoom)
        {
            GSize sMin = GetTileMatrixMinXY(zoom);
            GSize sMax = GetTileMatrixMaxXY(zoom);

            return(new GSize(sMax.Width - sMin.Width + 1, sMax.Height - sMin.Height + 1));
        }
Esempio n. 3
0
        public override PointLatLng FromPixelToLatLng(long x, long y, int zoom)
        {
            PointLatLng ret                = PointLatLng.Empty;
            GSize       s                  = GetTileMatrixSizePixel(zoom);
            double      mapSizeX           = s.Width;
            double      mapSizeY           = s.Height;
            double      xMercatorBaidu     = x - 0.5 * mapSizeX;
            double      yMercatorBaidu     = -y + 0.5 * mapSizeY;
            double      xTileNum           = xMercatorBaidu / 256;
            double      yTileNum           = yMercatorBaidu / 256;
            int         tileXNum           = (int)Math.Floor(xTileNum);
            int         tileYNum           = (int)Math.Floor(yTileNum);
            double      xRelativeTileCoord = xMercatorBaidu % 256 / 256; xRelativeTileCoord = xRelativeTileCoord > 0 ? xRelativeTileCoord : 1 + xRelativeTileCoord;
            double      yRelativeTileCoord = yMercatorBaidu % 256 / 256; yRelativeTileCoord = yRelativeTileCoord > 0 ? 1 - yRelativeTileCoord : -yRelativeTileCoord;
            long        xPixelCoord        = (long)(xRelativeTileCoord * 256);
            long        yPixelCoord        = (long)(yRelativeTileCoord * 256);
            double      tileNumX           = (tileXNum + (double)xPixelCoord / 256);

            ret.Lng = (Math.Pow(2.0, 26 - zoom) * (tileNumX)) / (Math.PI * Axis) * 180;
            double eIndex = Math.Pow(2.0, 26 - zoom) * (tileYNum + 1 - (double)yPixelCoord / 256) / Axis;

            ret.Lat = 360 * Math.Atan(Math.Pow(Math.E, eIndex)) / Math.PI - 90;

            ret.Lat += 0.1748;
            ret.Lng -= 0.0014;

            return(ret);
        }
Esempio n. 4
0
 /// <summary>
 /// marker using manual bitmap
 /// </summary>
 /// <param name="p"></param>
 /// <param name="bitmap"></param>
 public GMarkerIcon(PointLatLng p, Bitmap bitmap)
     : base(p)
 {
     fBitmap = bitmap;
     Size    = new GSize(bitmap.Width, bitmap.Height);
     Offset  = new GPoint(-Size.Width / 2, -Size.Height);
 }
Esempio n. 5
0
        /// <summary>
        /// 计算瓦片范围
        /// </summary>
        /// <param name="zoom">瓦片等级</param>
        /// <param name="buffer">外扩大小</param>
        /// <param name="tileMinX">最小瓦片X坐标</param>
        /// <param name="tileMaxX">最大瓦片X坐标</param>
        /// <param name="tileMinY">最小瓦片Y坐标</param>
        /// <param name="tileMaxY">最大瓦片Y坐标</param>
        /// <returns>瓦片数量</returns>
        private long CoorExtent(int zoom, long buffer, out long tileMinX, out long tileMaxX, out long tileMinY, out long tileMaxY)
        {
            GSize  size         = _provider.Projection.GetTileMatrixSizeXY(zoom); // zoom等级的时候所有瓦片的数量
            GSize  sMin         = _provider.Projection.GetTileMatrixMinXY(zoom);  // 瓦片最小范围
            GSize  sMax         = _provider.Projection.GetTileMatrixMaxXY(zoom);  // 瓦片最大范围
            GPoint left_top     = _provider.Projection.FromPixelToTileXY(_provider.Projection.FromLatLngToPixel(_top_lat, _left_lng, zoom));
            GPoint right_bottom = _provider.Projection.FromPixelToTileXY(_provider.Projection.FromLatLngToPixel(_bottom_lat, _right_lng, zoom));

            long xmin = left_top.X;         //
            long xmax = right_bottom.X;     //
            long ymin = left_top.Y;         //
            long ymax = right_bottom.Y;     //

            xmin = xmin - buffer;           // 缓冲
            xmax = xmax + buffer;           // 缓冲
            ymin = ymin - buffer;           // 缓冲
            ymax = ymax + buffer;           // 缓冲

            xmin = (long)Clip(xmin, sMin.Width, sMax.Width);
            xmax = (long)Clip(xmax, sMin.Width, sMax.Width);
            ymin = (long)Clip(ymin, sMin.Height, sMax.Height);
            ymax = (long)Clip(ymax, sMin.Height, sMax.Height);

            tileMinX = xmin;
            tileMaxX = xmax;
            tileMinY = ymin;
            tileMaxY = ymax;

            long total = (xmax - xmin + 1) * (ymax - ymin + 1);

            return(total);
        }
Esempio n. 6
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            PureProjection proj        = map.MapProvider.Projection;
            GSize          size1       = proj.GetTileMatrixSizeXY(1);
            GSize          sizeCurrent = proj.GetTileMatrixSizeXY((int)(double)value);

            return(sizeCurrent.Width / (double)size1.Width * 0.001);
        }
Esempio n. 7
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            if (_list != null)
            {
                _list.Clear();
                _list = null;
            }

            _list       = _provider.Projection.GetAreaTileList(_area, _zoom, 0);
            _maxOfTiles = _provider.Projection.GetTileMatrixMaxXY(_zoom);
            _all        = _list.Count;

            int countOk = 0;
            int retry   = 0;

            Stuff.Shuffle <GPoint>(_list);

            for (int i = 0; i < _all; i++)
            {
                if (_worker.CancellationPending)
                {
                    break;
                }

                var p = _list[i];
                {
                    if (CacheTiles(_zoom, p))
                    {
                        countOk++;
                        retry = 0;
                    }
                    else
                    {
                        if (++retry <= 1) // retry only one
                        {
                            i--;
                            Thread.Sleep(1111);
                            continue;
                        }
                        else
                        {
                            retry = 0;
                        }
                    }
                }

                _worker.ReportProgress((i + 1) * 100 / _all, i + 1);

                Thread.Sleep(_sleep);
            }

            e.Result = countOk;

            if (!stopped)
            {
                done.WaitOne();
            }
        }
Esempio n. 8
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            if (list != null)
            {
                list.Clear();
                list = null;
            }
            list       = provider.Projection.GetAreaTileList(area, zoom, 0);
            maxOfTiles = provider.Projection.GetTileMatrixMaxXY(zoom);
            all        = list.Count;

            int countOk = 0;
            int retry   = 0;

            Stuff.Shuffle <GPoint>(list);

            for (int i = 0; i < all; i++)
            {
                if (worker.CancellationPending)
                {
                    break;
                }

                GPoint p = list[i];
                {
                    if (CacheTiles(zoom, p))
                    {
                        countOk++;
                        retry = 0;
                    }
                    else
                    {
                        if (++retry <= 1) // retry only one
                        {
                            i--;
                            System.Threading.Thread.Sleep(1111);
                            continue;
                        }
                        else
                        {
                            retry = 0;
                        }
                    }
                }

                worker.ReportProgress((int)((i + 1) * 100 / all), i + 1);

                System.Threading.Thread.Sleep(sleep);
            }

            e.Result = countOk;

            if (!stopped)
            {
                done.WaitOne();
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 下载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDownload_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtSaveFolder.Text))
            {
                MessageBox.Show("保存路径不能为空");
                btnSaveFolder.Focus();
                return;
            }

            if (!Util.Validation.IsNumber(txtMinLongitude.Text) || !Util.Validation.IsNumber(txtMaxLongitude.Text) ||
                !Util.Validation.IsNumber(txtMinLatitude.Text) || !Util.Validation.IsNumber(txtMaxLatitude.Text))
            {
                MessageBox.Show("坐标格式不正确");
                return;
            }

            PureProjection proj = mapControl.MapProvider.Projection;

            int   zoom       = Convert.ToInt32(mapControl.Zoom);
            GSize minOfTiles = proj.GetTileMatrixMinXY(zoom);
            GSize maxOfTiles = proj.GetTileMatrixMaxXY(zoom);

            PointLatLng position  = new PointLatLng(double.Parse(txtMinLatitude.Text), double.Parse(txtMinLongitude.Text));
            PointLatLng position1 = new PointLatLng(double.Parse(txtMaxLatitude.Text), double.Parse(txtMaxLongitude.Text));

            Core.MapPoint minPoint = new Core.MapPoint()
            {
                X = position.Lng, Y = position.Lat
            };
            Core.MapPoint maxPoint = new Core.MapPoint()
            {
                X = position1.Lng, Y = position1.Lat
            };

            Core.Log.Clear(logFile);
            downloader = new Core.Provider.GoogleChinaMapDownloader(
                new Core.Extent(minPoint.X, minPoint.Y, maxPoint.X, maxPoint.Y),
                int.Parse(txtMinZoom.Text),
                int.Parse(txtMaxZoom.Text)
                )
            {
                SavePath = txtSaveFolder.Text
            };
            downloader.TileDownloadCompleted += TileDownloadCompleted;
            downloader.DownloadCompleted     += DownloadCompleted;
            downloader.BeginDownload();
            statusbar_progress.Visible = true;
            statusbar_progress.Maximum = 100;
            statusbar_status.Text      = "下载中......";
        }
        public override PointLatLng FromPixelToLatLng(int x, int y, int zoom)
        {
            PointLatLng ret = PointLatLng.Zero;

            GSize  s        = GetTileMatrixSizePixel(zoom);
            double mapSizeX = s.Width;
            double mapSizeY = s.Height;

            double scale = 360.0 / mapSizeX;

            ret.Lat = 90 - (y * scale);
            ret.Lng = (x * scale) - 180;

            return(ret);
        }
Esempio n. 11
0
        public override PointLatLng FromPixelToLatLng(long x, long y, int zoom)
        {
            PointLatLng ret = PointLatLng.Empty;

            GSize  s        = GetTileMatrixSizePixel(zoom);
            double mapSizeX = s.Width;
            double mapSizeY = s.Height;

            double scale = 360.0 / mapSizeX;

            ret.Lat = 90 - y * scale;
            ret.Lng = x * scale - 180;

            return(ret);
        }
Esempio n. 12
0
        public override PointLatLng FromPixelToLatLng(long x, long y, int zoom)
        {
            PointLatLng ret = PointLatLng.Zero;

            GSize  s        = GetTileMatrixSizePixel(zoom);
            double mapSizeX = s.Width;
            double mapSizeY = s.Height;

            double xx = (Clip(x, 0, mapSizeX - 1) / mapSizeX) - 0.5;
            double yy = 0.5 - (Clip(y, 0, mapSizeY - 1) / mapSizeY);

            ret.Lat = 90 - 360 * Math.Atan(Math.Exp(-yy * 2 * Math.PI)) / Math.PI;
            ret.Lng = 360 * xx;

            return(ret);
        }
        public override PointLatLng FromPixelToLatLng(long x, long y, int zoom)
        {
            PointLatLng ret = PointLatLng.Empty;

            GSize  s        = GetTileMatrixSizePixel(zoom);
            double mapSizeX = s.Width;
            double mapSizeY = s.Height;

            double xx = (Clip(x, 0, mapSizeX - 1) / mapSizeX) - 0.5;
            double yy = 0.5 - (Clip(y, 0, mapSizeY - 1) / mapSizeY);

            ret.Lat = 90 - 360 * Math.Atan(Math.Exp(-yy * 2 * Math.PI)) / Math.PI + 14.307 + 0.0070715774074;
            ret.Lng = 360 * xx + 45.245 - 0.004644012451;

            return(ret);
        }
        public override GPoint FromLatLngToPixel(double lat, double lng, int zoom)
        {
            GPoint ret = GPoint.Empty;

            lat = Clip(lat, MinLatitude, MaxLatitude);
            lng = Clip(lng, MinLongitude, MaxLongitude);

            GSize  s        = GetTileMatrixSizePixel(zoom);
            double mapSizeX = s.Width;
            double mapSizeY = s.Height;

            double scale = 360.0 / mapSizeX;

            ret.Y = (int)((90.0 - lat) / scale);
            ret.X = (int)((lng + 180.0) / scale);

            return(ret);
        }
Esempio n. 15
0
        public override GPoint FromLatLngToPixel(double lat, double lng, int zoom)
        {
            GPoint ret = GPoint.Empty;

            lat = Clip(lat, MinLatitude, MaxLatitude);
            lng = Clip(lng, MinLongitude, MaxLongitude);

            double x           = (lng + 180) / 360;
            double sinLatitude = Math.Sin(lat * Math.PI / 180);
            double y           = 0.5 - Math.Log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI);

            GSize s        = GetTileMatrixSizePixel(zoom);
            long  mapSizeX = s.Width;
            long  mapSizeY = s.Height;

            ret.X = (long)Clip(x * mapSizeX + 0.5, 0, mapSizeX - 1);
            ret.Y = (long)Clip(y * mapSizeY + 0.5, 0, mapSizeY - 1);

            return(ret);
        }
Esempio n. 16
0
        public override GPoint FromLatLngToPixel(double lat, double lng, int zoom)
        {
            double[] latlng = new double[2];
            this.transform(lat, lng, latlng);
            lat = latlng[0];
            lng = latlng[1];
            GPoint empty = GPoint.Empty;

            lat = PureProjection.Clip(lat, MinLatitude, MaxLatitude);
            lng = PureProjection.Clip(lng, MinLongitude, MaxLongitude);
            double num  = (lng + 180.0) / 360.0;
            double num2 = Math.Sin((lat * 3.1415926535897931) / 180.0);
            double num3 = 0.5 - (Math.Log((1.0 + num2) / (1.0 - num2)) / 12.566370614359172);
            GSize  tileMatrixSizePixel = this.GetTileMatrixSizePixel(zoom);
            long   width  = tileMatrixSizePixel.Width;
            long   height = tileMatrixSizePixel.Height;

            empty.X = (long)PureProjection.Clip((num * width) + 0.5, 0.0, (double)(width - 1L));
            empty.Y = (long)PureProjection.Clip((num3 * height) + 0.5, 0.0, (double)(height - 1L));
            return(empty);
        }
Esempio n. 17
0
        public override GPoint FromLatLngToPixel(double lat, double lng, int zoom)
        {
            lat -= 0.1748;
            lng += 0.0014;

            GPoint ret = GPoint.Empty;

            lat = Clip(lat, MinLatitude, MaxLatitude);
            lng = Clip(lng, MinLongitude, MaxLongitude);
            GSize  s                = GetTileMatrixSizePixel(zoom);
            long   mapSizeX         = s.Width;
            long   mapSizeY         = s.Height;
            double xMercatorTileNum = (Math.Pow(2.0, zoom - 26) * (Math.PI * lng * Axis / 180.0));
            double xAxisPixelLength = xMercatorTileNum * 256;

            ret.X = (long)(mapSizeX * 0.5 + xAxisPixelLength);
            double yMercatorTileNum = (Math.Pow(2.0, zoom - 26) * Axis * Math.Log(Math.Tan(Math.PI * lat / 180.0) + 1.0 / Math.Cos(Math.PI * lat / 180.0)));
            double yAxisPixelLength = yMercatorTileNum * 256; ret.Y = (long)(mapSizeY * 0.5 - yAxisPixelLength);

            return(ret);
        }
Esempio n. 18
0
        public override PointLatLng FromPixelToLatLng(long x, long y, int zoom)
        {
            PointLatLng empty = PointLatLng.Empty;
            GSize       tileMatrixSizePixel = this.GetTileMatrixSizePixel(zoom);
            double      width  = tileMatrixSizePixel.Width;
            double      height = tileMatrixSizePixel.Height;
            double      num3   = (PureProjection.Clip((double)x, 0.0, width - 1.0) / width) - 0.5;
            double      num4   = 0.5 - (PureProjection.Clip((double)y, 0.0, height - 1.0) / height);

            empty.Lat = 90.0 - ((360.0 * Math.Atan(Math.Exp((-num4 * 2.0) * 3.1415926535897931))) / 3.1415926535897931);
            empty.Lng = 360.0 * num3;
            PointLatLng lng2 = new PointLatLng();

            double[] latlng = new double[2];
            this.transform(empty.Lat, empty.Lng, latlng);
            lng2.Lat   = latlng[0];
            lng2.Lng   = latlng[1];
            empty.Lat -= lng2.Lat - empty.Lat;
            empty.Lng -= lng2.Lng - empty.Lng;
            return(empty);
        }
Esempio n. 19
0
 private bool CacheTiles(int zoom, GPoint p, GSize maxOfTiles)
 {
     foreach (GMapProvider provider in this._provider.Overlays)
     {
         Exception result;
         PureImage pureImage;
         if (!(provider is TurkeyMapProvider))
         {
             pureImage = Singleton <GMaps> .Instance.GetImageFrom(provider, p, zoom, out result);
         }
         else
         {
             pureImage = Singleton <GMaps> .Instance.GetImageFrom(provider,
                                                                  new GPoint(p.X, maxOfTiles.Height - p.Y),
                                                                  zoom, out result);
         }
         if (pureImage == null)
         {
             return(false);
         }
         pureImage.Dispose();
     }
     return(true);
 }
Esempio n. 20
0
      public override GSize GetTileMatrixMaxXY(int zoom)
      {
         GSize ret = GSize.Empty;

         switch(zoom)
         {
            #region -- sizes --
            case 0:
            {
               ret = new GSize(14, 9);
            }
            break;

            case 1:
            {
               ret = new GSize(28, 18);
            }
            break;

            case 2:
            {
               ret = new GSize(43, 28);
            }
            break;

            case 3:
            {
               ret = new GSize(86, 56);
            }
            break;

            case 4:
            {
               ret = new GSize(173, 112);
            }
            break;

            case 5:
            {
               ret = new GSize(434, 282);
            }
            break;

            case 6:
            {
               ret = new GSize(868, 564);
            }
            break;

            case 7:
            {
               ret = new GSize(1737, 1129);
            }
            break;

            case 8:
            {
               ret = new GSize(3474, 2258);
            }
            break;

            case 9:
            {
               ret = new GSize(8686, 5647);
            }
            break;

            case 10:
            {
               ret = new GSize(17372, 11294);
            }
            break;

            case 11:
            {
               ret = new GSize(43430, 28236);
            }
            break;
            #endregion
         }

         return ret;
      }
Esempio n. 21
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            if (list != null)
            {
                list.Clear();
                list = null;
            }
            list       = provider.Projection.GetAreaTileList(area, zoom, 0);
            maxOfTiles = provider.Projection.GetTileMatrixMaxXY(zoom);
            all        = list.Count;

            int countOk    = 0;
            int retryCount = 0;

            if (Shuffle)
            {
                Shuffle1(list);
            }

            //lock (this)
            //{
            //    CachedTiles.Clear();
            //}

            for (int i = 0; i < all; i++)
            {
                if (worker.CancellationPending)
                {
                    break;
                }

                GPoint p = list[i];
                {
                    if (CacheTiles(zoom, p))
                    {
                        //if (Overlay != null)
                        //{
                        //    lock (this)
                        //    {
                        //        CachedTiles.Enqueue(p);
                        //    }
                        //}
                        countOk++;
                        retryCount = 0;
                    }
                    else
                    {
                        if (++retryCount <= retry) // retry only one
                        {
                            i--;
                            Thread.Sleep(1111);
                            continue;
                        }
                        failure++;
                        MethodInvoker m = delegate
                        {
                            label2.Text = string.Format("下载失败数量: {0}", failure);
                        };
                        Invoke(m);
                        retryCount = 0;
                    }
                }

                worker.ReportProgress((i + 1) * 100 / all, i + 1);

                if (sleep > 0)
                {
                    Thread.Sleep(sleep);
                }
            }

            e.Result = countOk;

            if (!IsDisposed)
            {
                done.WaitOne();
            }
        }
Esempio n. 22
0
        void worker_DoWork1(object sender, DoWorkEventArgs e)
        {
            if (list != null)
            {
                list.Clear();
                list = null;
            }
            list       = provider.Projection.GetAreaTileList(area, zoom, 0);
            maxOfTiles = provider.Projection.GetTileMatrixMaxXY(zoom);
            all        = list.Count;

            int countOk = 0;

            if (Shuffle)
            {
                Shuffle1(list);
            }

            //lock (this)
            //{
            //    CachedTiles.Clear();
            //}

            var __任务列表 = new List <Task>();

            for (int j = 0; j < _线程数; j++)
            {
                var temp = Task.Factory.StartNew(q =>
                {
                    var __线程标识     = (int)q;
                    int retryCount = 0;

                    for (int i = __线程标识; i < all; i = i + _线程数)
                    {
                        if (worker.CancellationPending)
                        {
                            break;
                        }

                        GPoint p = list[i];
                        if (CacheTiles(zoom, p))
                        {
                            //if (Overlay != null)
                            //{
                            //    lock (this)
                            //    {
                            //        CachedTiles.Enqueue(p);
                            //    }
                            //}
                            countOk++;
                            retryCount = 0;
                        }
                        else
                        {
                            if (++retryCount <= retry) // retry only one
                            {
                                i = i - _线程数;
                                Thread.Sleep(1111);
                                continue;
                            }
                            failure++;
                            MethodInvoker m = delegate
                            {
                                label2.Text = string.Format("下载失败数量: {0}", failure);
                            };
                            Invoke(m);
                            retryCount = 0;
                        }

                        worker.ReportProgress(countOk * 100 / all, countOk);

                        if (sleep > 0)
                        {
                            Thread.Sleep(sleep);
                        }
                    }
                }, j);
                __任务列表.Add(temp);
            }
            Task.WaitAll(__任务列表.ToArray());

            e.Result = countOk;

            if (!IsDisposed)
            {
                done.WaitOne();
            }
        }
Esempio n. 23
0
        public override GSize GetTileMatrixMaxXY(int zoom)
        {
            GSize ret = GSize.Empty;

             switch(zoom)
             {
            #region -- sizes --
            case 0:
            {
               ret = new GSize(14, 10);
            }
            break;

            case 1:
            {
               ret = new GSize(30, 20);
            }
            break;

            case 2:
            {
               ret = new GSize(45, 31);
            }
            break;

            case 3:
            {
               ret = new GSize(90, 62);
            }
            break;

            case 4:
            {
               ret = new GSize(181, 125);
            }
            break;

            case 5:
            {
               ret = new GSize(454, 311);
            }
            break;

            case 6:
            {
               ret = new GSize(903, 623);
            }
            break;

            case 7:
            {
               ret = new GSize(1718, 1193);
            }
            break;

            case 8:
            {
               ret = new GSize(3437, 2386);
            }
            break;

            case 9:
            {
               ret = new GSize(8594, 5966);
            }
            break;

            case 10:
            {
               ret = new GSize(17189, 11932);
            }
            break;

            case 11:
            {
               ret = new GSize(42972, 29831);
            }
            break;
            #endregion
             }

             return ret;
        }
Esempio n. 24
0
        public override GSize GetTileMatrixMinXY(int zoom)
        {
            GSize ret = GSize.Empty;

             switch(zoom)
             {
            #region -- sizes --
            case 0:
            {
               ret = new GSize(12, 8);
            }
            break;

            case 1:
            {
               ret = new GSize(24, 17);
            }
            break;

            case 2:
            {
               ret = new GSize(37, 25);
            }
            break;

            case 3:
            {
               ret = new GSize(74, 51);
            }
            break;

            case 4:
            {
               ret = new GSize(149, 103);
            }
            break;

            case 5:
            {
               ret = new GSize(374, 259);
            }
            break;

            case 6:
            {
               ret = new GSize(749, 519);
            }
            break;

            case 7:
            {
               ret = new GSize(1594, 1100);
            }
            break;

            case 8:
            {
               ret = new GSize(3188, 2201);
            }
            break;

            case 9:
            {
               ret = new GSize(7971, 5502);
            }
            break;

            case 10:
            {
               ret = new GSize(15943, 11005);
            }
            break;

            case 11:
            {
               ret = new GSize(39858, 27514);
            }
            break;
            #endregion
             }

             return ret;
        }
Esempio n. 25
0
        public override GSize GetTileMatrixMinXY(int zoom)
        {
            GSize ret = GSize.Empty;

            switch (zoom)
            {
                #region -- sizes --
            case 0:
            {
                ret = new GSize(13, 8);
            }
            break;

            case 1:
            {
                ret = new GSize(26, 17);
            }
            break;

            case 2:
            {
                ret = new GSize(39, 26);
            }
            break;

            case 3:
            {
                ret = new GSize(79, 52);
            }
            break;

            case 4:
            {
                ret = new GSize(159, 105);
            }
            break;

            case 5:
            {
                ret = new GSize(399, 262);
            }
            break;

            case 6:
            {
                ret = new GSize(798, 525);
            }
            break;

            case 7:
            {
                ret = new GSize(1597, 1050);
            }
            break;

            case 8:
            {
                ret = new GSize(3195, 2101);
            }
            break;

            case 9:
            {
                ret = new GSize(7989, 5254);
            }
            break;

            case 10:
            {
                ret = new GSize(15978, 10509);
            }
            break;

            case 11:
            {
                ret = new GSize(39945, 26273);
            }
            break;
                #endregion
            }

            return(ret);
        }
Esempio n. 26
0
        public override GSize GetTileMatrixSizePixel(int zoom)
        {
            GSize s = GetTileMatrixSizeXY(zoom);

            return(new GSize(s.Width << 8, s.Height << 8));
        }
Esempio n. 27
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            if(list != null)
             {
            list.Clear();
            list = null;
             }
             list = provider.Projection.GetAreaTileList(area, zoom, 0);
             maxOfTiles = provider.Projection.GetTileMatrixMaxXY(zoom);
             all = list.Count;

             int countOk = 0;
             int retry = 0;

             Stuff.Shuffle<GPoint>(list);

             for(int i = 0; i < all; i++)
             {
            if(worker.CancellationPending)
               break;

            GPoint p = list[i];
            {
               if(CacheTiles(zoom, p))
               {
                  countOk++;
                  retry = 0;
               }
               else
               {
                  if(++retry <= 1) // retry only one
                  {
                     i--;
                     System.Threading.Thread.Sleep(1111);
                     continue;
                  }
                  else
                  {
                     retry = 0;
                  }
               }
            }

            worker.ReportProgress((int)((i + 1) * 100 / all), i + 1);

            System.Threading.Thread.Sleep(sleep);
             }

             e.Result = countOk;

             if(!stopped)
             {
            done.WaitOne();
             }
        }
Esempio n. 28
0
        public override GSize GetTileMatrixMaxXY(int zoom)
        {
            GSize ret = GSize.Empty;

            switch (zoom)
            {
                #region -- sizes --
            case 0:
            {
                ret = new GSize(14, 10);
            }
            break;

            case 1:
            {
                ret = new GSize(30, 20);
            }
            break;

            case 2:
            {
                ret = new GSize(45, 31);
            }
            break;

            case 3:
            {
                ret = new GSize(90, 62);
            }
            break;

            case 4:
            {
                ret = new GSize(181, 125);
            }
            break;

            case 5:
            {
                ret = new GSize(454, 311);
            }
            break;

            case 6:
            {
                ret = new GSize(903, 623);
            }
            break;

            case 7:
            {
                ret = new GSize(1718, 1193);
            }
            break;

            case 8:
            {
                ret = new GSize(3437, 2386);
            }
            break;

            case 9:
            {
                ret = new GSize(8594, 5966);
            }
            break;

            case 10:
            {
                ret = new GSize(17189, 11932);
            }
            break;

            case 11:
            {
                ret = new GSize(42972, 29831);
            }
            break;

            case 12:
            {
                ret = new GSize(85944, 59662);
            }
            break;

                #endregion
            }

            return(ret);
        }
Esempio n. 29
0
        private void LoadBitmap()
        {
            fBitmap = GetIcon(Type.ToString());
            Size    = new GSize(fBitmap.Width, fBitmap.Height);

            switch (Type)
            {
            case GMarkerIconType.arrow:
            {
                Offset = new GPoint(-11, -Size.Height);
                if (fArrowShadow == null)
                {
                    fArrowShadow = GetIcon("arrow_shadow");
                }
                fBitmapShadow = fArrowShadow;
            }
            break;

            case GMarkerIconType.blue:
            case GMarkerIconType.blue_dot:
            case GMarkerIconType.green:
            case GMarkerIconType.green_dot:
            case GMarkerIconType.yellow:
            case GMarkerIconType.yellow_dot:
            case GMarkerIconType.lightblue:
            case GMarkerIconType.lightblue_dot:
            case GMarkerIconType.orange:
            case GMarkerIconType.orange_dot:
            case GMarkerIconType.pink:
            case GMarkerIconType.pink_dot:
            case GMarkerIconType.purple:
            case GMarkerIconType.purple_dot:
            case GMarkerIconType.red:
            case GMarkerIconType.red_dot:
            {
                Offset = new GPoint(-Size.Width / 2 + 1, -Size.Height + 1);
                if (fMarkerShadow == null)
                {
                    fMarkerShadow = GetIcon("msmarker_shadow");
                }
                fBitmapShadow = fMarkerShadow;
            }
            break;

            case GMarkerIconType.black_small:
            case GMarkerIconType.blue_small:
            case GMarkerIconType.brown_small:
            case GMarkerIconType.gray_small:
            case GMarkerIconType.green_small:
            case GMarkerIconType.yellow_small:
            case GMarkerIconType.orange_small:
            case GMarkerIconType.purple_small:
            case GMarkerIconType.red_small:
            case GMarkerIconType.white_small:
            {
                Offset = new GPoint(-Size.Width / 2, -Size.Height + 1);
                if (fShadowSmall == null)
                {
                    fShadowSmall = GetIcon("shadow_small");
                }
                fBitmapShadow = fShadowSmall;
            }
            break;
            }
        }
Esempio n. 30
0
      public override GSize GetTileMatrixMinXY(int zoom)
      {
         GSize ret = GSize.Empty;

         switch(zoom)
         {
            #region -- sizes --
            case 0:
            {
               ret = new GSize(13, 8);
            }
            break;

            case 1:
            {
               ret = new GSize(26, 17);
            }
            break;

            case 2:
            {
               ret = new GSize(39, 26);
            }
            break;

            case 3:
            {
               ret = new GSize(79, 52);
            }
            break;

            case 4:
            {
               ret = new GSize(159, 105);
            }
            break;

            case 5:
            {
               ret = new GSize(399, 262);
            }
            break;

            case 6:
            {
               ret = new GSize(798, 525);
            }
            break;

            case 7:
            {
               ret = new GSize(1597, 1050);
            }
            break;

            case 8:
            {
               ret = new GSize(3195, 2101);
            }
            break;

            case 9:
            {
               ret = new GSize(7989, 5254);
            }
            break;

            case 10:
            {
               ret = new GSize(15978, 10509);
            }
            break;

            case 11:
            {
               ret = new GSize(39945, 26273);
            }
            break;
            #endregion
         }

         return ret;
      }
Esempio n. 31
0
        public override GSize GetTileMatrixMaxXY(int zoom)
        {
            GSize ret = GSize.Empty;

            switch (zoom)
            {
                #region -- sizes --
            case 0:
            {
                ret = new GSize(14, 9);
            }
            break;

            case 1:
            {
                ret = new GSize(28, 18);
            }
            break;

            case 2:
            {
                ret = new GSize(43, 28);
            }
            break;

            case 3:
            {
                ret = new GSize(86, 56);
            }
            break;

            case 4:
            {
                ret = new GSize(173, 112);
            }
            break;

            case 5:
            {
                ret = new GSize(434, 282);
            }
            break;

            case 6:
            {
                ret = new GSize(868, 564);
            }
            break;

            case 7:
            {
                ret = new GSize(1737, 1129);
            }
            break;

            case 8:
            {
                ret = new GSize(3474, 2258);
            }
            break;

            case 9:
            {
                ret = new GSize(8686, 5647);
            }
            break;

            case 10:
            {
                ret = new GSize(17372, 11294);
            }
            break;

            case 11:
            {
                ret = new GSize(43430, 28236);
            }
            break;
                #endregion
            }

            return(ret);
        }
Esempio n. 32
0
        /// <summary>
        /// gets matrix size in pixels
        /// </summary>
        /// <param name="zoom"></param>
        /// <returns></returns>
        public virtual GSize GetTileMatrixSizePixel(int zoom)
        {
            GSize s = GetTileMatrixSizeXY(zoom);

            return(new GSize(s.Width * TileSize.Width, s.Height * TileSize.Height));
        }
Esempio n. 33
0
 public SphericalMercatorProjection()
 {
     this.tileSize = new GSize(256, 256);
     EpsgCode      = 3857;
 }
Esempio n. 34
0
        void bg_DoWork(object sender, DoWorkEventArgs e)
        {
            MapInfo info = (MapInfo)e.Argument;

            if (!info.Area.IsEmpty)
            {
                string bigImage = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + Path.DirectorySeparatorChar + "GMap at zoom " + info.Zoom + " - " + info.Type + "-" + DateTime.Now.Ticks + ".jpg";
                e.Result = bigImage;

                // current area
                GPoint topLeftPx     = info.Type.Projection.FromLatLngToPixel(info.Area.LocationTopLeft, info.Zoom);
                GPoint rightButtomPx = info.Type.Projection.FromLatLngToPixel(info.Area.Bottom, info.Area.Right, info.Zoom);
                GPoint pxDelta       = new GPoint(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y);
                GSize  maxOfTiles    = info.Type.Projection.GetTileMatrixMaxXY(info.Zoom);

                int padding = info.MakeWorldFile || info.MakeKmz ? 0 : 22;
                {
                    //gfx = Graphics.FromImage(bmpDe)
                    Bitmap bmpDestination = new Bitmap((int)(pxDelta.X + padding * 2), (int)(pxDelta.Y + padding * 2));
                    gfx = Graphics.FromImage(bmpDestination);

                    gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    gfx.SmoothingMode     = SmoothingMode.HighQuality;

                    int i = 0;

                    // get tiles & combine into one
                    lock (tileArea) {
                        foreach (var p in tileArea)
                        {
                            if (bg.CancellationPending)
                            {
                                e.Cancel = true;
                                return;
                            }

                            int pc = (int)(((double)++i / tileArea.Count) * 100);
                            bg.ReportProgress(pc, p);

                            foreach (var tp in info.Type.Overlays)
                            {
                                Exception ex;
                                GMapImage tile;

                                // tile number inversion(BottomLeft -> TopLeft) for pergo maps
                                if (tp.InvertedAxisY)
                                {
                                    tile = GMaps.Instance.GetImageFrom(tp, new GPoint(p.X, maxOfTiles.Height - p.Y), info.Zoom, out ex) as GMapImage;
                                }
                                else   // ok
                                {
                                    tile = GMaps.Instance.GetImageFrom(tp, p, info.Zoom, out ex) as GMapImage;
                                }

                                if (tile != null)
                                {
                                    using (tile) {
                                        long x = p.X * info.Type.Projection.TileSize.Width - topLeftPx.X + padding;
                                        long y = p.Y * info.Type.Projection.TileSize.Width - topLeftPx.Y + padding;
                                        {
                                            gfx.DrawImage(tile.Img, x, y, info.Type.Projection.TileSize.Width, info.Type.Projection.TileSize.Height);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // draw info
                    if (!info.MakeWorldFile)
                    {
                        System.Drawing.Rectangle rect = new System.Drawing.Rectangle();
                        {
                            rect.Location = new System.Drawing.Point(padding, padding);
                            rect.Size     = new System.Drawing.Size((int)pxDelta.X, (int)pxDelta.Y);
                        }

                        using (Font f = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold)) {
                            if (cb_drawinfo.Checked)
                            {
                                // draw bounds & coordinates
                                using (Pen p = new Pen(Brushes.DimGray, 3)) {
                                    p.DashStyle = DashStyle.DashDot;

                                    gfx.DrawRectangle(p, rect);

                                    string topleft = info.Area.LocationTopLeft.ToString();
                                    SizeF  s       = gfx.MeasureString(topleft, f);

                                    gfx.DrawString(topleft, f, p.Brush, rect.X + s.Height / 2, rect.Y + s.Height / 2);

                                    string rightBottom = new PointLatLng(info.Area.Bottom, info.Area.Right).ToString();
                                    SizeF  s2          = gfx.MeasureString(rightBottom, f);

                                    gfx.DrawString(rightBottom, f, p.Brush, rect.Right - s2.Width - s2.Height / 2, rect.Bottom - s2.Height - s2.Height / 2);
                                }
                            }

                            if (cb_drawscale.Checked)
                            {
                                // draw scale
                                using (Pen p = new Pen(Brushes.Blue, 1)) {
                                    double rez    = info.Type.Projection.GetGroundResolution(info.Zoom, info.Area.Bottom);
                                    int    px100  = (int)(100.0 / rez);  // 100 meters
                                    int    px1000 = (int)(1000.0 / rez); // 1km

                                    gfx.DrawRectangle(p, rect.X + 10, rect.Bottom - 20, px1000, 10);
                                    gfx.DrawRectangle(p, rect.X + 10, rect.Bottom - 20, px100, 10);

                                    string leftBottom = "scale: 100m | 1Km";
                                    SizeF  s          = gfx.MeasureString(leftBottom, f);
                                    gfx.DrawString(leftBottom, f, p.Brush, rect.X + 10, rect.Bottom - s.Height - 20);
                                }
                            }
                        }


                        bmpDestination.Save(bigImage, ImageFormat.Jpeg);
                    }
                }
            }
        }
Esempio n. 35
0
        public override GSize GetTileMatrixMinXY(int zoom)
        {
            GSize ret = GSize.Empty;

            switch (zoom)
            {
                #region -- sizes --
            case 0:
            {
                ret = new GSize(12, 8);
            }
            break;

            case 1:
            {
                ret = new GSize(24, 17);
            }
            break;

            case 2:
            {
                ret = new GSize(37, 25);
            }
            break;

            case 3:
            {
                ret = new GSize(74, 51);
            }
            break;

            case 4:
            {
                ret = new GSize(149, 103);
            }
            break;

            case 5:
            {
                ret = new GSize(374, 259);
            }
            break;

            case 6:
            {
                ret = new GSize(749, 519);
            }
            break;

            case 7:
            {
                ret = new GSize(1594, 1100);
            }
            break;

            case 8:
            {
                ret = new GSize(3188, 2201);
            }
            break;

            case 9:
            {
                ret = new GSize(7971, 5502);
            }
            break;

            case 10:
            {
                ret = new GSize(15943, 11005);
            }
            break;

            case 11:
            {
                ret = new GSize(39858, 27514);
            }
            break;

            case 12:
            {
                ret = new GSize(79716, 27514);
            }
            break;

                #endregion
            }

            return(ret);
        }