如果在进行argis二次开发的时候没有进行mapcontrol控件的初始化,往往会遇到莫名其妙的问题,比如读取栅格数据闪退,创建数据库失败,自定义坐标系或者未知坐标系的图层无法读取等,解决方案如下:
cs
在主程序初始化时加上如下代码:
private void Initial()
{
var win = new Window()
{
Content = new WindowsFormsHost() { Child = new AxMapControl() },
WindowState = WindowState.Minimized
};
win.Loaded += (s, e) =>
{
var host = ((Window)s).Content as WindowsFormsHost;
host.Child.Dispose();
host.Dispose();
((Window)s).Close();
};
win.Show();
}
bs
在Application_Start函数中进行调用Initial()函数
arcgis授权可参考往期博客
https://blog.csdn.net/qq_36047595/article/details/111770931
/// <summary>
/// 加载许可以及控件初始化处理
/// </summary>
public static void Initial()
{
//arcgis授权
LoadLicense();
//初始化AxMapControl控件,否则栅格读取会闪退
Thread thread = new Thread(() =>
{
ShowWindow();
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
private static void ShowWindow()
{
//初始化控件的代码
var win = new Window()
{
Content = new WindowsFormsHost() { Child = new AxMapControl() },
WindowState = WindowState.Minimized
};
win.Loaded += (s, e) =>
{
var host = ((Window)s).Content as WindowsFormsHost;
host.Child.Dispose();
host.Dispose();
((Window)s).Close();
};
win.ShowDialog();
}