private IEnvelope Envelope_Search(IActiveView activeView) { IArea Area; IEnvelope pEnvelope; IRubberBand rubberEnv; IGeometry geom; rubberEnv = new RubberEnvelopeClass(); geom = rubberEnv.TrackNew(activeView.ScreenDisplay, null); geom.SpatialReference = Map.SpatialReference; pEnvelope = geom.Envelope; Area = (IArea)pEnvelope; if (pEnvelope.IsEmpty || Area.Area == 0) { pEnvelope = new EnvelopeClass(); //////////////////////////////////////////////////////////////////////////////////////// ESRI.ArcGIS.esriSystem.tagRECT RECT = new tagRECT(); RECT.bottom = 0; RECT.left = 0; RECT.right = 5; RECT.top = 5; IDisplayTransformation dispTrans = activeView.ScreenDisplay.DisplayTransformation; dispTrans.TransformRect(pEnvelope, RECT, 4); pEnvelope.CenterAt(clickedPoint); } return(pEnvelope); }
static void SelectFeaturesScreenPoint(IMap pMap, int x, int y, int pixelTol) { tagRECT r; //Construct a small rectangle out of the x,y coordinates' pixel tolerance. r.left = x - pixelTol; //Upper left x, top left is 0,0. r.top = y - pixelTol; //Upper left y, top left is 0,0. r.right = x + pixelTol; //Lower right x, top left is 0,0. r.bottom = y + pixelTol; //Lower right y, top left is 0,0. //Transform the device rectangle into a geographic rectangle via the display transformation. IEnvelope pEnvelope = new EnvelopeClass(); IActiveView pActiveView = pMap as IActiveView; IDisplayTransformation pDisplayTrans = pActiveView.ScreenDisplay.DisplayTransformation; pDisplayTrans.TransformRect(pEnvelope, ref r, 5); //5 = esriTransformPosition + esriTransformToMap. pEnvelope.SpatialReference = pMap.SpatialReference; //ISelectionEnvironment pSelectionEnvironment = new SelectionEnvironmentClass(); //pSelectionEnvironment.CombinationMethod = // esriSelectionResultEnum.esriSelectionResultNew; //pMap.SelectByShape(pEnvelope, pSelectionEnvironment, false); }
private void ZoomToolStripMenuItem1_Click(object sender, EventArgs e) { if (item == null) { return; } IFeature pF = (IFeature)m_ArrayListFeatures[item.Index]; ILayer Layer = (ILayer)m_ArrayListLayers[item.Index]; IEnvelope pEnvelope; IActiveView ActiveView = (IActiveView)m_Map; if (Layer == null || pF == null) { return; } if (pF.Shape.GeometryType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint) { pEnvelope = pF.Extent; pEnvelope.Expand(1.5, 1.5, true); } else { pEnvelope = new EnvelopeClass(); ESRI.ArcGIS.esriSystem.tagRECT RECT = new tagRECT(); IDisplayTransformation dispTrans = ActiveView.ScreenDisplay.DisplayTransformation; dispTrans.TransformRect(pEnvelope, RECT, 4); pEnvelope.Width = ActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width / 10; pEnvelope.Height = ActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Height / 10; pEnvelope.CenterAt(pF.ShapeCopy as IPoint); pEnvelope.SpatialReference = m_Map.SpatialReference; } ActiveView.Extent = pEnvelope; ActiveView.Refresh(); }
protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) { int X = arg.X; int Y = arg.Y; IMxApplication pMxApp = null; IMxDocument pMxDoc = null; pMxApp = (IMxApplication)ArcMap.Application; pMxDoc = (IMxDocument)ArcMap.Application.Document; // calculate tolerance rectangle to identify features inside it int Tolerance = 0; Tolerance = pMxDoc.SearchTolerancePixels; IDisplayTransformation pDispTrans = null; pDispTrans = pMxApp.Display.DisplayTransformation; tagRECT pToleranceRect = new tagRECT(); pToleranceRect.left = X - Tolerance; pToleranceRect.right = X + Tolerance; pToleranceRect.top = Y - Tolerance; pToleranceRect.bottom = Y + Tolerance; IEnvelope pSearchEnvelope = null; pSearchEnvelope = new EnvelopeClass(); pDispTrans.TransformRect(pSearchEnvelope, ref pToleranceRect, (int)(esriDisplayTransformationEnum.esriTransformPosition | esriDisplayTransformationEnum.esriTransformToMap)); // identify feature points of measurement IBasicDocument pBasicDoc = null; pBasicDoc = (IBasicDocument)ArcMap.Application.Document; pSearchEnvelope.SpatialReference = pMxDoc.ActiveView.FocusMap.SpatialReference; IIdentify pIdentify = null; pIdentify = (IIdentify)pMxDoc.FocusMap.get_Layer(0); if (pIdentify == null) { MessageBox.Show("No layer"); return; } IArray pIDArray = null; pIDArray = pIdentify.Identify(pSearchEnvelope); // get object from feature point IIdentifyObj pIDObj = null; if (pIDArray != null) { pIDObj = (IIdentifyObj)pIDArray.get_Element(0); } if (pIDObj == null) { MessageBox.Show("No feature was identified"); return; } // get the name of the layer containing feature points ILayer pLayer = null; pLayer = pMxDoc.FocusMap.get_Layer(0); string layerName = null; layerName = pLayer.Name; // get primary display field for measurement values and set names of a date/time field and gage ID field IFeatureLayer pFeatLayer = null; pFeatLayer = (IFeatureLayer)pLayer; string dataFldName = null; string timefldName = null; string gageIDFldName = null; dataFldName = "TSValue"; timefldName = "TSDateTime"; // substitute data/time field name for different dataset gageIDFldName = "Name"; // substitute gage ID field name for different dataset // get display table from layer ITable pTable = null; IDisplayTable pDisplayTable = null; pDisplayTable = (IDisplayTable)pLayer; if (pDisplayTable != null) { pTable = pDisplayTable.DisplayTable; if (pTable == null) { goto THEEND; } } // get fields from display table IFields pFields = null; pFields = pTable.Fields; long fldCount = 0; fldCount = pFields.FieldCount; // create WHERE clause from identified objects of measurement points int gageIDFldIdx = 0; gageIDFldIdx = pFields.FindField(gageIDFldName); IRowIdentifyObject pRowIDObj = null; pRowIDObj = (IRowIdentifyObject)pIDObj; string gageID = null; gageID = (string)pRowIDObj.Row.get_Value(gageIDFldIdx); IFeatureLayerDefinition pFeatureLayerDef = null; pFeatureLayerDef = (IFeatureLayerDefinition)pLayer; string definitionExpression = null; definitionExpression = pFeatureLayerDef.DefinitionExpression; string whereClause = null; if (definitionExpression == "") { whereClause = "[" + gageIDFldName + "] = '" + gageID + "'"; } else { whereClause = "[" + gageIDFldName + "] = '" + gageID + "' AND " + definitionExpression; } //find color for the identified object from feature layer's renderer IGeoFeatureLayer pGeoFeatureLayer = null; pGeoFeatureLayer = (IGeoFeatureLayer)pLayer; ILookupSymbol pLookupSymbol = null; pLookupSymbol = (ILookupSymbol)pGeoFeatureLayer.Renderer; IFeature pFeature = null; pFeature = (IFeature)pRowIDObj.Row; IMarkerSymbol pSymbol = null; pSymbol = (IMarkerSymbol)pLookupSymbol.LookupSymbol(false, pFeature); // Find an opened GraphWindow IDataGraphBase pDataGraphBase = null; IDataGraphT pDataGraphT = null; IDataGraphWindow2 pDGWin = null; IDataGraphCollection pDataGraphs = null; pDataGraphs = (IDataGraphCollection)pMxDoc; int grfCount = 0; grfCount = pDataGraphs.DataGraphCount; for (int i = 0; i < grfCount; i++) { pDataGraphBase = pDataGraphs.get_DataGraph(i); pDGWin = FindGraphWindow(ref pDataGraphBase); if (pDGWin != null) { break; } } // if there is not an opened graph window - create a new graph for if (pDGWin == null) { // create graph pDataGraphT = new DataGraphTClass(); pDataGraphBase = (IDataGraphBase)pDataGraphT; // load template from <ARCGISHOME>\GraphTemplates\ string strPath = null; strPath = Environment.GetEnvironmentVariable("ARCGISHOME"); try { pDataGraphT.LoadTemplate(strPath + @"GraphTemplates\timeseries.tee"); } catch { } // graph, axis and legend titles. Substitute them for different input layer pDataGraphT.GeneralProperties.Title = "Daily Streamflow for Guadalupe Basin in 1999"; pDataGraphT.LegendProperties.Title = "Monitoring Point"; pDataGraphT.get_AxisProperties(0).Title = "Streamflow (cfs)"; pDataGraphT.get_AxisProperties(0).Logarithmic = true; pDataGraphT.get_AxisProperties(2).Title = "Date"; pDataGraphBase.Name = layerName; } else // get graph from the opened window { pDataGraphT = (IDataGraphT)pDataGraphBase; } // create vertical line series for all measurements for the identified gage ISeriesProperties pSP = null; pSP = pDataGraphT.AddSeries("line:vertical"); pSP.ColorType = esriGraphColorType.esriGraphColorCustomAll; pSP.CustomColor = pSymbol.Color.RGB; pSP.WhereClause = whereClause; pSP.InLegend = true; pSP.Name = gageID; pSP.SourceData = pLayer; pSP.SetField(0, timefldName); pSP.SetField(1, dataFldName); IDataSortSeriesProperties pSortFlds = null; pSortFlds = (IDataSortSeriesProperties)pSP; int idx = 0; pSortFlds.AddSortingField(timefldName, true, ref idx); pDataGraphBase.UseSelectedSet = true; ITrackCancel pCancelTracker = null; pCancelTracker = new CancelTracker(); pDataGraphT.Update(pCancelTracker); // create data graph window if there is not any opened one if (pDGWin == null) { pDGWin = new DataGraphWindowClass(); pDGWin.DataGraphBase = pDataGraphBase; pDGWin.Application = ArcMap.Application; pDGWin.Show(true); pDataGraphs.AddDataGraph(pDataGraphBase); } THEEND: return; //base.OnMouseDown(arg); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { IMap map; IPoint clickedPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); //If ActiveView is a PageLayout if (m_hookHelper.ActiveView is IPageLayout) { //See whether the mouse has been clicked over a Map in the PageLayout map = m_hookHelper.ActiveView.HitTestMap(clickedPoint); //If mouse click isn't over a Map exit if (map == null) { return; } //Ensure the Map is the FocusMap if ((!object.ReferenceEquals(map, m_hookHelper.FocusMap))) { m_hookHelper.ActiveView.FocusMap = map; m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } //Still need to convert the clickedPoint into map units using the map's IActiveView clickedPoint = ((IActiveView)map).ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); } else //Or ActiveView is a Map { map = m_hookHelper.FocusMap; } IActiveView activeView = (IActiveView)map; IRubberBand rubberEnv = new RubberEnvelopeClass(); IGeometry geom = rubberEnv.TrackNew(activeView.ScreenDisplay, null); IArea area = (IArea)geom; //Extra logic to cater for the situation where the user simply clicks a point on the map //or where envelope is so small area is zero if ((geom.IsEmpty == true) || (area.Area == 0)) { //create a new envelope IEnvelope tempEnv = new EnvelopeClass(); //create a small rectangle ESRI.ArcGIS.esriSystem.tagRECT RECT = new tagRECT(); RECT.bottom = 0; RECT.left = 0; RECT.right = 5; RECT.top = 5; //transform rectangle into map units and apply to the tempEnv envelope IDisplayTransformation dispTrans = activeView.ScreenDisplay.DisplayTransformation; dispTrans.TransformRect(tempEnv, ref RECT, 4); //4 = esriDisplayTransformationEnum.esriTransformToMap) tempEnv.CenterAt(clickedPoint); geom = (IGeometry)tempEnv; } //Set the spatial reference of the search geometry to that of the Map ISpatialReference spatialReference = map.SpatialReference; geom.SpatialReference = spatialReference; map.SelectByShape(geom, null, false); activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, activeView.Extent); }