Пример #1
0
        // gets the tile set of maps with the given coords of the center, width and height of tiling
        // and configuration for the center tile
        public static void DownloadNewTileSet(MapConfiguration config, BackgroundWorker worker)
        {
            String fileName = Directory.GetCurrentDirectory().ToString() + @"\Images\" + config.MapSetName + ".map";

            using (StreamWriter file = new StreamWriter(fileName))
            {
                Tuple <int, int> centerPoint = MapConversion.LatLongToPixelXY(config.Latitude,
                                                                              config.Longitude, config.Zoom);

                file.WriteLine(config.ImgWidth + "x" + config.ImgHeight + "|" + config.Latitude + ","
                               + config.Longitude + "|" + config.Zoom + "|" + config.Scale + "|" + config.MapType);

                // center of the tiling is 0,0
                int startx = -config.TilingWidth / 2;
                int starty = -config.TilingHeight / 2;
                if (config.TilingWidth % 2 == 0)
                {
                    startx++;
                }
                if (config.TilingHeight % 2 == 0)
                {
                    starty++;
                }
                int numberDownloaded = 0;

                for (int i = startx; i <= config.TilingWidth / 2; i++)
                {
                    for (int j = starty; j <= config.TilingHeight / 2; j++)
                    {
                        if (worker != null)
                        {
                            worker.ReportProgress(numberDownloaded);
                        }

                        Tuple <double, double> newCoords = MapConversion.PixelXYToLatLong
                                                               (centerPoint.Item1 + (i * config.ImgWidth), centerPoint.Item2
                                                               + (j * config.ImgHeight), config.Zoom);
                        config.Latitude  = newCoords.Item1;
                        config.Longitude = newCoords.Item2;
                        string imageName = Fetch(config);
                        if (imageName != null)
                        {
                            file.WriteLine(i + "," + j + "|" + imageName);
                        }

                        numberDownloaded++;
                    }
                }
            }
        }
Пример #2
0
        // gets the tile set of maps with the given coords of the center, width and height of tiling
        // and configuration for the center tile
        public static void DownloadNewTileSet(Tuple <int, int> tilingDim, Configuration config, String mapSetName)
        {
            String fileName = Directory.GetCurrentDirectory().ToString() + @"\MapTiles\" + mapSetName + ".txt";

            using (StreamWriter file = new StreamWriter(fileName))
            {
                int    zoom;
                int    imgWidth;
                int    imgHeight;
                double longe;
                double lat;

                String[] imgDim = config.GetImageDim().Split('x');
                String[] coords = config.GetLocation().Split(',');
                Int32.TryParse(imgDim[0], out imgWidth);
                Int32.TryParse(imgDim[1], out imgHeight);
                Int32.TryParse(config.GetZoom(), out zoom);
                Double.TryParse(coords[0], out lat);
                Double.TryParse(coords[1], out longe);

                Tuple <int, int> centerPoint = MapConversion.LatLongToPixelXY(lat, longe, zoom);

                file.WriteLine(config.GetImageDim() + "|" + zoom + "|" + config.GetScale());

                // center of the tiling is 0,0
                int startx = -tilingDim.Item1 / 2;
                int starty = -tilingDim.Item2 / 2;
                if (tilingDim.Item1 % 2 == 0)
                {
                    startx++;
                }
                if (tilingDim.Item2 % 2 == 0)
                {
                    starty++;
                }

                for (int i = startx; i <= tilingDim.Item1 / 2; i++)
                {
                    for (int j = starty; j <= tilingDim.Item2 / 2; j++)
                    {
                        Tuple <double, double> newCoords = MapConversion.PixelXYToLatLong
                                                               (centerPoint.Item1 + (i * imgWidth), centerPoint.Item2 + (j * imgHeight), zoom);
                        config.SetLocation(newCoords);
                        file.WriteLine(i + "," + j + "|" + Fetch(config));
                    }
                }
            }
        }