/// <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"]));