很久没写blog了,备份一下,这段代码是我从网上看来的,根据需要修改了一下。

 /**//// <summary>
       /**//// <summary>
 /// 更新鹰眼图
        /// 更新鹰眼图
 /// </summary>
        /// </summary>
 private void UpdateEyeMap()
        private void UpdateEyeMap()

 
         {
{

 try
            try  {
{
 //如果主图和鹰眼图加载的是同一实例,那么鹰眼图就需要检测是否有效
                //如果主图和鹰眼图加载的是同一实例,那么鹰眼图就需要检测是否有效
 //if (eyeMap != null)
                //if (eyeMap != null)

 
                 {
{
 //加载鹰眼矩形临时表
                    //加载鹰眼矩形临时表
 Table tblRect;
                    Table tblRect;
 tblRect = Session.Current.Catalog.GetTable("TempRect");
                    tblRect = Session.Current.Catalog.GetTable("TempRect");
 if (tblRect != null)
                    if (tblRect != null)
 tblRect.Close();
                        tblRect.Close();
 TableInfo tblInfo;
                    TableInfo tblInfo;
 tblInfo = TableInfoFactory.CreateTemp("TempRect");
                    tblInfo = TableInfoFactory.CreateTemp("TempRect");
 TableSessionInfo tblSessionInfo = new TableSessionInfo();
                    TableSessionInfo tblSessionInfo = new TableSessionInfo();

 tblRect = Session.Current.Catalog.CreateTable(tblInfo, tblSessionInfo);
                    tblRect = Session.Current.Catalog.CreateTable(tblInfo, tblSessionInfo);
 FeatureLayer feaLayer = new FeatureLayer(tblRect);
                    FeatureLayer feaLayer = new FeatureLayer(tblRect);
 eyeMap.Layers.Insert(0, feaLayer);
                    eyeMap.Layers.Insert(0, feaLayer);

 //实时在鹰眼临时表图上画矩形
                    //实时在鹰眼临时表图上画矩形
 tblRect = Session.Current.Catalog.GetTable("TempRect");
                    tblRect = Session.Current.Catalog.GetTable("TempRect");
 (tblRect as ITableFeatureCollection).Clear();//清除当前层上的图元
                    (tblRect as ITableFeatureCollection).Clear();//清除当前层上的图元

 //设置矩形的样式
                    //设置矩形的样式
 DRect rect = mapControl.Map.Bounds;
                    DRect rect = mapControl.Map.Bounds;
 FeatureGeometry feageo = new MapInfo.Geometry.Rectangle(mapControl.Map.GetDisplayCoordSys(), rect);
                    FeatureGeometry feageo = new MapInfo.Geometry.Rectangle(mapControl.Map.GetDisplayCoordSys(), rect);
 SimpleLineStyle simLineStyle = new SimpleLineStyle(new LineWidth(2, MapInfo.Styles.LineWidthUnit.Point), 2, System.Drawing.Color.Red);
                    SimpleLineStyle simLineStyle = new SimpleLineStyle(new LineWidth(2, MapInfo.Styles.LineWidthUnit.Point), 2, System.Drawing.Color.Red);
 SimpleInterior simInterior = new SimpleInterior(9, System.Drawing.Color.Gray, System.Drawing.Color.Green, true);
                    SimpleInterior simInterior = new SimpleInterior(9, System.Drawing.Color.Gray, System.Drawing.Color.Green, true);
 CompositeStyle comStyle = new CompositeStyle(new AreaStyle(simLineStyle, simInterior), null, null, null);
                    CompositeStyle comStyle = new CompositeStyle(new AreaStyle(simLineStyle, simInterior), null, null, null);

 //将矩形插入到图层中
                    //将矩形插入到图层中
 Feature fea = new Feature(feageo, comStyle);
                    Feature fea = new Feature(feageo, comStyle);
 tblRect.InsertFeature(fea);
                    tblRect.InsertFeature(fea);
 //重新定位鹰眼图的中心
                    //重新定位鹰眼图的中心
 eyeMap.Center = map.Center;
                    eyeMap.Center = map.Center;
 eyeMap.Layers["TempRect"].Invalidate();
                    eyeMap.Layers["TempRect"].Invalidate();

 //清理对象变量
                    //清理对象变量
 tblSessionInfo = null;
                    tblSessionInfo = null;
 feageo = null;
                    feageo = null;
 simLineStyle = null;
                    simLineStyle = null;
 simInterior = null;
                    simInterior = null;
 comStyle = null;
                    comStyle = null;
 fea = null;
                    fea = null;
 }
                }              

 }catch(Exception ex)
            }catch(Exception ex)  {
{
 GlobalHelper.ShowError("显示鹰眼图错误,"+ex.Message);
                GlobalHelper.ShowError("显示鹰眼图错误,"+ex.Message);
 }
            }
 
 
 
           
 }
        }
将该函数放入Map_ViewChangedEvent事件中,每当主图改变的时候鹰眼图会跟着变化,不过速度慢了点,因为需要重绘方框和移动中心坐标。
当然之前你要载入和主图一样的地图:
 //鹰眼图加载,添加不同实例,减小耦合性
                //鹰眼图加载,添加不同实例,减小耦合性
 eyeMap.Load(new MapGeosetLoader(basePath + GlobalHelper.IniFile["GST"]["gstFile"]));
                eyeMap.Load(new MapGeosetLoader(basePath + GlobalHelper.IniFile["GST"]["gstFile"]));
专注移动开发
Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
	
posted on 2008-02-25 14:24 
TiGERTiAN 阅读(1608) 
评论(2)  编辑  收藏  所属分类: 
DotNet 、
MapXtreme