mapxtreme 鹰眼图的开发

本文介绍了一种在主地图变化时同步更新鹰眼图的方法,通过创建临时表并绘制矩形来实现。此方法适用于需要实时展示地图缩略图的应用场景。

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

       /**//// <summary>
        
/// 更新鹰眼图
        
/// </summary>

        private void UpdateEyeMap()
        
{
            
try {
                
//如果主图和鹰眼图加载的是同一实例,那么鹰眼图就需要检测是否有效
                
//if (eyeMap != null)
                {
                    
//加载鹰眼矩形临时表
                    Table tblRect;
                    tblRect 
= Session.Current.Catalog.GetTable("TempRect");
                    
if (tblRect != null)
                        tblRect.Close();
                    TableInfo tblInfo;
                    tblInfo 
= TableInfoFactory.CreateTemp("TempRect");
                    TableSessionInfo tblSessionInfo 
= new TableSessionInfo();

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

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

                    
//设置矩形的样式
                    DRect rect = mapControl.Map.Bounds;
                    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);
                    SimpleInterior simInterior 
= new SimpleInterior(9, System.Drawing.Color.Gray, System.Drawing.Color.Green, true);
                    CompositeStyle comStyle 
= new CompositeStyle(new AreaStyle(simLineStyle, simInterior), nullnullnull);

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

                    
//清理对象变量
                    tblSessionInfo = null;
                    feageo 
= null;
                    simLineStyle 
= null;
                    simInterior 
= null;
                    comStyle 
= null;
                    fea 
= null;
                }
              
            }
catch(Exception ex) {
                GlobalHelper.ShowError(
"显示鹰眼图错误,"+ex.Message);
            }

 
           
        }
将该函数放入Map_ViewChangedEvent事件中,每当主图改变的时候鹰眼图会跟着变化,不过速度慢了点,因为需要重绘方框和移动中心坐标。
当然之前你要载入和主图一样的地图:
                //鹰眼图加载,添加不同实例,减小耦合性
                eyeMap.Load(new MapGeosetLoader(basePath + GlobalHelper.IniFile["GST"]["gstFile"]));

转载于:https://www.cnblogs.com/tigertian/archive/2008/10/05/1304120.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值