Back to Devexpress

MiniMap Class

windowsforms-devexpress-dot-xtramap-a33f6776.md

latest7.0 KB
Original Source

MiniMap Class

Implements a mini map displayed within the MapControl.

Namespace : DevExpress.XtraMap

Assembly : DevExpress.XtraMap.v25.2.dll

NuGet Package : DevExpress.Win.Map

Declaration

csharp
public class MiniMap :
    MapDisposableObject,
    IOwnedElement,
    IMapView,
    IMapViewCore,
    ICoordinateSystemProvider,
    IRenderMiniMapContentProvider,
    IRenderContextProvider,
    IRenderStyleProvider,
    IUIThreadRunner,
    IServiceProvider,
    IMapStyleOwner,
    IRenderContextCreator,
    IDesignTimeItem,
    IUpdateSupportItem,
    IUnitConverterProvider,
    IItemVisibilityCalculatorProvider
vb
Public Class MiniMap
    Inherits MapDisposableObject
    Implements IOwnedElement,
               IMapView,
               IMapViewCore,
               ICoordinateSystemProvider,
               IRenderMiniMapContentProvider,
               IRenderContextProvider,
               IRenderStyleProvider,
               IUIThreadRunner,
               IServiceProvider,
               IMapStyleOwner,
               IRenderContextCreator,
               IDesignTimeItem,
               IUpdateSupportItem,
               IUnitConverterProvider,
               IItemVisibilityCalculatorProvider

The following members return MiniMap objects:

Example

Tip

The complete sample project is available on GitHub.

To add a mini map to a map, do the following.

csharp
// In the Form's constructor.
object data = LoadData(@"..\..\Data\Ships.xml");

// Create a mini map and data for it.
MiniMap miniMap = new MiniMap();
miniMap.Alignment = MiniMapAlignment.BottomLeft;
miniMap.Layers.AddRange(new MiniMapLayerBase[] {
    new MiniMapImageTilesLayer() {
        DataProvider = new BingMapDataProvider() {
            BingKey = "YOUR_BING_MAPS_KEY_HERE"
        }
    },
    new MiniMapVectorItemsLayer() {
        Data = CreateMiniMapAdapter(data)
    }
});
map.MiniMap = miniMap;

// Creates an adapter for the map's vector layer.
private IMapDataAdapter CreateAdapter(object source) {
    ListSourceDataAdapter adapter = new ListSourceDataAdapter();

    adapter.DataSource = source;

    adapter.Mappings.Latitude = "Latitude";
    adapter.Mappings.Longitude = "Longitude";

    adapter.AttributeMappings.Add(new MapItemAttributeMapping() { Member = "Name", Name = "Name" });
    adapter.AttributeMappings.Add(new MapItemAttributeMapping() { Member = "Year", Name = "Year" });
    adapter.AttributeMappings.Add(new MapItemAttributeMapping() { Member = "Description", Name = "Description" });

    return adapter;
}

// Loads data from a XML file.
private List<ShipwreckData> LoadData(string path) {
    return XDocument.Load(path).Element("Ships").Elements("Ship")
        .Select(e => new ShipwreckData(
            year: Convert.ToInt32(e.Element("Year").Value, CultureInfo.InvariantCulture),
            name: e.Element("Name").Value,
            description: e.Element("Description").Value,
            latitude: Convert.ToDouble(e.Element("Latitude").Value, CultureInfo.InvariantCulture),
            longitude: Convert.ToDouble(e.Element("Longitude").Value, CultureInfo.InvariantCulture)
        ))
        .ToList();
}

public class ShipwreckData {
    public int Year { get; }
    public string Name { get; }
    public string Description { get; }
    public double Latitude { get; }
    public double Longitude { get; }

    public ShipwreckData(int year, string name, string description, double latitude, double longitude) {
        this.Year = year;
        this.Name = name;
        this.Description = description;
        this.Latitude = latitude;
        this.Longitude = longitude;
    }
}
vb
' In the Form's constructor.
Dim data As Object = LoadData("..\..\Data\Ships.xml")

' Create a mini map and data for it.
Dim miniMap As New MiniMap()
miniMap.Alignment = MiniMapAlignment.BottomLeft
miniMap.Layers.AddRange(New MiniMapLayerBase() {
    New MiniMapImageTilesLayer() With {
        .DataProvider = New BingMapDataProvider() With {.BingKey = "YOUR_BING_MAPS_KEY_HERE"}
    },
    New MiniMapVectorItemsLayer() With {.Data = CreateMiniMapAdapter(data)}
})
map.MiniMap = miniMap

' Creates an adapter for the mini map's vector layer.
Private Function CreateMiniMapAdapter(ByVal source As Object) As IMapDataAdapter
    Dim adapter As New ListSourceDataAdapter()

    adapter.DataSource = source

    adapter.Mappings.Latitude = "Latitude"
    adapter.Mappings.Longitude = "Longitude"

    adapter.PropertyMappings.Add(New MapItemFillMapping() With {.DefaultValue = Color.Red})
    adapter.PropertyMappings.Add(New MapItemStrokeMapping() With {.DefaultValue = Color.White})
    adapter.PropertyMappings.Add(New MapItemStrokeWidthMapping() With {.DefaultValue = 2})
    adapter.PropertyMappings.Add(New MapDotSizeMapping() With {.DefaultValue = 8})

    adapter.DefaultMapItemType = MapItemType.Dot

    Return adapter
End Function

' Loads data from a XML file.
Private Function LoadData(ByVal path As String) As List(Of ShipwreckData)
    Return XDocument.Load(path).Element("Ships").Elements("Ship") _
        .Select(Function(e) New ShipwreckData(
            year:=Convert.ToInt32(e.Element("Year").Value, CultureInfo.InvariantCulture),
            name:=e.Element("Name").Value,
            description:=e.Element("Description").Value,
            latitude:=Convert.ToDouble(e.Element("Latitude").Value, CultureInfo.InvariantCulture),
            longitude:=Convert.ToDouble(e.Element("Longitude").Value, CultureInfo.InvariantCulture)
        )) _
        .ToList()
End Function

Public Class ShipwreckData
    Public ReadOnly Property Year() As Integer
    Public ReadOnly Property Name() As String
    Public ReadOnly Property Description() As String
    Public ReadOnly Property Latitude() As Double
    Public ReadOnly Property Longitude() As Double

    Public Sub New(ByVal year As Integer, ByVal name As String, ByVal description As String, ByVal latitude As Double, ByVal longitude As Double)
        Me.Year = year
        Me.Name = name
        Me.Description = description
        Me.Latitude = latitude
        Me.Longitude = longitude
    End Sub
End Class

Inheritance

Object MapDisposableObject MiniMap

See Also

MiniMap Members

DevExpress.XtraMap Namespace