public string GetFeatureFromPoint(int x, int y) { string result = string.Empty; IActiveView activeView = ArcUtils.ActiveView; if ((activeView != null) && InsideScale) { IMappedFeature mapFeature = CreateMappedFeature(null); string objectId = mapFeature.ObjectId; IScreenDisplay screenDisplay = activeView.ScreenDisplay; IDisplayTransformation dispTrans = screenDisplay.DisplayTransformation; IPoint pointLu = dispTrans.ToMapPoint(x - SizeLayer, y - SizeLayer); IPoint pointRd = dispTrans.ToMapPoint(x + SizeLayer, y + SizeLayer); IEnvelope envelope = new EnvelopeClass { XMin = pointLu.X, XMax = pointRd.X, YMin = pointLu.Y, YMax = pointRd.Y, SpatialReference = ArcUtils.SpatialReference }; envelope.Project(SpatialReference); ISpatialFilter spatialFilter = new SpatialFilterClass { Geometry = envelope, GeometryField = FeatureClass.ShapeFieldName, SpatialRel = esriSpatialRelEnum.esriSpatialRelContains, SubFields = objectId }; var existsResult = FeatureClass.Search(spatialFilter, false); IFeature feature; // ReSharper disable UseIndexedProperty while ((feature = existsResult.NextFeature()) != null) { int imId = existsResult.FindField(objectId); result = (string)feature.get_Value(imId); } // ReSharper restore UseIndexedProperty } return(result); }
protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) { try { dlg = gpExtension.elevationDlg; if (dlg == null) { return; } IDisplayTransformation displayTransformation = view.ScreenDisplay.DisplayTransformation; //the clicked point in map crs: IPoint mapPoint = displayTransformation.ToMapPoint(arg.X, arg.Y); //Get the polyline object from the users mouse clicks polyline = geopuntHelper.GetPolylineFromMouseClicks(view); dlg.getData(polyline); } catch (Exception ex) { MessageBox.Show(ex.Message + " : " + ex.StackTrace); } finally { base.OnMouseDown(arg); } }
private IPoint TransformToMapPoint(int X, int Y) { IActiveView pActiveView = m_hookHelper.ActiveView; IDisplayTransformation pDisplayTrans = pActiveView.ScreenDisplay.DisplayTransformation; IPoint point = pDisplayTrans.ToMapPoint(X, Y); return(point); }
/// <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) IActiveView activeView = m_hookHelper.ActiveView; IDisplayTransformation displayTrans = activeView.ScreenDisplay.DisplayTransformation; IPoint point = displayTrans.ToMapPoint(X, Y); point.SpatialReference = m_hookHelper.FocusMap.SpatialReference; //project the point to WGS1984 CoordSys if (null != point.SpatialReference) { if (point.SpatialReference.FactoryCode != m_spatialRefWGS84.FactoryCode) { point.Project(m_spatialRefWGS84); } } //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, point.Y, point.X); //refresh the map activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, m_weatherLayer, displayTrans.FittedBounds); activeView.ScreenDisplay.UpdateWindow(); //release the featurecursor Marshal.ReleaseComObject(featureCursor); }
protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) { IScreenDisplay screenDisplay = view.ScreenDisplay; batchGeocodeForm batchDlg = gpExtension.batchGeocodeDlg; IDisplayTransformation displayTransformation = view.ScreenDisplay.DisplayTransformation; if (batchDlg != null) { IPoint mapPoint = displayTransformation.ToMapPoint(arg.X, arg.Y); IPoint lam72Point = geopuntHelper.Transform2Lam72(mapPoint) as IPoint; batchDlg.getXYasValidAdres(lam72Point.X, lam72Point.Y); } base.OnMouseDown(arg); }
public bool OnContextMenu(int x, int y) { IScreenDisplay screenDisplay = this.hk.PageLayoutControl.ActiveView.ScreenDisplay; IDisplayTransformation displayTransformation = screenDisplay.DisplayTransformation; ESRI.ArcGIS.Geometry.IPoint point = displayTransformation.ToMapPoint(x, y); IElement textElement = ElementPropetyImp.GetElementFromPage(this.hk.PageLayoutControl, (int)point.X, (int)point.Y); _rightMenu1.SetCurrentElement(textElement); _rightMenu2.SetCurrentElement(textElement); _layerMenu.PopupMenu(x, y, this.hk.PageLayoutControl.hWnd); return(false); }
protected override void OnMouseDown(MouseEventArgs arg) { try { IDisplayTransformation displayTransformation = view.ScreenDisplay.DisplayTransformation; IPoint mapPoint = displayTransformation.ToMapPoint(arg.X, arg.Y); IPoint lam72Point = geopuntHelper.Transform2Lam72(mapPoint) as IPoint; if (resultForm != null) { if (resultForm.IsDisposed) { resultForm = null; } else { if (!resultForm.Visible) { resultForm.Show(); } resultForm.WindowState = FormWindowState.Normal; resultForm.Focus(); resultForm.reverseGeocode(lam72Point); return; } } resultForm = new reverseZoekForm(); gpExtension.reverseDlg = resultForm; resultForm.Show(); resultForm.WindowState = FormWindowState.Normal; resultForm.Focus(); resultForm.reverseGeocode(lam72Point); } catch (Exception ex) { MessageBox.Show(ex.Message + " : " + ex.StackTrace); } finally { base.OnMouseDown(arg); } }