很久沒寫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), null, null, null);

//將矩形插入到圖層中
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"]));
---------------------------------------------------------
專注移動開發
Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
posted on 2008-02-25 14:24
TiGERTiAN 閱讀(1588)
評論(2) 編輯 收藏 所屬分類:
DotNet 、
MapXtreme