1、添加mapcontrol的OnExtentUpdated方法
2、在globecontrol上添加IglobeGraphicsLayer图层,然后根据map的更新范围,在globe画红线框
3、重新设置观察者的坐标为map更新范围pEnv的中心点,然后全局显示globe
但是现在红线框能画上,不能让globe全局显示,之前用IGlobeCamera 的方法SetToZoomToExtents将globe放大到局部了,不能实现鹰眼的效果,后来用SetObserverLatLonAlt设置pEnv的中心点为观察者点,但是也达不到想要的效果,请大神指点下!!谢谢!以下是我的代码:
IEnvelope pEnv = (IEnvelope)e.newEnvelope;
IZAware pZaware = pEnv as IZAware;
pZaware.ZAware = true;
IActiveView pActiveView = m_Globe as IActiveView;
if (pEnv.XMax>180)//判断地图是否超出范围,如果超出直接设置最大值或者最小值
{
pEnv.XMax = 179;//这里不能设置为180,因为地图时间范围是179.99999,没有180,画红框时不准确,因此设置为179,可能也有点误差
}
if (pEnv.XMin <-180)
{
pEnv.XMin = -179;
}
if (pEnv.YMax >90)
{
pEnv.YMax = 89;
}
if (pEnv.YMin <-90)
{
pEnv.YMin = -89;
}
//axGlobeControl1.GlobeCamera.SetToZoomToExtents(pEnv, m_Globe, m_SceneViewer);
//在globe上添加一个图层
(globeGraphicsLayer as IGraphicsContainer3D).DeleteAllElements();
pGlobeElementPropers.DrapeElement = true;
pGlobeElementPropers.DrapeQuality = true;
pGlobeElementPropers.DrapeZOffset = 15000;
IElement pLineElement = new LineElementClass();
ISimpleLine3DSymbol pSimpleLineSymbol = new SimpleLine3DSymbolClass();
pSimpleLineSymbol.Style = esriSimple3DLineStyle.esriS3DLSStrip;
pSimpleLineSymbol.ResolutionQuality = 1;
IColor pRgbColor = new RgbColorClass();
pRgbColor.RGB = 255;
ILineSymbol pLineSymbol = pSimpleLineSymbol as ILineSymbol;
pLineSymbol.Color = pRgbColor;
pLineSymbol.Width = 5;
//设置geometry
IPolyline pPolyLine = new PolylineClass();
ISegment pSegment = new LineClass();
ISegmentCollection pSegmentCollection = new PathClass();
object Missing = Type.Missing;
IPoint fromPoint = new PointClass();
fromPoint.PutCoords(pEnv.XMin, pEnv.YMin);
pSegment.FromPoint = fromPoint;
IPoint toPoint = new PointClass();
toPoint.PutCoords(pEnv.XMax, pEnv.YMin);
pSegment.ToPoint = toPoint;
pSegmentCollection.AddSegment(pSegment, ref Missing, ref Missing);
ISegment pSegment2 = new LineClass();
IPoint fromPoint2 = new PointClass();
IPoint toPoint2 = new PointClass();
fromPoint2.PutCoords(pEnv.XMax, pEnv.YMin);
pSegment2.FromPoint = fromPoint2;
toPoint2.PutCoords(pEnv.XMax, pEnv.YMax);
pSegment2.ToPoint = toPoint2;
pSegmentCollection.AddSegment(pSegment2, ref Missing, ref Missing);
ISegment pSegment3 = new LineClass();
IPoint fromPoint3 = new PointClass();
IPoint toPoint3 = new PointClass();
fromPoint3.PutCoords(pEnv.XMax, pEnv.YMax);
pSegment3.FromPoint = fromPoint3;
toPoint3.PutCoords(pEnv.XMin, pEnv.YMax);
pSegment3.ToPoint = toPoint3;
pSegmentCollection.AddSegment(pSegment3, ref Missing, ref Missing);
ISegment pSegment4 = new LineClass();
IPoint fromPoint4 = new PointClass();
IPoint toPoint4 = new PointClass();
fromPoint4.PutCoords(pEnv.XMin, pEnv.YMax);
pSegment4.FromPoint = fromPoint4;
toPoint4.PutCoords(pEnv.XMin, pEnv.YMin);
pSegment4.ToPoint = toPoint4;
pSegmentCollection.AddSegment(pSegment4, ref Missing, ref Missing);
IGeometryCollection pGeometryCollection = new PolylineClass();
pGeometryCollection.AddGeometry(pSegmentCollection as IGeometry, ref Missing, ref Missing);
pPolyLine = pGeometryCollection as IPolyline;
pLineElement.Geometry = pPolyLine;
//添加到graphics layer上
ILineElement pLineElement_2 = pLineElement as ILineElement;
pLineElement_2.Symbol = pLineSymbol;
globeGraphicsLayer.AddElement(pLineElement, pGlobeElementPropers, out index0);
//
double lon, lat, alt;
ICamera pCamera = m_Globe.GlobeDisplay.ActiveViewer.Camera;
IGlobeCamera pGlobeCamera = pCamera as IGlobeCamera;
pGlobeCamera.OrientationMode = esriGlobeCameraOrientationMode.esriGlobeCameraOrientationGlobal;
IPoint pTarge = new PointClass();
pTarge.PutCoords(0.0,0.0);
pTarge.Z = 0;
pCamera.Target = pTarge;
lon=(pEnv.XMin + pEnv.XMax) / 2.0;
lat=(pEnv.YMax + pEnv.YMin) / 2.0;
alt=Math.Max(pEnv.Width, pEnv.Height)* 1000 * 0.0553;
//m_globeViewUtil.WindowToGeographic(m_GlobeDisplay, m_SceneViewer, (int)((pEnv.XMin + pEnv.XMax) / 2), (int)((pEnv.YMax + pEnv.YMin) / 2), true, out lon, out lat, out alt);
//axGlobeControl1.GlobeCamera.GetObserverLatLonAlt(out lat, out lon, out alt);
//axGlobeControl1.GlobeCamera.SetObserverLatLonAlt((pEnv.XMin + pEnv.XMax) / 2, (pEnv.YMax + pEnv.YMin) / 2, 100);
//ICommand pCommand = new ControlsGlobeFullExtentCommandClass();
//pCommand.OnCreate(axGlobeControl1.Object);
//pCommand.OnClick();
axGlobeControl1.GlobeCamera.SetObserverLatLonAlt(lat, lon, alt);
//axGlobeControl1.GlobeCamera.SetToZoomToExtents(pActiveView.FullExtent, m_Globe, m_SceneViewer);
//ESRI.ArcGIS.Geometry.ISpatialReference spatialReference = pScene.SpatialReference;
//if (pEnv.Width < 0.005 && pEnv.Height < 0.005)
// pEnv.Expand(0.005, 0.005, false);
//else
// pEnv.Expand(0.0005, 0.0005, false);
//double centerPointX = (pEnv.XMax + pEnv.XMin) / 2;
//double cneterPointY = (pEnv.YMax + pEnv.YMin) / 2;
//ESRI.ArcGIS.Geometry.IPoint centerPoint = new ESRI.ArcGIS.Geometry.PointClass();
//centerPoint.SpatialReference = spatialReference;
//centerPoint.X = centerPointX;
//centerPoint.Y = cneterPointY;
//pEnv.CenterAt(centerPoint);
//axGlobeControl1.GlobeCamera.SetToZoomToExtents(pEnv, m_Globe, m_SceneViewer);
m_SceneViewer.Redraw(true);
axGlobeControl1.Globe.GlobeDisplay.RefreshViewers();