界面需要自己设计出来,代码功能为遍历所有的图层,较为简单,作业要求只需要部分核心代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SuperMapLib;
using System.Runtime.InteropServices;
namespace test4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void connectSupermap()
{
object objHandle = axSuperWorkspace1.ObjectHandle;
axSuperMap1.Connect(objHandle);
Marshal.ReleaseComObject(objHandle);
}
private void menu_file_openWorkspace_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "(*.smw)|*.smw";
openFileDialog1.FileName = "";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string path = openFileDialog1.FileName;
bool flag = axSuperWorkspace1.Open(path, "");
if (flag)
{
MessageBox.Show("打开成功");
connectSupermap();
}
else
{
MessageBox.Show("打开失败");
}
}
}
private void getDataToolStripMenuItem_Click(object sender, EventArgs e)
{
int sourcesCount = axSuperWorkspace1.Datasources.Count;
for (int i = 1; i <= sourcesCount; i++)
{
soDatasets dataSets = axSuperWorkspace1.Datasources[i].Datasets;
int num = dataSets.Count;
for (int j = 1; j <= num; j++)
{
string s = dataSets[j].Name;
axSuperMap1.Layers.AddDataset(dataSets[j], true);
axSuperMap1.Refresh();
MessageBox.Show(s);
}
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
System.Diagnostics.Process.GetCurrentProcess().Kill();
}
}
}