Author Topic: Display a web map in a WPF with Autocad 2013-2021  (Read 457 times)

0 Members and 1 Guest are viewing this topic.

helaman

  • Mosquito
  • Posts: 5
Display a web map in a WPF with Autocad 2013-2021
« on: February 25, 2021, 03:04:01 PM »
I am making a free topo tool that makes use of Mapsui maps ( https://github.com/Mapsui/Mapsui ) that reads and manipulates shape and KMZ files and then inserts them in model space already projected. The problem is that it doesn't show the map inside the window, I don't know if I have to do it asynchronous, with threads or I need to give it permission for external connections. I had already been able to display Arcgis Runtime maps but they were only displayed in AutoCAD 2020 and 2021, so I decided to use MapSui but the result was worse.
I am using the Autoloader (.bundle) structure to run the command, in that same folder I put all the necessary files for the map to work, but still it doesn't do it, it doesn't even give error.
Does anyone know why this happens? or do you have any alternative for the map, it should be noted that I do not want to use the map that brings autocad because it is only available in the 2015 version onwards and I need it from 2013 and its projection systems are limited to UTM.

Technologies:
C#
WPF
Visual studio 2019
Autocad dll base 2013
Mapsui

If you want me to pass you the project or .bundle folder, please comment

n.yuan

  • Bull Frog
  • Posts: 304
Re: Display a web map in a WPF with Autocad 2013-2021
« Reply #1 on: February 26, 2021, 10:37:10 AM »
Well, it looks to me that Mapsui is a map UI component to visualize map data, and in your case, you use its WPF support to display map. by itself, it has nothing to do with AutoCAD: AutoCAD only works as host to show the WPF UI (WPF window, or usercontrol). Whether the map displays or not depends on your code to use Mapsui component correctly or not. For easier debugging, you should be able to simply use Mapsui component in a WPF exe project, so to avoid the long wait for AutoCAD starting up and load your DLL. Before your DLL works/fully debugged, there is little sense to make a bundle to autoload the DLL. Again, I do not see your issue has anything to do with AutoCAD before you can use Mapsui to display map in a WPF exe app.

helaman

  • Mosquito
  • Posts: 5
Re: Display a web map in a WPF with Autocad 2013-2021
« Reply #2 on: February 26, 2021, 03:12:13 PM »
Well, it looks to me that Mapsui is a map UI component to visualize map data, and in your case, you use its WPF support to display map. by itself, it has nothing to do with AutoCAD: AutoCAD only works as host to show the WPF UI (WPF window, or usercontrol). Whether the map displays or not depends on your code to use Mapsui component correctly or not. For easier debugging, you should be able to simply use Mapsui component in a WPF exe project, so to avoid the long wait for AutoCAD starting up and load your DLL. Before your DLL works/fully debugged, there is little sense to make a bundle to autoload the DLL. Again, I do not see your issue has anything to do with AutoCAD before you can use Mapsui to display map in a WPF exe app.

I understand, and yes, the map runs as normal in .exe.
In fact it is already the second map I try to use, the previous one was ArcgisRuntime, and it only showed in autocad 2020 and 2021, Mapsui in any version, so it made me think that maybe it is some kind of AutoCAD configuration or the way to launch the form.
I have been using fiddler to see the HTTP requests in real time and apparently mapsui connects and reacts when you click on the window but nothing is displayed.

This is the code I used to display the form.
Code: [Select]
Mapsui.MainWindow map = new Mapsui.MainWindow();
         Application.ShowModalWindow(map);

Attached is an image where it looks like it works outside of AutoCAD.

n.yuan

  • Bull Frog
  • Posts: 304
Re: Display a web map in a WPF with Autocad 2013-2021
« Reply #3 on: February 27, 2021, 03:21:35 PM »
...
... the previous one was ArcgisRuntime, and it only showed in autocad 2020 and 2021, Mapsui in any version, ...

Sorry, I still do not fully understand what you said here (let's leave ArcGISRuntime out here and focus on Mapsui): do you mean if you use Mapsui with WPF UI to show map, it ONLY WORKS for Acad2020/2021, but not for any older version of AutoCAD (all the way to Acad2013)? or it does not work with any version of AutoCAD?

Clearly Mapsui works with stand-alone exe (I simply tried their sample project to verify it). Because I do not know exactly you said (run with Acad2020/2021 only, or not with any version of Acad), I went ahead to use WPF window in my Acad2020's add-in project and added Nuget package of "Mapsui3.UI.Wpf". My DLL runs OK in AutoCAD 2020 and the WPF window shows the map as expected.

Unfortunately, I do not have any older version of AutoCAD than 2020 available for a test. However, if your Acad add-in project is developed against any older version of AutoCAD, as long as your targeted .NET framework is not older that Mapsui3's (it seems it is .NET 4.6.2), it should work. Again, since I do not have access for older AutoCAD, I cannot give it a try.

But one thing is for sure: it has absolutely nothing to do with the add-in code being loaded from bundle or not.

helaman

  • Mosquito
  • Posts: 5
Re: Display a web map in a WPF with Autocad 2013-2021
« Reply #4 on: February 27, 2021, 04:55:02 PM »
...
... the previous one was ArcgisRuntime, and it only showed in autocad 2020 and 2021, Mapsui in any version, ...

Sorry, I still do not fully understand what you said here (let's leave ArcGISRuntime out here and focus on Mapsui): do you mean if you use Mapsui with WPF UI to show map, it ONLY WORKS for Acad2020/2021, but not for any older version of AutoCAD (all the way to Acad2013)? or it does not work with any version of AutoCAD?

Clearly Mapsui works with stand-alone exe (I simply tried their sample project to verify it). Because I do not know exactly you said (run with Acad2020/2021 only, or not with any version of Acad), I went ahead to use WPF window in my Acad2020's add-in project and added Nuget package of "Mapsui3.UI.Wpf". My DLL runs OK in AutoCAD 2020 and the WPF window shows the map as expected.

Unfortunately, I do not have any older version of AutoCAD than 2020 available for a test. However, if your Acad add-in project is developed against any older version of AutoCAD, as long as your targeted .NET framework is not older that Mapsui3's (it seems it is .NET 4.6.2), it should work. Again, since I do not have access for older AutoCAD, I cannot give it a try.

But one thing is for sure: it has absolutely nothing to do with the add-in code being loaded from bundle or not.

I really appreciate you taking the time to investigate the problem.
And yes, an apology, I was using arcgis maps and switched to mapsui to try my luck.

You are right, let's focus on mapsui, I tried running it in several versions of autoCAD (2013, 2017,2019,2020) and it did not show me the map in any of them.
Now, I would like to know, if you would be so kind, what files you used for the plugin and how you deployed them.
The framework I am using is 4.7.2, I think there is no problem with that.

I am going to create a new project and install the same nuget package to see what result I get.

n.yuan

  • Bull Frog
  • Posts: 304
Re: Display a web map in a WPF with Autocad 2013-2021
« Reply #5 on: February 28, 2021, 08:47:16 AM »
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.8), 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:

Code: [Select]
<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:

Code: [Select]
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:

Code: [Select]
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).

helaman

  • Mosquito
  • Posts: 5
Re: Display a web map in a WPF with Autocad 2013-2021
« Reply #6 on: February 28, 2021, 11:41:23 PM »
I tested your code and it ran without problems, I would like to say that everything was fixed but it is not.

I ran it in AutoCAD 2020, 2019 and 2013, it only showed the map in the 2020 version, like you. (I attach an image)

In version 2019 and 2013 there was no response. Now, check the sessions with fiddler and with 2019 and 2013 it has this behavior.

In contrast to the 2020 version.

Apart from the amount of requests that are made when the map is not displayed as opposed to when it does, I see that the version of SSL and TSL are lower in AutoCAD 2019 and 2013, I do not know if that is because of fiddler or is a normal behavior when there is no response but I found that difference interesting.
If that is the problem I don't know if I can change those parameters.

The red lines are AutoCAD 2019 and the blue lines are AutoCAD 2020.
The green lines are AutoCAD 2013 but they are almost the same as AutoCAD 2019.


helaman

  • Mosquito
  • Posts: 5
Re: Display a web map in a WPF with Autocad 2013-2021
« Reply #7 on: March 01, 2021, 03:14:09 PM »
I did it, I was able to solve it, if it was the version of the TLS protocol, apparently on August 3, 2019 the version of the transport layer was updated for a security issue from versions 1.0 and 1.1 to version 1.2, just the one that comes out in the images I showed.
Update was sent for all previous versions of AutoCAD 2019 as it says here (https://knowledge.autodesk.com/search-result/caas/simplecontent/content/transport-layer-security-tls-updates-required-to-maintain-software-access.html).
My AutoCAD 2019 was not updated that's why it did not show the map and the previous versions only needed to update that security patch.

Only the problem was the change in AutoCAD 2013, as it is no longer considered in the updates, but I found that adding these lines to the "acad.exe.config" file solved it.

Code: [Select]

<runtime>
    <AppContextSwitchOverrides
         value="Switch.System.ServiceModel.DisableUsingServicePointManagerSecurityProtocols=false;Switch.System.Net.DontEnableSchUseStrongCrypto=false" />
</runtime>

I really appreciate the help you gave me @n.yuan. I hope this information will be useful to someone else if they have a similar problem to mine.

n.yuan

  • Bull Frog
  • Posts: 304
Re: Display a web map in a WPF with Autocad 2013-2021
« Reply #8 on: March 02, 2021, 10:42:25 AM »
thanks for letting us know the issue you identified and the solution.