Here is how I got Mapsui to show maps in AutoCAD add-in with WPF window (being modeless or modal makes no different):
1. Start a AutoCAD DLL project (.NET Framework Class Library) in Visual Studio, choose .NET 4.7 as target (depending on your AutoCAD version, it could be 4.6, or 4.
, add necessary Acad .NET assembly references, of course;
2. Add NuGet Package of Mapsui. Pay attention here: when browsing/searching Nuget package, you need to select the correct ons, circled in red, as shown in attached picture. You probably do not need to install all 5 packages one by one; choose "Mapsui3.UI.Wpf" and install it would also install other needed dependent packages anyway.
3. Then, you add a WPF UserControl into the project (and then change it from <UserControl.../> to <Window..../>
4. Here is the simple XAML for the window:
<Window x:Class="MapsuiTest.MapView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MapsuiTest"
xmlns:mapsui="clr-namespace:Mapsui.UI.Wpf;assembly=Mapsui.UI.Wpf"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" ResizeMode="NoResize"
Width="900" Height="700" WindowStartupLocation="CenterOwner">
<Grid>
<mapsui:MapControl x:Name="MyMapControl" />
</Grid>
</Window>
5. Here is the code behind the window:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BruTile.Predefined;
using Mapsui.Layers;
namespace MapsuiTest
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class MapView : Window
{
public MapView()
{
InitializeComponent();
Loaded += (o, e) =>
{
MyMapControl.Map.Layers.Add(
new TileLayer(KnownTileSources.Create()));
};
}
}
}
6. Here is the CommandMethod to show the map window:
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CadApp = Autodesk.AutoCAD.ApplicationServices.Application;
[assembly: CommandClass(typeof(MapsuiTest.MyCommands))]
namespace MapsuiTest
{
public class MyCommands
{
[CommandMethod("ShowMap")]
public static void RunMyCommand()
{
try
{
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
var view = new MapView();
CadApp.ShowModalWindow(CadApp.MainWindow.Handle, view);
}
finally
{
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
}
}
}
}
The picture of the map window in AutoCAD as the result of the command is also attached.
While the Mapsui WPF component renders map really really smooth, in comparison with other mapping tools, such as ArcGIS's AutoCAD addin, it is a bit annoying that it bringS so may DLL files (30+) to our Acad add-in.
Again, I used Acad2020. But I do not see why it would not work with earlier versions. or later one (Acad2021).