wpf-devexpress-dot-xpf-dot-map-a1787658.md
Provides the map with image tiles.
Namespace : DevExpress.Xpf.Map
Assembly : DevExpress.Xpf.Map.v25.2.dll
NuGet Package : DevExpress.Wpf.Map
public class ImageTileDataProvider :
MapTileDataProviderBase
Public Class ImageTileDataProvider
Inherits MapTileDataProviderBase
This provider allows you to load image tiles created at runtime from almost any source.
To use the Image Tile Data Provider, assign a ImageTileDataProvider object to the ImageLayer.DataProvider property.
Specify the TileSource property to configure the provider’s image tile source.
This example shows how to use an ImageTileDataProvider instance to generate map tiles.
ImageTileDataProvider object and assign it to the ImageLayer.DataProvider property.<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DXMapInMemoryTileProvider"
xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/map"
x:Class="DXMapInMemoryTileProvider.MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<dxm:MapControl>
<dxm:ImageLayer x:Name="imageLayer"/>
</dxm:MapControl>
</Grid>
</Window>
using DevExpress.Xpf.Map;
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace DXMapInMemoryTileProvider {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
ImageTileDataProvider tileDataProvider = new ImageTileDataProvider();
tileDataProvider.TileSource = new SimpleTileGenerator();
this.imageLayer.DataProvider = tileDataProvider;
}
}
public class SimpleTileGenerator : ImageTileSource {
Random rnd = new Random();
public override string Name => nameof(SimpleTileGenerator);
public override ImageSource GetImageSource(long x, long y, int level, Size size) {
DrawingVisual drawingVisual = new DrawingVisual();
using (DrawingContext drawingContext = drawingVisual.RenderOpen()) {
FormattedText text = new FormattedText($"{x}:{y}:{level}", new CultureInfo("en-us"),
FlowDirection.LeftToRight, new Typeface("Arial"), 14, Brushes.Black);
drawingContext.DrawRectangle(new SolidColorBrush(Color.FromArgb(128, (byte)rnd.Next(255),
(byte)rnd.Next(255), (byte)rnd.Next(255))), null,
new Rect(new Point(), size));
drawingContext.DrawText(text, new Point(5, 5));
drawingContext.Close();
}
RenderTargetBitmap bmp = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Pbgra32);
bmp.Render(drawingVisual);
return bmp;
}
protected override MapDependencyObject CreateObject() {
return new SimpleTileGenerator();
}
}
}
Imports DevExpress.Xpf.Map
Imports System
Imports System.Globalization
Imports System.Windows
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Namespace DXMapInMemoryTileProvider
Public Partial Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
Dim tileDataProvider As ImageTileDataProvider = New ImageTileDataProvider()
tileDataProvider.TileSource = New SimpleTileGenerator()
Me.imageLayer.DataProvider = tileDataProvider
End Sub
End Class
Public Class SimpleTileGenerator
Inherits ImageTileSource
Private rnd As Random = New Random()
Public Overrides ReadOnly Property Name As String
Get
Return NameOf(SimpleTileGenerator)
End Get
End Property
Public Overrides Function GetImageSource(ByVal x As Long, ByVal y As Long, ByVal level As Integer, ByVal size As Size) As ImageSource
Dim drawingVisual As DrawingVisual = New DrawingVisual()
Using drawingContext As DrawingContext = drawingVisual.RenderOpen()
Dim text As FormattedText = New FormattedText($"{x}:{y}:{level}", New CultureInfo("en-us"), FlowDirection.LeftToRight, New Typeface("Arial"), 14, Brushes.Black)
drawingContext.DrawRectangle(New SolidColorBrush(Color.FromArgb(128, CByte(rnd.[Next](255)), CByte(rnd.[Next](255)), CByte(rnd.[Next](255)))), Nothing, New Rect(New Point(), size))
drawingContext.DrawText(text, New Point(5, 5))
drawingContext.Close()
End Using
Dim bmp As RenderTargetBitmap = New RenderTargetBitmap(CInt(size.Width), CInt(size.Height), 96, 96, PixelFormats.Pbgra32)
bmp.Render(drawingVisual)
Return bmp
End Function
Protected Overrides Function CreateObject() As MapDependencyObject
Return New SimpleTileGenerator()
End Function
End Class
End Namespace
Show 12 items
Object DispatcherObject DependencyObject Freezable MapDependencyObject MapImageDataProviderBase DevExpress.Xpf.Map.MapTileDataProviderBase ImageTileDataProvider VectorTileDataProviderBase
UriBasedVectorTileDataProvider
See Also