示例#1
0
        /// <summary>
        /// Handles the click over the cell
        /// </summary>
        private void dgv_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }

            tkTileProvider provider = (tkTileProvider)dgv.Rows[e.RowIndex].Tag;

            switch (e.ColumnIndex)
            {
            case CMN_CLEAR:
                if (MessageBox.Show(String.Format("Do you want to clear the cache for the: {0}?", provider.ToString()),
                                    Application.ProductName,
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    this.tiles.ClearCache2(this.cacheType, provider, 0, 100);
                    dgv.Invalidate();
                }
                break;

            case CMN_SCALES:
                break;
            }
        }
        public static void Init(ToolStripMenuItem root)
        {
            root.DropDownItems.Clear();
            var item = root.DropDownItems.Add("No tiles");

            item.Click += item_Click;
            item.Tag    = -1;

            root.DropDownItems.Add(new ToolStripSeparator());

            var list = new tkTileProvider[]
            {
                tkTileProvider.OpenStreetMap, tkTileProvider.OpenTransportMap,
                tkTileProvider.OpenHumanitarianMap, tkTileProvider.OpenCycleMap,
                tkTileProvider.MapQuestAerial, tkTileProvider.BingMaps,
                tkTileProvider.BingHybrid, tkTileProvider.BingSatellite
            };

            foreach (var p in list)
            {
                item        = root.DropDownItems.Add(p.ToString());
                item.Click += item_Click;
                item.Tag    = (int)p;
            }

            root.DropDownItems.Add(new ToolStripSeparator());

            item        = root.DropDownItems.Add("Set Bing Maps API key");
            item.Click += item_Click;
            item.Tag    = Commands.SetBingApiKey;

            root.DropDownOpening += root_DropDownOpening;
            App.Map.Tiles.DoCaching[tkCacheType.Disk] = true;
            App.Map.Tiles.UseCache[tkCacheType.Disk]  = true;
        }
示例#3
0
        private void PrefetchToFolder(tkTileProvider tileProvider, int maxZoom, Extents latLongExtents)
        {
            // Set tiles provider:
            _axMap1.Tiles.Provider       = tileProvider;
            _axMap1.Tiles.GlobalCallback = this;

            Helper.DebugMsg("Tiles projection status: " + _axMap1.Tiles.ProjectionStatus);
            Helper.DebugMsg("_axMap1.Tiles.ProjectionIsSphericalMercator: " + _axMap1.Tiles.ProjectionIsSphericalMercator);

            var outputFolder = $@"D:\tmp\axmap.tiles\{_axMap1.Tiles.Provider.ToString()}";

            if (!Directory.Exists(outputFolder))
            {
                Directory.CreateDirectory(outputFolder);
            }
            _settings.StartLogTileRequests($@"D:\tmp\axmap.tiles\TileRequests-{_axMap1.Tiles.Provider.ToString()}.log");

            var providerId    = Convert.ToInt32(tileProvider);
            var numRounds     = 0;                                        // To prevent endless loops
            var maximizedZoom = Math.Min(maxZoom, _axMap1.Tiles.MaxZoom); // Prevent asking higher zoom than allowed

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            while (true)
            {
                var numTilesToCache = 0;
                for (var i = _axMap1.Tiles.MinZoom; i < maximizedZoom; i++)
                {
                    numTilesToCache +=
                        _axMap1.Tiles.PrefetchToFolder(latLongExtents, i, providerId, outputFolder, ".png", this);
                    Helper.DebugMsg($"numTilesToCache: {numTilesToCache} for zoom {i}");
                    // Wait a moment:
                    Thread.Sleep(2000);
                }

                numRounds++;
                Helper.DebugMsg($"Finished round {numRounds}");

                // Wait before doing another round:
                if (numTilesToCache > 0)
                {
                    Thread.Sleep(2000);
                }
                if (numTilesToCache == 0 || numRounds > 9)
                {
                    break;
                }
            }

            stopWatch.Stop();
            Helper.DebugMsg("Time it took: " + stopWatch.Elapsed);
        }
