windowsforms-16954-controls-and-libraries-map-control-examples-map-image-data-how-to-show-image-tiles-loading-progress-from-the-web-data-service.md
This example shows how to visualize the progress of loading image tiles from the OpenStreetMap data provider using a progress bar.
To accomplish this task, handle the ImageLayer.RequestDataLoading event and specify how the progress bar should be updated using the UpdateProgressBar method. Then, handle the LayerBase.DataLoaded event to specify the final state of the progress bar when the data load is finished.
using DevExpress.XtraMap;
using System;
using System.Windows.Forms;
namespace TilesLoaded {
public partial class Form1 : Form {
int requestsCounter = 0;
ImageLayer Layer { get { return (ImageLayer)mapControl1.Layers[0]; } }
public Form1() {
InitializeComponent();
Layer.RequestDataLoading += Layer_RequestDataLoading;
Layer.DataLoaded += Layer_DataLoaded;
}
void Layer_RequestDataLoading(object sender, EventArgs e) {
requestsCounter++;
UpdateProgressBar();
}
void Layer_DataLoaded(object sender, DataLoadedEventArgs e) {
progressBar1.Value = 100;
progressBar1.Visible = false;
label1.Visible = false;
requestsCounter = 0;
}
void UpdateProgressBar() {
if (!progressBar1.Visible)
progressBar1.Visible = true;
if (!label1.Visible)
label1.Visible = true;
progressBar1.Value = (int)(100 * (requestsCounter - 1) / requestsCounter);
}
}
}
Imports DevExpress.XtraMap
Imports System
Imports System.Windows.Forms
Namespace TilesLoaded
Partial Public Class Form1
Inherits Form
Private requestsCounter As Integer = 0
Private ReadOnly Property Layer() As ImageLayer
Get
Return CType(mapControl1.Layers(0), ImageLayer)
End Get
End Property
Public Sub New()
InitializeComponent()
AddHandler Layer.RequestDataLoading, AddressOf Layer_RequestDataLoading
AddHandler Layer.DataLoaded, AddressOf Layer_DataLoaded
End Sub
Private Sub Layer_RequestDataLoading(ByVal sender As Object, ByVal e As EventArgs)
requestsCounter += 1
UpdateProgressBar()
End Sub
Private Sub Layer_DataLoaded(ByVal sender As Object, ByVal e As DataLoadedEventArgs)
progressBar1.Value = 100
progressBar1.Visible = False
label1.Visible = False
requestsCounter = 0
End Sub
Private Sub UpdateProgressBar()
If Not progressBar1.Visible Then
progressBar1.Visible = True
End If
If Not label1.Visible Then
label1.Visible = True
End If
progressBar1.Value = CInt(100 * (requestsCounter - 1) \ requestsCounter)
End Sub
End Class
End Namespace