public IGeometry DrawPolyline(ESRI.ArcGIS.Carto.IActiveView activeView) { if (activeView == null) { return(null); } ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay; // Constant screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColor(); rgbColor.Red = 255; ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit Cast ESRI.ArcGIS.Display.ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol(); simpleLineSymbol.Color = color; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDashDot; ESRI.ArcGIS.Display.ISymbol symbol = (ESRI.ArcGIS.Display.ISymbol)simpleLineSymbol; // Explicit Cast ESRI.ArcGIS.Display.IRubberBand rubberBand = new RubberLine(); ESRI.ArcGIS.Geometry.IGeometry geometry = rubberBand.TrackNew(screenDisplay, symbol); screenDisplay.SetSymbol(symbol); screenDisplay.DrawPolyline(geometry); screenDisplay.FinishDrawing(); return(geometry); }
//生成颜色 public static IRgbColor CreatRgbColor(int nR, int nG, int nB, bool blTransparency) { ESRI.ArcGIS.Display.IRgbColor pRgbColor = null; pRgbColor = new ESRI.ArcGIS.Display.RgbColor(); if (blTransparency == true) { pRgbColor.Transparency = 0; } else { pRgbColor.Red = nR; pRgbColor.Green = nG; pRgbColor.Blue = nB; } return(pRgbColor); }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { try { //get access to the document and the active view pMxDocument = (IMxDocument)clsAgrcArcMapExtension.m_application.Document; pMap = pMxDocument.FocusMap; pActiveView = pMxDocument.ActiveView; //pActiveView = (IActiveView)pMap; //get the map's graphics layer ICompositeGraphicsLayer2 pComGraphicsLayer = pMap.BasicGraphicsLayer as ICompositeGraphicsLayer2; ICompositeLayer pCompositeLayer = pComGraphicsLayer as ICompositeLayer; ILayer pLayer; //loop through all graphic layers in the map and check for the 'PolyVertices' layer, if found, delete it, in order to start fresh for (int i = 0; i < pCompositeLayer.Count; i++) { pLayer = pCompositeLayer.get_Layer(i); if (pLayer.Name == "PolyVertices") { pComGraphicsLayer.DeleteLayer("PolyVertices"); break; } } if (bolVerticesOn == false) { IGraphicsLayer pGraphicsLayer = pComGraphicsLayer.AddLayer("PolyVertices", null); pMap.ActiveGraphicsLayer = (ILayer)pGraphicsLayer; IGraphicsContainer pGraphicsContainer = pComGraphicsLayer.FindLayer("PolyVertices") as IGraphicsContainer; //make sure the user has selected a polygon or polyline layer if (pMxDocument.SelectedLayer == null) { MessageBox.Show("Please select a layer.", "Select Layer", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!(pMxDocument.SelectedLayer is IFeatureLayer)) { MessageBox.Show("Please select a polygon or line layer.", "Polygon or Line", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //cast the selected layer as a feature layer IGeoFeatureLayer pGFlayer = (IGeoFeatureLayer)pMxDocument.SelectedLayer; //check if the feaure layer is a polygon or line layer if (pGFlayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon & pGFlayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolyline) { MessageBox.Show("Please select a polygon or line layer.", "Polygon or Line", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //setup marker symbol ISimpleMarkerSymbol pSimpleMarker = new SimpleMarkerSymbol(); ISymbol pSymbolMarker = (ISymbol)pSimpleMarker; IRgbColor pRgbColor = new ESRI.ArcGIS.Display.RgbColorClass(); pRgbColor.Red = 223; pRgbColor.Green = 155; pRgbColor.Blue = 255; pSimpleMarker.Color = pRgbColor; pSimpleMarker.Style = esriSimpleMarkerStyle.esriSMSDiamond; pSimpleMarker.Size = 8; //setup line symbol ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbol(); ISymbol pSymbolLine = (ISymbol)pSimpleLineSymbol; pRgbColor = new ESRI.ArcGIS.Display.RgbColor(); pRgbColor.Red = 0; pRgbColor.Green = 255; pRgbColor.Blue = 0; pSimpleLineSymbol.Color = pRgbColor; pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; pSimpleLineSymbol.Width = 1; //setup simplefill symbol ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbol(); ISymbol pSymbolPolygon = (ISymbol)pSimpleFillSymbol; pRgbColor = new ESRI.ArcGIS.Display.RgbColor(); pRgbColor.Red = 0; pRgbColor.Green = 0; pRgbColor.Blue = 255; pSimpleFillSymbol.Color = pRgbColor; pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; //get all the polygons in the current map extent ina cursor IEnvelope pMapExtent = pActiveView.Extent; ISpatialFilter pQFilter = new SpatialFilter(); pQFilter.GeometryField = "SHAPE"; pQFilter.Geometry = pMapExtent; pQFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureCursor pFCursor = pGFlayer.Search(pQFilter, true); //draw each polygon and then each polygon's point collection IFeature pFeature = pFCursor.NextFeature(); IGeometry pGeometry; while (pFeature != null) { pGeometry = pFeature.Shape; //draw the polygon //draw each vertex on the polygon IPointCollection pPointCollection = pGeometry as IPointCollection; for (int i = 0; i < pPointCollection.PointCount; i++) { IGeometry pPtGeom = pPointCollection.get_Point(i); IElement pElement = new MarkerElement(); pElement.Geometry = pPtGeom; IMarkerElement pMarkerElement = pElement as IMarkerElement; pMarkerElement.Symbol = pSimpleMarker; pGraphicsContainer.AddElement(pElement, 0); } pFeature = pFCursor.NextFeature(); } bolVerticesOn = true; } else //if (bolVerticesOn == true) { bolVerticesOn = false; } //refresh the map pActiveView.Refresh(); pActiveView.Refresh(); } catch (Exception ex) { MessageBox.Show("Error Message: " + Environment.NewLine + ex.Message + Environment.NewLine + Environment.NewLine + "Error Source: " + Environment.NewLine + ex.Source + Environment.NewLine + Environment.NewLine + "Error Location:" + Environment.NewLine + ex.StackTrace, "AGRC Custom Tools ArcMap Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }