Hello. I have just tried to use MapWinGIS 5.2 control in WPF Net Core 3.1 project.
My csproj:
My project dependencies:
To install MapWinGIS to WPF, I followed this tutorial: WPF创建MapWinGis项目(一)_u010209404的博客-程序员秘密_mapwingis类库 - 程序员秘密 (cxymm.net).
All worked fine until I started messing around with layers.
I used this code:
namespace KP
{
using AxMapWinGIS;
using MapWinGIS;
public partial class Mestorojdenia : Window
{
private string con = @"MSSQL:server=.\sqlexpress;database=BD;trusted_connection=yes";
private string query_mestorojdeniaPoint = "SELECT * FROM Mestorojdenie1";
private AxMap axMap;
private int hndl_mestorojdeniaPoint = 0;
public OgrDatasource ds = new OgrDatasource();
public Mestorojdenia()
{
InitializeComponent();
DataContext = new MestorojdeniaViewModel();
axMap = new AxMap()
{
Dock = System.Windows.Forms.DockStyle.Fill
};
_FormsPanel.Controls.Add(axMap);
}
private void MestorojdeniaGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (MestorojdeniaGrid.SelectedItem != null)
{
Mestorojdenie Mestorojdenie = MestorojdeniaGrid.SelectedItem as Mestorojdenie;
var mvm = DataContext as MestorojdeniaViewModel;
mvm.Mestorojdenie = Mestorojdenie.Name;
mvm.Mestopolojenie = Mestorojdenie.Mestopolojenie;
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
axMap.Projection = MapWinGIS.tkMapProjection.PROJECTION_GOOGLE_MERCATOR;
axMap.TileProvider = MapWinGIS.tkTileProvider.OpenStreetMap;
axMap.GrabProjectionFromData = true;
axMap.Tiles.DoCaching[tkCacheType.RAM] = true;
axMap.Redraw3(tkRedrawType.RedrawSkipAllLayers, true);
axMap.ShowZoomBar = true;
axMap.MapUnits = tkUnitsOfMeasure.umMeters;
axMap.ReuseTileBuffer = true;
axMap.KnownExtents = tkKnownExtents.keNone;
axMap.CursorMode = tkCursorMode.cmIdentify;
axMap.MapUnits = tkUnitsOfMeasure.umMeters;
axMap.SendMouseDown = true;
axMap.Latitude = 57.1612968f;
axMap.Longitude = 65.5239944f;
axMap.CurrentZoom = 12;
OgrLayer lr_mestorojdeniaPoint;
if (ds.Open(con))
{
axMap.Projection = MapWinGIS.tkMapProjection.PROJECTION_GOOGLE_MERCATOR;
axMap.Tiles.Provider = tkTileProvider.OpenStreetMap;
new GlobalSettings() { ReprojectLayersOnAdding = true };
lr_mestorojdeniaPoint = ds.RunQuery(query_mestorojdeniaPoint);
ds.Close();
}
else
{
MessageBox.Show("Не подключилось чего-то");
return;
}
if (lr_mestorojdeniaPoint != null)
{
axMap.RemoveAllLayers();
hndl_mestorojdeniaPoint = axMap.AddLayer(lr_mestorojdeniaPoint, true);
Shapefile sf_mestorojdeniaPoint = axMap.get_Shapefile(hndl_mestorojdeniaPoint);
sf_mestorojdeniaPoint.Identifiable = true;
sf_mestorojdeniaPoint.Selectable = true;
sf_mestorojdeniaPoint.GenerateLabels(sf_mestorojdeniaPoint.get_FieldIndexByName("Name"), tkLabelPositioning.lpCenter);
sf_mestorojdeniaPoint.Labels.FrameVisible = true;
sf_mestorojdeniaPoint.Labels.FrameType = tkLabelFrameType.lfRectangle;
sf_mestorojdeniaPoint.Labels.Synchronized = true;
MessageBox.Show(sf_mestorojdeniaPoint.NumShapes.ToString());
}
}
}
}
App crashes on this line
hndl_mestorojdeniaPoint = axMap.AddLayer(lr_mestorojdeniaPoint, true);
As a result:
System.PlatformNotSupportedException: "Operation is not supported on this platform."
I am wondering maybe i need to change somehow TargetFramework to get it work.
UPD: Changing TargetFramework breaks NuGet packages so its another challenge.
Not sure, maybe someone experienced this problem and knows how to solve. Suggestions appreciated.
I could redo everything in Winforms but lots of work done on WPF and no way to go back.