我用C#进行开发,程序初始化时需要先将几个点绘制在地图上,然后再地图中用鼠标选中几何图形,总是无法选中。
public void AddPointForIni()
{
Recordset recordset = null;
try
{
//获取数据源
Datasource datasource = m_workspace.Datasources[0];
//新建数据集
String name = "person";
//获取数据集
DatasetVector dataset = m_workspace.Datasources[0].Datasets[name] as DatasetVector;
if(dataset==null){
//设置矢量数据集的信息
DatasetVectorInfo datasetVectorInfo = new DatasetVectorInfo();
datasetVectorInfo.Type = DatasetType.Point;
datasetVectorInfo.IsFileCache = true;
datasetVectorInfo.Name = name;
//创建矢量数据集
datasource.Datasets.Create(datasetVectorInfo);
}
//获取所有记录集
recordset = dataset.GetRecordset(false,CursorType.Dynamic);
recordset.DeleteAll();
//向记录集中添加点一个几何对象
double x = 12571750.9161018;
double y = 2880758.72201756;
GeoPoint geoPoint1 = new GeoPoint(x, y);
recordset.AddNew(geoPoint1);
recordset.Update();
//添加字段
FieldInfos m_fieldInfos = dataset.FieldInfos;
if (m_fieldInfos.IndexOf("uri") == -1)
{
// 实例化一个字段信息对象,对其进行设置
FieldInfo fieldInfo = new FieldInfo();
fieldInfo.Name = "uri";
fieldInfo.Caption = "uri";
fieldInfo.DefaultValue = "sip:@test.com";
fieldInfo.Type = FieldType.Text;
fieldInfo.IsRequired = false;
// 将字段 "uri" 添加到数据集 dataset 中
FieldInfos fieldInfos = dataset.FieldInfos;
fieldInfos.Add(fieldInfo);
fieldInfo.Dispose();
}
Layer personLayer = m_mapControlMain.Map.Layers.Add(dataset, true);
m_mapControlMain.Map.EnsureVisible(personLayer);
m_mapControlMain.Map.Refresh();
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
}
finally
{
// recordset 使用完毕后Dispose
if (recordset != null)
{
recordset.Dispose();
}
}
}
然后我在鼠标MouseUp注册事件:m_mapControlMain.MouseUp += new MouseEventHandler(m_mapControlMain_MouseUp);
void m_mapControlMain_MouseUp(object sender, MouseEventArgs e){
if (m_mapControlMain.Action == SuperMap.UI.Action.Select2){
Selection[] selection = m_mapControlMain.Map.FindSelection(true);}
}
selection 的长度总是为0,是怎么回事呢?