首页 / 浏览问题 / 组件GIS / 问题详情
VS示例代码运行错误
3EXP 2021年02月01日

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 SuperMap.Data;          //添加引用
using SuperMap.Mapping;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_load(object sender, EventArgs e)
        {
            mapControl1.Map.Workspace = workspace1;     //工作空间与地图控件关联
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            mapControl1.Dispose();             //释放资源
            workspace1.Dispose();
        }

        private void btnOpenMap_Click(object sender, EventArgs e)
        {
             //添加以下代码,避免连续打开工作空间导致程序异常
            mapControl1.Map.Close();  //关闭地图
            workspace1.Close();       //关闭工作空间
            //添加以下代码,实现地图加载

            //构造工作空间连接对象
            WorkspaceConnectionInfo workspaceConnectionInfo = new WorkspaceConnectionInfo();
            WorkspaceConnectionInfo.Type = WorkspaceType.SMWU;
            WorkspaceConnectionInfo.Server = @"D:\SuperMap\supermap-iobjectsdotnet-10.1.1-19230-84288-all\SampleData\World\World,smwu";
            
                workspace1.Open(workspaceConnectionInfo);      //打开工作空间
                string MapName = workspace1.Maps[0];           //打开地图
                mapControl1.Map.Open(MapName);
                mapControl1.Map.ViewEntire();                  //全幅显示
            
            }
        }
    }

错误    1    非静态字段、方法或属性“SuperMap.Data.WorkspaceConnectionInfo.Type.get”要求对象引用    D:\SuperMap\project\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs    41    13    WindowsFormsApplication1
错误    2    非静态字段、方法或属性“SuperMap.Data.WorkspaceConnectionInfo.Server.get”要求对象引用    D:\SuperMap\project\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs    42    13    WindowsFormsApplication1
 

1个回答

WorkspaceConnectionInfo.Type = WorkspaceType.SMWU;

WorkspaceConnectionInfo.Server = @"D:\SuperMap\supermap-iobjectsdotnet-10.1.1-19230-84288-all\SampleData\World\World,smwu";

您在对工作空间连接信息赋值的这两行代码错误。

您对工作空间连接信息变量实例化名称是workspaceConnectionInfo,而不是WorkspaceConnectionInfo。

将其修改为即可。(大小写W→w)
10,588EXP 2021年02月01日
...