Mapxtreme 添加和删除图元并且添加一些自定义的属性

        /// <summary>
        
/// 给给定图层添加图元
        
/// </summary>
        
/// <param name="layerName"></param>
        
/// <param name="list"></param>

        private void DrawFeature(string layerName, ArrayList list)
        
{
            DPoint dpoint;
            Point point;
            BitmapPointStyle vs;
            Feature f;
            FeatureLayer flayer;

            
try
            
{
                flayer 
= map.Layers[layerName] as FeatureLayer;
                
if (flayer == null)
                    
return;

                Table fTable 
= flayer.Table;

                
foreach (object o in list)
                
{
                    
                    Trouble t 
= (Trouble) o;
                    dpoint 
= new DPoint(t.X, t.Y);
                    point 
= new Point(map.GetDisplayCoordSys(), dpoint);

                    vs 
= new BitmapPointStyle();
                    vs.Name 
= @t.BmpName;
                    vs.PointSize 
= Convert.ToInt16(24);
                    vs.Attributes 
= StyleAttributes.PointAttributes.BaseAll;
                    vs.SetApplyAll();

                    f 
= new Feature(fTable.TableInfo.Columns);
                    f.Geometry 
= point;
                    f.Style 
= vs;
                    f[GlobalHelper.MIFields[
0]] = t.TroubleType;
                    f[GlobalHelper.MIFields[
1]] = t.Id;
                    f[GlobalHelper.MIFields[
2]] = t.SpecTypeCode;


                    flayer.Table.InsertFeature(f);
                }


            }

            
catch (Exception ex)
            
{
                GlobalHelper.ShowError(
"绘制隐患图元错误,原因:" + ex.Message);
            }


        }
上半部分都是获得地理信息和图标,到了这边

                    f = new Feature(fTable.TableInfo.Columns);
                    f.Geometry = point;
                    f.Style = vs;
                    f[GlobalHelper.MIFields[0]] = t.TroubleType;
                    f[GlobalHelper.MIFields[1]] = t.Id;
                    f[GlobalHelper.MIFields[2]] = t.SpecTypeCode;
第一句主要是从图层的表中获得列结构,然后给这个feature赋值地理信息和图标,后面三句就是给这个feature添加编号和类型等信息(当然这些属性都是图层表中的结构),这样当点击图元的时候可以根据这些信息进行搜索
如下代码可以创建表结构
/// <summary>
        
/// 创建图层
        
/// </summary>
        
/// <param name="tableName"></param>

        public static void CreateLayerTableFile(string tableName, Map map)
        
{
            
try {
                
string[] colNames = GlobalHelper.MIFields;
                TableInfoNative ti 
= new TableInfoNative(tableName);
                ti.TablePath 
= GlobalHelper.UserMapFilePath + tableName + ".tab";
                ti.DataPath 
= GlobalHelper.UserMapFilePath + tableName + ".dat";
                
//添加列
                ti.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(map.GetDisplayCoordSys()));
                ti.Columns.Add(ColumnFactory.CreateStyleColumn());
                
for (int i = 0; i < colNames.Length; i++)
                
{
                    Column c 
= ColumnFactory.CreateStringColumn(colNames[i], 150);
                    
//给ID做索引,方便搜索
                    if (colNames[i].Equals("ID"))
                        c.Indexed 
= true;
                    ti.Columns.Add(c);
                }

                ti.WriteTabFile();
                
//插入图层
                Table table = Session.Current.Catalog.CreateTable(ti);
                FeatureLayer flayer 
= new FeatureLayer(table);
                map.Layers.Add(flayer);
            }
catch(Exception ex) {
                GlobalHelper.ShowError(
"创建图层文件出错,原因:" + ex.Message);
            }


        }

posted on 2008-10-05 10:12  TiGERTiAN  阅读(1485)  评论(0编辑  收藏  举报

导航