And because I am using C# and don't exaclty know of all the references needed to import,
I still have no real understanding of all the misc other function calls (SimpleMarkerSymbol, MarkerElement, etc). I can look up their meaning but do not understand really why they are needed or why they should/would be needed
Code without explanation in my context won't really help
import java.awt.event.MouseEvent; import java.io.IOException; import java.text.DecimalFormat; import com.esri.arcgis.addins.desktop.Tool; import com.esri.arcgis.arcmapui.IMxDocument; import com.esri.arcgis.carto.GroupElement; import com.esri.arcgis.carto.IActiveView; import com.esri.arcgis.carto.IGraphicsContainer; import com.esri.arcgis.carto.MarkerElement; import com.esri.arcgis.carto.TextElement; import com.esri.arcgis.display.IDisplayTransformation; import com.esri.arcgis.display.IScreenDisplay; import com.esri.arcgis.display.ITextSymbol; import com.esri.arcgis.display.RgbColor; import com.esri.arcgis.display.SimpleMarkerSymbol; import com.esri.arcgis.display.TextSymbol; import com.esri.arcgis.display.esriTextVerticalAlignment; import com.esri.arcgis.framework.IApplication; import com.esri.arcgis.geometry.IPoint; import com.esri.arcgis.geometry.ISpatialReference; import com.esri.arcgis.geometry.Point; import com.esri.arcgis.geometry.SpatialReferenceEnvironment; import com.esri.arcgis.interop.AutomationException; import com.esri.arcgis.support.ms.stdole.StdFont; public class Tool1 extends Tool { private IApplication app; private IActiveView av; private IMxDocument mxDocument; private String message; @Override public void activate() throws IOException, AutomationException { } @Override public void init(IApplication arg0) throws IOException, AutomationException { super.init(arg0); this.app = arg0; mxDocument = (IMxDocument) app.getDocument(); av = mxDocument.getActiveView(); } @Override public void mousePressed(MouseEvent mouseEvent) { super.mousePressed(mouseEvent); try{ Point point1 = new Point(); // point where user clicks point1.putCoords((double)mouseEvent.getX(), (double)mouseEvent.getY()); Point point2 = (Point) getMapCoordinatesFromScreenCoordinates(point1,av); double x = point2.getX(); double y = point2.getY(); DecimalFormat df = new DecimalFormat("#.####"); message = "x: " + df.format(x) + " y: " + df.format(y); RgbColor color = new RgbColor(); color.setRed(255); StdFont font = new StdFont(); font.setName("Arial"); SimpleMarkerSymbol sms = new SimpleMarkerSymbol(); sms.setStyle(com.esri.arcgis.display.esriSimpleMarkerStyle.esriSMSCircle); sms.setColor(color); MarkerElement me = new MarkerElement(); me.setSymbol(sms); me.setGeometry(point2); me.setName("me"); ITextSymbol textSymbol = new TextSymbol(); textSymbol.setColor(color); textSymbol.setFont(font); textSymbol.setSize(9); textSymbol.setVerticalAlignment(esriTextVerticalAlignment.esriTVACenter); TextElement textElement = new TextElement(); textElement.setSymbol(textSymbol); textElement.setColor(color); textElement.setText(message); textElement.setGeometry(point2); textElement.setYOffset(11.27); textElement.setName("textElement"); GroupElement gp = new GroupElement(); gp.addElement(textElement); gp.addElement(me); gp.setName("click location"); IGraphicsContainer graphicsContainer = av.getGraphicsContainer(); graphicsContainer.addElement(gp, 0); av.partialRefresh(com.esri.arcgis.carto.esriViewDrawPhase.esriViewGraphics, gp, av.getExtent()); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } public IPoint getMapCoordinatesFromScreenCoordinates(IPoint screenPoint, IActiveView activeView)throws Exception{ if (screenPoint == null || screenPoint.isEmpty() || activeView == null) return null; IScreenDisplay screenDisplay = activeView.getScreenDisplay(); IDisplayTransformation displayTransformation = screenDisplay.getDisplayTransformation(); return displayTransformation.toMapPoint((int)screenPoint.getX(), (int) screenPoint.getY()); } }
protected override void OnClick() { IMxDocument _mxDoc = ArcMap.Application.Document as IMxDocument; IMap _map = _mxDoc.FocusMap; IActiveView _activeView = _mxDoc.ActiveView; // IActiveView _activeView = _map as IActiveView; IPageLayout3 _pageLayout = _activeView as IPageLayout3; Double posX = 2.0; Double posY = 2.0; Double legW = 5.0; IGraphicsContainer _GraphContain = _pageLayout as IGraphicsContainer; IMapFrame _mapFrame = _GraphContain.FindFrame(_map) as IMapFrame; ESRI.ArcGIS.esriSystem.UID _uid = new UIDClass(); _uid.Value = "esriCarto.Legend"; IMapSurroundFrame _mapSurroundFrame = _mapFrame.CreateSurroundFrame((ESRI.ArcGIS.esriSystem.UID)_uid, null); IQuerySize _querySize = _mapSurroundFrame.MapSurround as IQuerySize; Double w = 0; Double h = 0; _querySize.QuerySize(ref w, ref h); Double aspectRatio = w / h; IEnvelope _envelope = new EnvelopeClass(); _envelope.PutCoords(posX, posY, (posX * legW), (posY * legW / aspectRatio)); IElement _element = _mapSurroundFrame as IElement; _element.Geometry = _envelope; _GraphContain.AddElement(_element, 0); _activeView = _mxDoc.ActiveView; if (_activeView is IPageLayout) { MessageBox.Show("You're in layout view"); } else if (_activeView is IMap) { MessageBox.Show("You're in Data view"); } _activeView.Refresh(); }
package gov.gis.leo; import java.io.IOException; import javax.swing.JOptionPane; import com.esri.arcgis.addins.desktop.Button; import com.esri.arcgis.arcmapui.IMxDocument; import com.esri.arcgis.carto.IActiveView; import com.esri.arcgis.carto.IMap; import com.esri.arcgis.carto.IPageLayout; import com.esri.arcgis.framework.IApplication; import com.esri.arcgis.interop.AutomationException; public class Button1 extends Button { @Override public void init(IApplication arg0) throws IOException, AutomationException { super.init(arg0); this.app = arg0; // Initialize our map document mxDocument = (IMxDocument)app.getDocument(); } /** * Called when the button is clicked. * * @exception java.io.IOException if there are interop problems. * @exception com.esri.arcgis.interop.AutomationException if the component throws an ArcObjects exception. */ @Override public void onClick() throws IOException, AutomationException { activeView = mxDocument.getActiveView(); if(activeView instanceof IPageLayout){ JOptionPane.showMessageDialog(null, "You are in Page Layout view"); } if(activeView instanceof IMap){ JOptionPane.showMessageDialog(null, "You are in data view"); } } private IMxDocument mxDocument; private IApplication app; private IActiveView activeView; }
If "by the same" you mean they both provide a way to set and display text, then yes, they are essentially the same in that regard. You could check the ArcObjects API, but the .NET version is really impossible to find anything unless you are willing to click on every tree node in every namespace.
You could check the ArcObjects API, but the .NET version is really impossible to find anything unless you are willing to click on every tree node in every namespace. <sarcasm>Let's see, if I don't know what I'm looking for, perhaps it might be in the carto namespace, but maybe in A? or B? or C? Maybe it's cartoUI, but is it IA, or IB? or.. a list would be nice... </sarcasm>
I'm assuming the ITextElement, in simplistic terms, is a box that contains text?
My confusion stems from wanting a text element or a textbox element. But again I assume they are essentially the same.
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.