/// <summary> /// 屏幕坐标转地理坐标 /// </summary> /// <param name="x">屏幕X</param> /// <param name="y">屏幕Y</param> /// <returns></returns> public MapLngLat SceneToGeographyPoint(int x, int y) { double dLat, dLon, dAlt; IGlobeDisplay pGlobeDisplay = mapControl.GlobeDisplay; ISceneViewer pViewer = mapControl.GlobeDisplay.ActiveViewer; IGlobeViewUtil pGlobeViewUtil = mapControl.GlobeCamera as IGlobeViewUtil; pGlobeViewUtil.WindowToGeographic(pGlobeDisplay, pViewer, x, y, true, out dLon, out dLat, out dAlt); Core.Model.MapLngLat lnglat = new Core.Model.MapLngLat(dLon, dLat, dAlt); return(lnglat); }
private void GetGeographicCoordinates(IGlobe globe, int screenX, int screenY, ref double longitude, ref double latitude, ref double altitudeInKilometers) { IGlobeDisplay globeDisplay = globe.GlobeDisplay; ISceneViewer sceneViewer = globeDisplay.ActiveViewer; ICamera camera = globeDisplay.ActiveViewer.Camera; IGlobeViewUtil globeViewUtil = camera as IGlobeViewUtil; globeViewUtil.WindowToGeographic(globeDisplay, sceneViewer, screenX, screenY, true, out longitude, out latitude, out altitudeInKilometers); }
/// <summary> /// Occurs when the user click inside the globe /// </summary> /// <param name="Button"></param> /// <param name="Shift"></param> /// <param name="X"></param> /// <param name="Y"></param> public override void OnMouseDown(int Button, int Shift, int X, int Y) { //make sure that the weatherlayer and the featureclass exists if (null == m_weatherLayer || null == m_featureClass) { return; } //get the current point (convert the mouse coordinate into geographics coordinate) double lat, lon, alt; m_globeViewUtil.WindowToGeographic(m_globeDsp, m_globeDsp.ActiveViewer, X, Y, true, out lon, out lat, out alt); IPoint point = new PointClass(); ((IZAware)point).ZAware = true; point.PutCoords(lon, lat); //Set a default elevation of 1000M. Alternatively, the user can get the //elevation from the globesurface (ISurface) point.Z = 1000.0; //create the spatial filter in order to select the relevant zipCode ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = point as IGeometry; spatialFilter.GeometryField = m_featureClass.ShapeFieldName; //The spatial filter supposed to filter all the polygons containing the point spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin; //query the featureclass for the containing features IFeatureCursor featureCursor = m_featureClass.Search(spatialFilter, true); IFeature feature = featureCursor.NextFeature(); if (null == feature) { return; } //get the zip code from the containing feature long zipCode = Convert.ToInt64(feature.get_Value(feature.Fields.FindField("ZIP"))); //add the weather item to the layer m_weatherLayer.AddItem(zipCode, lat, lon); //release the featurecursor Marshal.ReleaseComObject(featureCursor); }
protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) { m_bDrawPoint = true; //move the light-source according to the mouse coordinate double lat, lon, alt; lat = lon = alt = 0; m_globeViewUtil.WindowToGeographic(m_globeDisplay, m_sceneViewer, arg.X, arg.Y, false, out lon, out lat, out alt); m_globeDisplayRendering.SetSunPosition(lat, lon); //Refresh the display so that the AfterDraw will get called m_sceneViewer.Redraw(false); }
/// <summary> /// Mouse move event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void axGlobeControl1_OnMouseMove(object sender, IGlobeControlEvents_OnMouseMoveEvent e) { double dLon, dLat, dAlt; //convert the window coordinate into geographic coordinates m_globeViewUtil.WindowToGeographic(m_globeControl.GlobeDisplay, m_globeControl.GlobeDisplay.ActiveViewer, e.x, e.y, true, out dLon, out dLat, out dAlt); //report the mouse geographic coordinate onto the statusbar statusBarXY.Text = string.Format("{0} {1} {2}", dLon.ToString("###.###"), dLat.ToString("###.###"), dAlt.ToString("###.###")); }