示例#4
0
        /// <summary>
        /// Draws the status bar for every provider
        /// </summary>
        private void dgv_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.ColumnIndex == CMN_STATUS && e.RowIndex != -1)
            {
                e.Paint(e.CellBounds, DataGridViewPaintParts.Background);
                e.Paint(e.CellBounds, DataGridViewPaintParts.Border);

                tkTileProvider provider = (tkTileProvider)dgv.Rows[e.RowIndex].Tag;

                // bounds for status
                Rectangle rect = new Rectangle(e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Width, e.CellBounds.Height);
                rect.Y      += 7;
                rect.X      += 10;
                rect.Height -= 14;
                rect.Width  -= 20;
                int width = rect.Width;

                double size         = tiles.get_CacheSize2(this.cacheType, provider, -1);
                double maxCacheSize = tiles.get_MaxCacheSize(this.cacheType);

                // particular status
                double ratio = size / maxCacheSize;
                if (ratio < 1.0)
                {
                    rect.Width = (int)((double)rect.Width * ratio);
                }

                Brush brush = new SolidBrush(Color.LightGreen);
                e.Graphics.FillRectangle(brush, rect);

                // bounds (initial)
                rect.Width = width;
                rect.X    -= 1;
                e.Graphics.DrawRectangle(new Pen(Color.Gray), rect);

                // drawing text
                e.Paint(e.CellBounds, DataGridViewPaintParts.ContentForeground);

                StringFormat format = new StringFormat();
                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Center;
                e.Graphics.DrawString(size.ToString("0.0") + " MB", dgv.Font,
                                      new SolidBrush(Color.Black),
                                      new PointF(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), format);

                e.Handled = true;
            }
        }
        private static void item_Click(object sender, EventArgs e)
        {
            var item = sender as ToolStripItem;

            if (item != null && item.Tag != null)
            {
                if ((int)item.Tag == (int)Commands.SetBingApiKey)
                {
                    SetBingApiKey();
                    return;
                }

                tkTileProvider provider = (tkTileProvider)item.Tag;
                switch (provider)
                {
                case tkTileProvider.BingSatellite:
                case tkTileProvider.BingMaps:
                case tkTileProvider.BingHybrid:
                    var gs = new GlobalSettings();
                    if (string.IsNullOrWhiteSpace(gs.BingApiKey))
                    {
                        if (!string.IsNullOrWhiteSpace(AppSettings.Instance.BingApiKey))
                        {
                            gs.BingApiKey = AppSettings.Instance.BingApiKey;
                        }
                        else
                        {
                            if (!SetBingApiKey())
                            {
                                return;
                            }
                        }
                    }
                    break;
                }
                App.Map.TileProvider = (tkTileProvider)item.Tag;
                App.Map.Redraw();
            }
        }
示例#6
0
        /// <summary>
        /// Reads settings from the file
        /// </summary>
        /// <param name="tiles">Reference to the tiles class</param>
        public static void Read(Tiles tiles)
        {
            if (tiles == null)
            {
                throw new ArgumentNullException("Reference to the tiles wasn't passed");
            }

            XElement root = XElement.Load(GetFilename());
            string   ns   = root.GetDefaultNamespace().NamespaceName;

            var list = from p in root.Descendants(XName.Get("DefaultProvider", ns))
                       where p.Attribute("Selected").Value != "0" select p;

            // setting versions
            foreach (var item in list)
            {
                tkTileProvider p     = (tkTileProvider)Convert.ToInt32(item.Attribute("Id").Value);
                int            index = tiles.Providers.get_IndexByProvider(p);
                tiles.Providers.set_Version(index, item.Attribute("Version").Value);
            }

            // updating custom providers
            tiles.Providers.Clear(false);
            var list2 = from p in root.Descendants(XName.Get("CustomProvider", ns))
                        where p.Attribute("Selected").Value != "0"
                        select new {
                Id         = Convert.ToInt32(p.Attribute("Id").Value),
                Name       = p.Attribute("Name").Value,
                Url        = p.Attribute("UrlPattern").Value,
                Projection = Convert.ToInt32(p.Attribute("Projection").Value)
            };

            foreach (var item in list2)
            {
                tiles.Providers.Add(item.Id, item.Name, item.Url, (tkTileProjection)item.Projection, 0, 17);
            }
        }
示例#7
0
 /// <summary>
 /// Gets the index of default provider in the list.
 /// </summary>
 /// <param name="Provider">Provider to find index for.</param>
 /// <returns>The index of provider in the list.</returns>
 public int get_IndexByProvider(tkTileProvider Provider)
 {
     throw new NotImplementedException();
 }
示例#8
0
 /// <summary>
 /// Gets the current size of cache used for specific provider and zoom level.
 /// </summary>
 /// <param name="cacheType">The type of cache to return size for.</param>
 /// <param name="Provider">Provider. ProviderNone will return size for all providers.</param>
 /// <param name="scale">Scale (zoom) level. -1 will return size for all zoom levels.</param>
 /// <returns>The size of cache in MB.</returns>
 public double get_CacheSize2(tkCacheType cacheType, tkTileProvider Provider = tkTileProvider.ProviderNone, int scale = -1)
 {
     throw new NotImplementedException();
 }
示例#9
0
 /// <summary>
 /// Clears cache of the specified to type for a given provider and scales.
 /// </summary>
 /// <param name="cacheType">Type of cache to be cleared.</param>
 /// <param name="Provider">Tile provider to be cleared. ProviderNone will clear tiles for all providers.</param>
 /// <param name="fromScale">Minimal scale (zoom) to clear tiles for.</param>
 /// <param name="toScale">Maximum scale (zoom) to clear tiles for.</param>
 public void ClearCache2(tkCacheType cacheType, tkTileProvider Provider, int fromScale = 0, int toScale = 100)
 {
     throw new NotImplementedException();
 }