随笔-348  评论-598  文章-0  trackbacks-0
        /// <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添加编号和类型等信息(当然这些属性都是图层表中的结构),这样当点击图元的时候可以根据这些信息进行搜索
当然如果图片不在系统自定义图片目录下,你需要自定义一个图片仓库:
                bool value = Session.Current.StyleRepository.BitmapPointStyleRepository.Reload(Constants.AppPath + "Resources");
之后就可以使用
                vs = new BitmapPointStyle();
                vs.Name = @t.BmpName;
直接载入相关图片了,说明一点,图片需要是4位色深的,如果是更大的色深则图片会无法载入,在地图上会显示一个黑方块。


---------------------------------------------------------
专注移动开发

Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
posted on 2008-02-25 18:52 TiGERTiAN 阅读(2365) 评论(0)  编辑  收藏 所属分类: DotNetMapXtreme

只有注册用户登录后才能发表评论。


网站导航: