private IStyleGalleryItem m_StyleGalleryItem: private void MainForm_Load(object sender, EventArgs e) { // Symbology control should be set on windows form first string sInstall = ESRI.ArcGIS.RuntimeManager.ActiveRuntime.Path; axSymbologyControl1.LoadStyleFile(sInstall + "\\Styles\\ESRI.ServerStyle"); axSymbologyControl1.StyleClass = esriSymbologyStyleClass.esriStyleClassMarkerSymbols; } private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { try { IPoint point = new PointClass(); point.PutCoords(e.mapX, e.mapY); IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)axMapControl1.ActiveView.FocusMap; // --- Element 1 ---------------------------------------------------------------- IElement pElement1 = null; pElement1 = new MarkerElementClass(); pElement1.Geometry = point; IMarkerElement markerElement1 = (IMarkerElement)pElement1; m_StyleGalleryItem = axSymbologyControl1.GetStyleClass(esriSymbologyStyleClass.esriStyleClassMarkerSymbols).GetItem(7); IMarkerSymbol markerSymbol1 = (IMarkerSymbol)m_StyleGalleryItem.Item; markerSymbol1.Size = 25; markerElement1.Symbol = markerSymbol1; // --- Element 2 ----------------------------------------------------------------- IElement pElement2 = null; IPoint pCalloutPoint = new PointClass(); pCalloutPoint.PutCoords(e.mapX, e.mapY); TextElementClass textElement = new TextElementClass(); textElement.Geometry = pCalloutPoint; textElement.Text = "text"; TextSymbolClass textSymbol = new TextSymbolClass(); IFontDisp font; font = new StdFontClass() as IFontDisp; font.Name = "Arial"; font.Bold = true; textSymbol.Font = font; textSymbol.Size = 7; IRgbColor pColor = new RgbColorClass(); pColor.Red = 0; pColor.Blue = 0; pColor.Green = 0; textSymbol.Color = pColor; textSymbol.XOffset = 13; textSymbol.YOffset = -13; BalloonCalloutClass callout = new BalloonCalloutClass(); callout.Style = esriBalloonCalloutStyle.esriBCSRectangle; callout.PutMargins(2, 1, 1, 0); IRgbColor background = new RgbColorClass(); background.Red = 200; background.Blue = 255; background.Green = 255; ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = background; callout.Symbol = simpleFillSymbol; textSymbol.Background = callout; textElement.Symbol = textSymbol; pElement2 = textElement as IElement; // --- Element 3 ----------------------------------------------------------------- IPoint p1 = new PointClass(); IPoint p2 = new PointClass(); p1 = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); p2 = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x - 30, e.y - 30); IPolyline polyline = new PolylineClass(); polyline.FromPoint = p1; polyline.ToPoint = p2; ILineElement lineElement = new LineElementClass(); IRgbColor color = new RgbColorClass(); color.Red = 255; color.Green = 120; color.Blue = 100; ISimpleLineSymbol symbol = new SimpleLineSymbolClass(); symbol.Color = color; symbol.Width = 2; lineElement.Symbol = symbol; IElement pElement3 = (IElement)lineElement; pElement3.Geometry = (IGeometry)polyline; // Group elements into group element IGroupElement group = new GroupElementClass(); group.AddElement(pElement2); group.AddElement(pElement1); group.AddElement(pElement3); axMapControl1.ActiveView.GraphicsContainer.AddElement((IElement)group, 0); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } catch (Exception exc) { System.Windows.Forms.MessageBox.Show(exc.Message); } }
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.