laptop and a wrench

漏洞

ClassCastException is generated when casting IGeometry to IGeoEllipse.

上次发布: August 25, 2014 No Product Found
漏洞 ID 编号 NIM035086
已提交May 9, 2008
上次修改时间June 5, 2024
适用范围No Product Found
找到的版本9.2
编程语言Java
修正版本N/A
状态Fixed

解决办法

The following code illustrates a work around to the problem.package arcgissamples.militaryanalyst.geodesy;import javax.swing.JFrame;import com.esri.arcgis.controls.*;import javax.swing.*;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import com.esri.arcgis.systemUI.*;import com.esri.arcgis.system.*;import java.awt.event.*;import com.esri.arcgis.geometry.*;import com.esri.arcgis.display.*;import com.esri.arcgis.carto.FeatureLayer;import com.esri.arcgis.carto.SimpleRenderer;import com.esri.arcgis.carto.esriViewDrawPhase;import com.esri.arcgis.geometry.Point;import com.esri.arcgis.geometry.Polygon;import com.esri.arcgis.geometry.Polyline;import java.awt.*;import com.esri.arcgis.carto.*;import com.esri.arcgis.militaryanalyst.*;import com.esri.arcgis.controls.*;import javax.swing.filechooser.FileFilter;import <a href="http://java.io" target="_blank">java.io</a>.IOException;import java.util.*;import <a href="http://java.io" target="_blank">java.io</a>.File;/** * <p>Title: MAGeodesy with map control</p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2006</p> * <p>Company: </p> * @author unascribed * @version 1.0 */public class MAGeodesy extends JFrame implements ActionListener,IMapControlEvents2{ private MapControl mapControl; private ToolbarControl toolBarControl; private Polyline polyLine = null; private JButton refreshButton,computeButton,clearLineButton; private JButton ellipseButton,kpButton,clearButton,clearEllipseButton; private JTextField X1Text; private JTextField Y1Text ; private JTextField X2Text ; private JTextField Y2Text ; private JTextField aziText ; private JTextField distText ; private int countClicks=0; private JComboBox lineCbo; private JTextField centerX1Text; private JTextField centerY1Text; private JTextField XAxisText ; private JTextField YAxisText ; private JTextField rotationText; private java.util.Vector pointVector; private final String R="Rhumb Line"; private final String G="Geodesic Line"; private final String C="Great Circle"; private IPolygon keypointPolygon; private boolean flag = true; private IPoint startPoint,endPoint; public MAGeodesy(String arcgishome){ super("MAGeodesy"); buildGui(); try{ String shapePath = arcgishome + <a href="http://java.io" target="_blank">java.io</a>.File.separator+"java"+<a href="http://java.io" target="_blank">java.io</a>.File.separator+"samples"+<a href="http://java.io" target="_blank">java.io</a>.File.separator+"data"+<a href="http://java.io" target="_blank">java.io</a>.File.separator+"world"+<a href="http://java.io" target="_blank">java.io</a>.File.separator+"Continent.lyr"; mapControl.addLayerFromFile (shapePath,0); addWindowListener(new WindowAdapter() { //@Override public void windowClosing(WindowEvent e) { try { new AoInitialize().shutdown(); } catch (Exception ex) { // Don't care } e.getWindow().dispose(); } }); this.setSize(650,800); this.setVisible(true); pointVector = new Vector(); } catch(IOException io){ JOptionPane.showMessageDialog(this,"Map Control not created correctly: Check if path variable 'arcgishome' is set to <a href="file:c://program" target="_blank">c:\\program</a> files<a href="file://arcgis" target="_blank">\\arcgis</a> ","Error Message",JOptionPane.ERROR_MESSAGE); } } public void buildGui() { JPanel mainPanel = new JPanel(new BorderLayout()); mapControl = new MapControl(); try { mapControl.addIMapControlEvents2Listener(this); } catch (Exception ex) { } toolBarControl = new ToolbarControl(); JPanel userPanel = new JPanel(); JPanel linePanel = new JPanel(); linePanel.setLayout(new BorderLayout());//BoxLayout(linePanel,BoxLayout.Y_AXIS)); JPanel ellipsePanel = new JPanel(); ellipsePanel.setLayout(new BorderLayout());//(ellipsePanel,BoxLayout.Y_AXIS)); userPanel.setLayout(new BoxLayout(userPanel,BoxLayout.X_AXIS)); userPanel.add(linePanel); userPanel.add(ellipsePanel); JSplitPane sp = new JSplitPane(); JPanel geoLinePanel = new JPanel(); geoLinePanel.setLayout(new SpringLayout());//GridLayout(8,2)); JPanel geoEllipsePanel = new JPanel(); JPanel lButtonPanel = new JPanel(); JPanel eButtonPanel = new JPanel(); linePanel.add(geoLinePanel,BorderLayout.CENTER); ellipsePanel.add(geoEllipsePanel,BorderLayout.CENTER); linePanel.add(lButtonPanel,BorderLayout.SOUTH); ellipsePanel.add(eButtonPanel,BorderLayout.SOUTH); geoEllipsePanel.setLayout(new SpringLayout());//GridLayout(8,2)); geoEllipsePanel.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("GeoEllipse"), BorderFactory.createEmptyBorder(5,5,5,5))); JLabel labelCenterX = new JLabel("X1(degrees):"); labelCenterX.setLabelFor(centerX1Text); centerX1Text = new JTextField(); JLabel labelCenterY = new JLabel("Y1(degrees):"); labelCenterY.setLabelFor(centerY1Text); centerY1Text = new JTextField(); JLabel labelXAxis = new JLabel("X Axis(km):"); labelXAxis.setLabelFor(XAxisText); XAxisText = new JTextField(); JLabel labelYAxis = new JLabel("Y Axis(km):"); labelYAxis.setLabelFor(YAxisText); YAxisText = new JTextField(); JLabel rotation = new JLabel("Rotation(degrees)"); rotation.setLabelFor(rotationText); rotationText = new JTextField(); ellipseButton = new JButton("Draw Ellipse"); kpButton = new JButton("Draw key points"); clearButton = new JButton("Clear Fields"); eButtonPanel.add(ellipseButton); eButtonPanel.add(kpButton); eButtonPanel.add(clearButton); ellipseButton.addActionListener(this); kpButton.addActionListener(this); clearButton.addActionListener(this); ellipseButton.setMnemonic(KeyEvent.VK_E); kpButton.setMnemonic(KeyEvent.VK_K); clearButton.setMnemonic(KeyEvent.VK_C); geoEllipsePanel.add(labelCenterX); geoEllipsePanel.add(centerX1Text); geoEllipsePanel.add(labelCenterY); geoEllipsePanel.add(centerY1Text); geoEllipsePanel.add(labelXAxis); geoEllipsePanel.add(XAxisText); geoEllipsePanel.add(labelYAxis); geoEllipsePanel.add(YAxisText); geoEllipsePanel.add(rotation); geoEllipsePanel.add(rotationText); SpringUtilities.makeCompactGrid(geoEllipsePanel, 5, 2, //rows, cols 6, 6, //initX, initY 6, 6); //xPad, yPad clearLineButton = new JButton("Add Layer"); computeButton = new JButton("Draw GeoLine"); computeButton.addActionListener(this); lButtonPanel.add(computeButton); refreshButton = new JButton("Clear Fields"); refreshButton.addActionListener(this); lButtonPanel.add(refreshButton); computeButton.setMnemonic(KeyEvent.VK_C); refreshButton.setMnemonic(KeyEvent.VK_R); clearLineButton.setMnemonic(KeyEvent.VK_A); geoLinePanel.setName("Input"); JLabel labelX = new JLabel("X1:"); labelX.setLabelFor(X1Text); X1Text = new JTextField(); JLabel labelY = new JLabel("Y1:"); labelY.setLabelFor(Y1Text); Y1Text = new JTextField(); JLabel X2Label = new JLabel("X2:"); X2Label.setLabelFor(X2Text); X2Text = new JTextField(); JLabel Y2Label = new JLabel("Y2:"); Y2Label.setLabelFor(Y2Text); Y2Text = new JTextField(); lineCbo = new JComboBox(); lineCbo.addItem(R); lineCbo.addItem(G); lineCbo.addItem(C); lineCbo.addActionListener(this); JLabel lineLabel = new JLabel("Line Type:"); lineLabel.setLabelFor(lineCbo); JLabel labelAzi = new JLabel("Azimuth(degree):"); labelAzi.setLabelFor(aziText); aziText = new JTextField(); JLabel labelDist = new JLabel("Distance(km) :"); labelDist.setLabelFor(distText); distText = new JTextField(); geoLinePanel.add(labelX); geoLinePanel.add(X1Text); geoLinePanel.add(labelY); geoLinePanel.add(Y1Text); geoLinePanel.add(X2Label); geoLinePanel.add(X2Text); geoLinePanel.add(Y2Label); geoLinePanel.add(Y2Text); geoLinePanel.add(lineLabel); geoLinePanel.add(lineCbo); geoLinePanel.add(labelAzi); geoLinePanel.add(aziText); geoLinePanel.add(labelDist); geoLinePanel.add(distText); SpringUtilities.makeCompactGrid(geoLinePanel, 7, 2, //rows, cols 6, 6, //initX, initY 6, 6); //xPad, yPad geoLinePanel.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("GeoPolyline"), BorderFactory.createEmptyBorder(5,5,5,5))); //geoLinePanel.add(lButtonPanel); //linePanel.add(geoLinePanel,BorderLayout.WEST); //linePanel.add(lButtonPanel,BorderLayout.SOUTH); try { toolBarControl.setBuddyControl(mapControl); toolBarControl.addItem(new ControlsOpenDocCommand(), 0, 0, false, 0, esriCommandStyles.esriCommandStyleIconOnly); //open toolBarControl.addItem(new ControlsMapZoomInTool(), 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconAndText); //ZoomIn toolBarControl.addItem(new ControlsMapZoomOutTool(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconAndText); //ZoomOut toolBarControl.addItem(new ControlsMapPanTool(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconAndText); //Pan toolBarControl.addItem(new ControlsMapFullExtentCommand(), 0, -1, true, 20, esriCommandStyles.esriCommandStyleIconAndText); toolBarControl.addItem(new com.esri.arcgis.controls.ControlsSelectTool(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconAndText); } catch (Exception ex) { } mainPanel.add(toolBarControl,BorderLayout.NORTH); mainPanel.add(mapControl,BorderLayout.CENTER); mainPanel.add(userPanel,BorderLayout.SOUTH); getContentPane().add(mainPanel); this.setDefaultCloseOperation(this.EXIT_ON_CLOSE); } public boolean getPoints() { try { double x1 = java.lang.Double.valueOf(X1Text.getText()).doubleValue(); double y1 = java.lang.Double.valueOf(Y1Text.getText()).doubleValue(); double x2 = java.lang.Double.valueOf(X2Text.getText()).doubleValue(); double y2 = java.lang.Double.valueOf(Y2Text.getText()).doubleValue(); startPoint = new Point(); startPoint.putCoords(x1,y1); endPoint = new Point(); endPoint.putCoords(x2,y2); return true; } catch (Exception ex) { JOptionPane.showMessageDialog(this,"Input value incorrect"); } return false; } public void actionPerformed(java.awt.event.ActionEvent e) { if(e.getSource()==computeButton){ if(((String)lineCbo.getSelectedItem()).equalsIgnoreCase(G)){ if(getPoints()) drawGeodesicLine(startPoint,endPoint); } else if(((String)lineCbo.getSelectedItem()).equalsIgnoreCase(R)){ if(getPoints()) drawRhumbLine(startPoint, endPoint); } else if(((String)lineCbo.getSelectedItem()).equalsIgnoreCase(C)){ if(getPoints()) drawGreateCircle(startPoint, endPoint); } } else if(e.getSource()==ellipseButton) { if(checkInput()) drawEllipse(); } else if(e.getSource()==clearButton) { try { mapControl.getActiveView().getGraphicsContainer().deleteAllElements(); mapControl.refresh(esriViewDrawPhase.esriViewBackground, null, null); flag = false; } catch (Exception ex) { System.out.println("Error in refresh"); ex.printStackTrace(); } centerX1Text.setText(""); centerY1Text.setText(""); XAxisText.setText(""); YAxisText.setText("") ; rotationText.setText(""); } else if(e.getSource()==kpButton) { if(checkInput()) drawKeyPoints(); } else if(e.getSource()==refreshButton){ try { mapControl.getActiveView().getGraphicsContainer().deleteAllElements(); mapControl.refresh(esriViewDrawPhase.esriViewBackground, null, null); pointVector.removeAllElements(); } catch (Exception ex) { System.out.println("Error in refresh"); ex.printStackTrace(); } X1Text.setText(""); Y1Text.setText("") ; X2Text.setText("") ; Y2Text.setText("") ; } } public void drawKeyPoints() { try { //outline color IRgbColor color = new RgbColor(); color.setGreen(255); //make fill color null IColor nullColor = new RgbColor(); nullColor.setNullColor(true); //create the outline symbol ILineSymbol lineSymbol = new SimpleLineSymbol(); lineSymbol.setColor(color); lineSymbol.setWidth(1.5); IHashLineSymbol hashLineSymbol = new HashLineSymbol(); hashLineSymbol.setHashSymbolByRef(lineSymbol); //create the fill symbol for the polygon IFillSymbol fillSymbol = new SimpleFillSymbol(); fillSymbol.setOutline(hashLineSymbol); fillSymbol.setColor(nullColor); //Run the CreateGeoEllipse subprocedure to get the geometry of the //key points polygon generated from the GeoEllipse. if(keypointPolygon == null) createEllipse(); //create the IElement to be rendered a PolygonElement and // its geometry to the key points polygon geometry defined in the //CreateGeoEllipse subprocedure IElement keyPointElement = new PolygonElement(); keyPointElement.setGeometry(keypointPolygon); //QI to IFillShapeElement to the symbology of the key points polygon graphic IFillShapeElement fillElement ; fillElement = (IFillShapeElement)keyPointElement; fillElement.setSymbol(fillSymbol); IElement e = (IElement)fillElement; //define the graphics container and draw the key points polygon graphic mapControl.getActiveView().getGraphicsContainer().addElement(e,0); mapControl.getActiveView().refresh(); } catch (Exception ex) { } } public boolean checkInput() { if(centerX1Text.getText().length()==0) { JOptionPane.showMessageDialog(this,"Input center X value","Error Message",JOptionPane.ERROR_MESSAGE); return false; } else if(centerY1Text.getText().length()==0) { JOptionPane.showMessageDialog(this,"Input center Y value","Error Message",JOptionPane.ERROR_MESSAGE); return false; } else if(XAxisText.getText().length()==0) { JOptionPane.showMessageDialog(this,"Input X axis value","Error Message",JOptionPane.ERROR_MESSAGE); return false; } else if(YAxisText.getText().length()==0) { JOptionPane.showMessageDialog(this,"Input X axis value","Error Message",JOptionPane.ERROR_MESSAGE); return false; } else if(rotationText.getText().length()==0) { JOptionPane.showMessageDialog(this,"Input rotation value","Error Message",JOptionPane.ERROR_MESSAGE); return false; } return true; } public IGeoEllipse createEllipse() { IGeoEllipse gEllipse = null; try { //Get axis values in km double x = java.lang.Double.parseDouble(XAxisText.getText()); double y = java.lang.Double.parseDouble(YAxisText.getText()); //Get ellipse origin values double xCenter = java.lang.Double.parseDouble(centerX1Text.getText()); double yCenter = java.lang.Double.parseDouble(centerY1Text.getText()); //Create origin point for ellipse IPoint startPoint = new Point(); startPoint.putCoords(xCenter,yCenter); //Create new ellipse with origin point //both axis in km and rotation gEllipse = new GeoEllipse(); gEllipse.setOrigin(startPoint); gEllipse.setAxisX(x*1000); gEllipse.setAxisY(y*1000); //set rotation in degrees gEllipse.setRotation(java.lang.Double.parseDouble(rotationText.getText())); //set the number of vertices to be used in the creation //of the polygon representation of the geoellipse gEllipse.setGeoEllipsePointCount(100); //define the key points polygon, which is a polygon connecting the end //points of the geoellipse X and Y axes keypointPolygon = gEllipse.getKeyPoints(); } catch (Exception ex) { } return gEllipse; } private void drawEllipse(){ try { //Outline color IRgbColor r = new RgbColor(); r.setRed(255); //Fill color IColor noFill = new RgbColor(); noFill.setNullColor(true); //Create GeoEllipse IGeoEllipse gEllipse = createEllipse(); //Create polygon with geo ellipse IPolygon poly = (IPolygon)(gEllipse); IElement gElement = new GeoEllipseElement(); //Create line symbol ILineSymbol lineSymbol = new SimpleLineSymbol(); lineSymbol.setColor(r); lineSymbol.setWidth(1.5); //Create fill symbol IFillSymbol fillSymbol = new LineFillSymbol(); fillSymbol.setOutline(lineSymbol); fillSymbol.setColor(noFill); //Set the geometry of the ellipse element gElement.setGeometry(poly); //Throws ClassCastException: //GeoEllipse geoEllipse = (GeoEllipse) gElement.getGeometry(); //following is the explanation and correct usage for constructing a GeoEllipse from an existing one /* * According to the MA team - "GeoEllipse class is used to construct a geodetically correct ellipse based on the parameters like center point, x-axis, y-axis, rotation etc. This ellipse is nothing but a Polygon geometry stored internally. And when you call getGeometry, that’s the polygon it returns. However, you can not set your own geometry. That is because there is no way to guarantee that the polygon geometry you set is actually an ellipse. So if you need to construct an ellipse, you need to do it by setting the input parameters mentioned earlier. The above is true even when IElement.getGeometry() is used to construct a GeoEllipse (above line 601). The inputs for other MA Geometries - GeoPolyline and GeoPolygon – are actually polyline and polygon geometries respectively. So this is the case only for GeoEllipse. In most use cases, you would anyways want to create Ellipse with center point, axes etc." */ GeoEllipse geoEllipse = new GeoEllipse(); geoEllipse.setAxisX(gEllipse.getAxisY()); geoEllipse.setAxisY(gEllipse.getAxisY()); geoEllipse.setOrigin(gEllipse.getOrigin()); geoEllipse.setRotation(gEllipse.getRotation()); geoEllipse.setGeoEllipsePointCount(gEllipse.getGeoEllipsePointCount()); //It works fine but is deprecated at 9.2: //IGeoEllipse geoEllipse = (GeoEllipse) (gElement.getGeometry()); System.out.println("Casting Success!!"); //Create ielement IFillShapeElement fillElement = new EllipseElement(gElement); fillElement.setSymbol(fillSymbol); IElement ee = (IElement)(fillElement); mapControl.getActiveView().getGraphicsContainer().addElement(ee,0); mapControl.getActiveView().refresh(); } catch (Exception ex) { /*JOptionPane m = new JOptionPane(); m.showMessageDialog(this,"Geol Ellipse not created ","Error",JOptionPane.ERROR_MESSAGE);*/ ex.printStackTrace(); } } private void drawRhumbLine(IPoint p1, IPoint p2){ try { //Set up measurement tool with //end point start point and line type MeasurementTool measureTool = new MeasurementTool(); measureTool.setFromPoint(p1); measureTool.setToPoint(p2); measureTool.setSpecialGeolineType(cjmtkSGType.cjmtkSGTRhumbLine); //Get poly line from measurement tool with desired number of points IPolyline polyLine = measureTool.getPolyline(100); //Set up geo polyline GeoPolyline g = new GeoPolyline(); g.setPolyline(polyLine); //Set up outline color IRgbColor r = new RgbColor(); r.setRGB(255); //Add outline color to the symbol which will //be added to the line IMarkerSymbol arrowMarker = new ArrowMarkerSymbol(); arrowMarker.setColor(r); //Create simple line decoration element ISimpleLineDecorationElement simpleLineDecoElement = new SimpleLineDecorationElement(); simpleLineDecoElement.setMarkerSymbol(arrowMarker); simpleLineDecoElement.addPosition(1.0); ILineDecorationElement lineDecoElement = simpleLineDecoElement; //Add line decoration element to line decoration ILineDecoration lineDecoration = new LineDecoration(); lineDecoration.addElement(lineDecoElement); //Define carto line symbol ICartographicLineSymbol cartoLineSymbol = new CartographicLineSymbol(); cartoLineSymbol.setColor(r); cartoLineSymbol.setWidth(1.5); //Set line properties ILineProperties lineProps = new CartographicLineSymbol(); lineProps = (ILineProperties)(cartoLineSymbol); lineProps.setLineDecorationByRef(lineDecoration); //create line symbol from line properties ILineSymbol symbol = (ILineSymbol)(lineProps); //Set line elment with the symbol ILineElement lineElement = new LineElement(); lineElement.setSymbol(symbol); //Set elemenet geometry with that of polyline IElement element = (IElement)lineElement; element.setGeometry(polyLine); //add line to graphics container mapControl.getActiveView().getGraphicsContainer().addElement(element,0); mapControl.getActiveView().refresh(); distText.setBackground(Color.lightGray); aziText.setBackground(Color.lightGray); distText.setText(java.lang.String.valueOf(Math.round(measureTool.getDistance() / 1000))); aziText.setText(java.lang.String.valueOf(Math.round(measureTool.getAngle()))); } catch (Exception ex) { ex.printStackTrace(); } } /** * This method allows the user to draw a Geodesic Line * based on the inputs in the GUI * @param p1 - start point * @param p2 - end point */ private void drawGeodesicLine(IPoint p1, IPoint p2){ try { //Set measure tool with //end point start point and line type MeasurementTool measureTool = new MeasurementTool(); measureTool.setFromPoint(p1); measureTool.setToPoint(p2); measureTool.setSpecialGeolineType(cjmtkSGType.cjmtkSGTGeodesic); //Get polyline from the measure tool with the number of points desired IPolyline polyLine = measureTool.getPolyline(100); //Set up geopolyline GeoPolyline g = new GeoPolyline(); g.setPolyline(polyLine); //Outer boundary color IRgbColor r = new RgbColor(); r.setRGB(255); IMarkerSymbol arrowMarker = new ArrowMarkerSymbol(); arrowMarker.setColor(r); //Create simple line decoration element ISimpleLineDecorationElement simpleLineDecoElement = new SimpleLineDecorationElement(); simpleLineDecoElement.setMarkerSymbol(arrowMarker); simpleLineDecoElement.addPosition(1.0); ILineDecorationElement lineDecoElement = simpleLineDecoElement; //Add line decoration element to line decoration ILineDecoration lineDecoration = new LineDecoration(); lineDecoration.addElement(lineDecoElement); //Define carto line symbol ICartographicLineSymbol cartoLineSymbol = new CartographicLineSymbol(); cartoLineSymbol.setColor(r); cartoLineSymbol.setWidth(1.5); //Set line properties ILineProperties lineProps = new CartographicLineSymbol(); lineProps = (ILineProperties)(cartoLineSymbol); lineProps.setLineDecorationByRef(lineDecoration); ILineSymbol symbol = (ILineSymbol)(lineProps); ILineElement lineElement = new LineElement(); lineElement.setSymbol(symbol); IElement element = (IElement)lineElement; element.setGeometry(polyLine); mapControl.getActiveView().getGraphicsContainer().addElement(element,0); mapControl.getActiveView().refresh(); distText.setBackground(Color.lightGray); aziText.setBackground(Color.lightGray); distText.setText(java.lang.String.valueOf(Math.round(measureTool.getDistance() / 1000))); aziText.setText(java.lang.String.valueOf(Math.round(measureTool.getAngle()))); } catch (Exception ex) { ex.printStackTrace(); } } /** * This method allows the user to draw a Great Circle * based on the inputs in GUI * @param p1 start point * @param p2 end point */ private void drawGreateCircle(IPoint p1, IPoint p2){ try{ //Set up measurement tool //with start point end point and line type MeasurementTool measureTool = new MeasurementTool(); measureTool.setFromPoint(p1); measureTool.setToPoint(p2); measureTool.setSpecialGeolineType(cjmtkSGType.cjmtkSGTGreatCircle); //get poly line from measurement tool with number of points desired IPolyline polyLine = measureTool.getPolyline(100); //Set up geo polyline GeoPolyline g = new GeoPolyline(); g.setPolyline(polyLine); //Set up outline color IRgbColor r = new RgbColor(); r.setRGB(255); IMarkerSymbol arrowMarker = new ArrowMarkerSymbol(); arrowMarker.setColor(r); //Create simple line decoration element ISimpleLineDecorationElement simpleLineDecoElement = new SimpleLineDecorationElement(); simpleLineDecoElement.setMarkerSymbol(arrowMarker); simpleLineDecoElement.addPosition(1.0); ILineDecorationElement lineDecoElement = simpleLineDecoElement; //Add line decoration element to line decoration ILineDecoration lineDecoration = new LineDecoration(); lineDecoration.addElement(lineDecoElement); //Define carto line symbol ICartographicLineSymbol cartoLineSymbol = new CartographicLineSymbol(); cartoLineSymbol.setColor(r); cartoLineSymbol.setWidth(1.5); //Set line properties ILineProperties lineProps = new CartographicLineSymbol(); lineProps = (ILineProperties)(cartoLineSymbol); lineProps.setLineDecorationByRef(lineDecoration); ILineSymbol symbol = (ILineSymbol)(lineProps); ILineElement lineElement = new LineElement(); lineElement.setSymbol(symbol); IElement element = (IElement)lineElement; element.setGeometry(polyLine); mapControl.getActiveView().getGraphicsContainer().addElement(element,0); mapControl.getActiveView().refresh(); distText.setBackground(Color.lightGray); aziText.setBackground(Color.lightGray); distText.setText(java.lang.String.valueOf(Math.round(measureTool.getDistance() / 1000))); aziText.setText(java.lang.String.valueOf(Math.round(measureTool.getAngle()))); } catch (Exception ex) { ex.printStackTrace(); } } public void onAfterDraw(IMapControlEvents2OnAfterDrawEvent theEvent) {} public void onAfterScreenDraw(IMapControlEvents2OnAfterScreenDrawEvent theEvent) {} public void onBeforeScreenDraw(IMapControlEvents2OnBeforeScreenDrawEvent theEvent) {} public void onDoubleClick(IMapControlEvents2OnDoubleClickEvent theEvent) { } public void onExtentUpdated(IMapControlEvents2OnExtentUpdatedEvent theEvent) {} public void onFullExtentUpdated(IMapControlEvents2OnFullExtentUpdatedEvent theEvent) {} public void onKeyDown(IMapControlEvents2OnKeyDownEvent theEvent) {} public void onKeyUp(IMapControlEvents2OnKeyUpEvent theEvent) {} public void onMapReplaced(IMapControlEvents2OnMapReplacedEvent theEvent) {} public void onMouseDown(IMapControlEvents2OnMouseDownEvent theEvent) { try { //On a right mouse button click use the TrackPolygon method on the map control //to define the vertices of an eventual GeoPolygon. Each right mouse button //click adds a vertex to the polygon; double-clicking the right mouse button //completes the polygon. int button= theEvent.getButton(); if(button==2){ //Create the polygon from the TrackPolygon method. This polygon will be //the foundation for a GeoPolygon object. IPolygon trackPoly ; IElement trackPolyElement ; trackPoly = (IPolygon)mapControl.trackPolygon(); //Define the GeoPolygon, QI to IGeoPolygon IGeoPolygon geoPolygon = new GeoPolygon(); geoPolygon.setPolygon(trackPoly); // the GeoPolyline type to form the segments of the GeoPolygon. In this ce //the segments will be Geodesic lines. geoPolygon.setSpecialGeolineType(com.esri.arcgis.militaryanalyst.cjmtkSGType.cjmtkSGTGeodesic); // the GeoPolygon spatial reference. // geoPolygon.BeSpatialReference = SpatialRef //outline color IRgbColor color = new RgbColor(); color.setBlue(255); //make fill color null IColor nullColor = new RgbColor(); nullColor.setNullColor(true); //create the outline symbol ILineSymbol lineSymbol = new SimpleLineSymbol(); lineSymbol.setColor(color); lineSymbol.setWidth(1.5); //create the fill symbol for the GeoPolygon IFillSymbol fillSymbol = new SimpleFillSymbol(); fillSymbol.setOutline(lineSymbol); fillSymbol.setColor(nullColor); //Create the IElement to be rendered a GeoPolygonElement and // its geometry to the GeoPolygon geometry. When a GeoPolygonElement //graphic is moved from one location to another in the map control //the GeoPolygon geometry is automatically updated bed on the //geographic location and the graphic is updated accordingly. trackPolyElement = new GeoPolygonElement(); trackPolyElement.setGeometry((IGeometry)geoPolygon); //QI to IFillShapeElement to the symbology of the GeoPolygon graphic IFillShapeElement fillElement ; fillElement = (IFillShapeElement)trackPolyElement; fillElement.setSymbol(fillSymbol); IGraphicsContainer gCont = mapControl.getActiveView().getGraphicsContainer(); gCont.deleteAllElements(); IElement element = (IElement)fillElement; //element.setGeometry(pointOnMap); gCont.addElement(element,0); //add the point to the map and refresh the map mapControl.refresh(esriViewDrawPhase.esriViewGraphics,null,null); } } catch (Exception ex) { } } public void onMouseMove(IMapControlEvents2OnMouseMoveEvent theEvent) { } public void onMouseUp(IMapControlEvents2OnMouseUpEvent theEvent) {} public void onOleDrop(IMapControlEvents2OnOleDropEvent theEvent) {} public void onSelectionChanged(IMapControlEvents2OnSelectionChangedEvent theEvent) {} public void onViewRefreshed(IMapControlEvents2OnViewRefreshedEvent theEvent) {} public void onMouseUp(ITOCControlEventsOnMouseUpEvent theEvent) {} public static void main(String[] args) {//throws HeadlessException { String arcgisHome = null; try { arcgisHome = System.getenv("ARCGISHOME"); } catch (Error ex) { JOptionPane.showInputDialog("ARCGISHOME h not been in your system path variable example ARCGISHOME = c:/programfiles/arcgis"); } try{ EngineInitializer.initializeVisualBeans(); AoInitialize aoInit = new AoInitialize(); aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine); MAGeodesy MAGeodesy1 = new MAGeodesy(arcgisHome); } catch(Exception e){e.printStackTrace();} }}

重现步骤

漏洞 ID: NIM035086

软件:

  • No Product Found

当漏洞状态发生变化时获得通知

下载 Esri 支持应用程序

发现关于本主题的更多内容

获取来自 ArcGIS 专家的帮助

联系技术支持部门

下载 Esri 支持应用程序

转至下载选项