败事有余
路人甲
路人甲
  • 注册日期2006-12-31
  • 发帖数39
  • QQ
  • 铜币247枚
  • 威望0点
  • 贡献值0点
  • 银元0个
10楼#
发布于:2007-03-06 15:59
<P>GIS----你好!</P>
<P>我也做了例子在加载地图时还是在这里报错,</P>
<P>但 是我用其他的加载方法就没有错误,如我用手动打开文档的方法来加载图时是正确的。</P>
<P>但一用到这个就出错,为什么???</P>
<P>但是只能用这个啊?因为我的程序启动时需要用它自动来加载地图</P>

<P>mapControl.addShapeFile(filePath, "country.shp");</P>
<P>报错信息:</P>
<P>Exception in initMap : AutomationException: 0x8000ffff - <BR>AutomationException: 0x8000ffff - <BR>at com.esri.arcgis.beans.map.MapControl.addShapeFile(Unknown Source)</P>
<P>我是用java+AE 来做的,请帮帮忙,这个问题困绕我好几天了,没有办法处理,我刚做这方面的开发没有什么经验,</P>
<P>请你多帮帮忙。</P>
<P>谢谢</P><img src="images/post/smile/dvbbs/em02.gif" /><img src="images/post/smile/dvbbs/em02.gif" />
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
11楼#
发布于:2007-03-07 11:09
<P> 你可以再看看这个例子:http://edn.esri.com/index.cfm?fa=codeExch.sampleDetail;pg=/arcobjects/9.1/Samples/Controls/MapControl/GeoEvents/Java/javaGeoEvent.htm </P>
<P>另外注意下面的几句代码,代码是从上面的例子拿出来的 </P>
<P>   private String shapefilePath = ".." + File.separator + ".." + File.separator + "data</P>
<P>    MapBean localMapBean = this.mapBean;<BR>    localMapBean.addShapeFile(this.shapefilePath, "world30");<BR>    localMapBean.addShapeFile(this.shapefilePath, "dissolvecntry");<BR></P>
举报 回复(0) 喜欢(0)     评分
栀竹
路人甲
路人甲
  • 注册日期2006-04-27
  • 发帖数40
  • QQ
  • 铜币334枚
  • 威望0点
  • 贡献值0点
  • 银元0个
12楼#
发布于:2007-03-09 13:44
<P>应该是这样:</P>
<P>String filePath="C:\\arcgis\\ArcTutor\\LinearReferencing\\" ;</P>
<P>mapControl.addShapeFile(filePath, "country");</P>
举报 回复(0) 喜欢(0)     评分
败事有余
路人甲
路人甲
  • 注册日期2006-12-31
  • 发帖数39
  • QQ
  • 铜币247枚
  • 威望0点
  • 贡献值0点
  • 银元0个
13楼#
发布于:2007-03-12 09:36
<P>package DrawTextd;</P>
<P>import javax.swing.SwingUtilities;<BR>import java.awt.BorderLayout;<BR>import javax.swing.JPanel;<BR>import javax.swing.JFrame;<BR>import javax.swing.UIManager;</P>
<P>import java.awt.Dimension;<BR>import java.awt.GridBagLayout;<BR>import javax.swing.BoxLayout;</P>
<P>import com.esri.arcgis.beans.map.IMapControlEvents2;<BR>import com.esri.arcgis.beans.map.IMapControlEvents2Adapter;<BR>import com.esri.arcgis.beans.map.IMapControlEvents2OnAfterDrawEvent;<BR>import com.esri.arcgis.beans.map.IMapControlEvents2OnMouseDownEvent;<BR>import com.esri.arcgis.beans.map.MapControl;<BR>import com.esri.arcgis.carto.FeatureLayer;<BR>import com.esri.arcgis.carto.SimpleRenderer;<BR>import com.esri.arcgis.carto.esriViewDrawPhase;<BR>import com.esri.arcgis.display.BezierTextPath;<BR>import com.esri.arcgis.display.IRgbColor;<BR>import com.esri.arcgis.display.ISimpleTextSymbol;<BR>import com.esri.arcgis.display.ITextPath;<BR>import com.esri.arcgis.display.RgbColor;<BR>import com.esri.arcgis.display.SimpleFillSymbol;<BR>import com.esri.arcgis.display.SimpleLineSymbol;<BR>import com.esri.arcgis.display.TextSymbol;<BR>import com.esri.arcgis.geometry.IEnvelope;<BR>import com.esri.arcgis.geometry.Point;<BR>import com.esri.arcgis.geometry.Polyline;<BR>import com.esri.arcgis.support.ms.stdole.StdFont;<BR>import com.esri.arcgis.system.AoInitialize;<BR>import com.esri.arcgis.system.EngineInitializer;<BR>import com.esri.arcgis.system.esriLicenseProductCode;</P>
<P>import javax.swing.JLabel;<BR>import javax.swing.JButton;<BR>import java.awt.GridBagConstraints;<BR>import java.awt.GridLayout;<BR>import java.io.File;</P>
<P>import javax.swing.JTextField;</P>
<P>public class DrawTextd extends JFrame {</P>
<P> private static final long serialVersionUID = 1L;</P>
<P> private JPanel jContentPane = null;</P>
<P> private JPanel bottomPanel = null;</P>
<P> private JPanel mainPanel = null;</P>
<P> private JPanel rightPanel = null;<BR> MapControl  mapControl=null;<BR> Polyline polyLine = null;</P>
<P> private JLabel helpLabel = null;<BR> String helpLabelString = "<HTML> Left mouse  <BR>" +<BR>    "button to trace a line <BR>" + "to draw text along. <BR>" + "<BR>" +<BR>    "Right mouse button to <BR>" + "drag a rectangle to zoom in.. <BR>" +<BR>    "</HTML>";  //  @jve:decl-index=0:</P>
<P> private JPanel buttonPanel = null;</P>
<P> private JButton clearButton = null;</P>
<P> private JButton fullExtentButton = null;</P>
<P> private JLabel enterTextLabel = null;</P>
<P> private JTextField textField = null;<BR> //String filePath = ".." + File.separator + ".." + File.separator + ".." + File.separator + ".." + File.separator + ".." + File.separator + "data" ;//+ File.separator + "World";  //  @jve:decl-index=0:<BR> String ss=this.getClass().getResource("/").getPath() ;  //  @jve:decl-index=0:<BR> String f1 = ".." + File.separator + ".." + File.separator + ".." + File.separator + ".." + File.separator + ".." + File.separator + "data" ;<BR> private String filePath="C:\\arcgis\\ArcTutor\\LinearReferencing\\" ;  //  @jve:decl-index=0:<BR> <BR> <BR> /**D:\map\data<BR>  * This method initializes bottomPanel <BR>  *  <BR>  * @return javax.swing.JPanel <BR>  */<BR> private JPanel getBottomPanel() {<BR>  if (bottomPanel == null) {<BR>   GridLayout gridLayout = new GridLayout();<BR>   gridLayout.setRows(1);<BR>   enterTextLabel = new JLabel();<BR>   enterTextLabel.setText("Enter Text");<BR>   bottomPanel = new JPanel();<BR>   bottomPanel.setLayout(gridLayout);<BR>   bottomPanel.add(enterTextLabel, null);<BR>   bottomPanel.add(getTextField(), null);<BR>  }<BR>  return bottomPanel;<BR> }</P>
<P> /**<BR>  * This method initializes mainPanel <BR>  *  <BR>  * @return javax.swing.JPanel <BR>  */<BR> private JPanel getMainPanel() {<BR>  if (mainPanel == null) {<BR>   mainPanel = new JPanel();<BR>   mainPanel.setLayout(new BorderLayout());<BR>   mainPanel.add(getRightPanel(), BorderLayout.EAST);<BR>   mainPanel.add(mapControl, BorderLayout.CENTER);<BR>  }<BR>  return mainPanel;<BR> }</P>
<P> /**<BR>  * This method initializes rightPanel <BR>  *  <BR>  * @return javax.swing.JPanel <BR>  */<BR> private JPanel getRightPanel() {<BR>  if (rightPanel == null) {<BR>   helpLabel = new JLabel(helpLabelString);<BR>   //helpLabel.setText("JLabel");<BR>   rightPanel = new JPanel();<BR>   rightPanel.setLayout(new BorderLayout());<BR>   rightPanel.add(helpLabel, BorderLayout.NORTH);<BR>   rightPanel.add(getButtonPanel(), BorderLayout.CENTER);<BR>  }<BR>  return rightPanel;<BR> }</P>
<P> /**<BR>  * This method initializes buttonPanel <BR>  *  <BR>  * @return javax.swing.JPanel <BR>  */<BR> private JPanel getButtonPanel() {<BR>  if (buttonPanel == null) {<BR>   buttonPanel = new JPanel();<BR>   buttonPanel.setLayout(new BorderLayout());<BR>   buttonPanel.add(getClearButton(), BorderLayout.NORTH);<BR>   buttonPanel.add(getFullExtentButton(), BorderLayout.CENTER);<BR>  }<BR>  return buttonPanel;<BR> }</P>
<P> /**<BR>  * This method initializes clearButton <BR>  *  <BR>  * @return javax.swing.JButton <BR>  */<BR> private JButton getClearButton() {<BR>  if (clearButton == null) {<BR>   clearButton = new JButton();<BR>   clearButton.setText("Clear Text");<BR>   clearButton.addActionListener(new java.awt.event.ActionListener() {<BR>    public void actionPerformed(java.awt.event.ActionEvent e) {<BR>     System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()<BR>    <BR>      try {<BR>                 //Get rid of the line<BR>                 polyLine = null;<BR>                //Refresh the foreground thereby removing any text annotation<BR>                 mapControl.refresh(esriViewDrawPhase.esriViewForeground, null, null);<BR>              }<BR>              catch (Exception ex) {<BR>                 System.out.println("Exception in clearText#action performed : " + ex);<BR>                 ex.printStackTrace();<BR>              }</P>
<P>    <BR>    }<BR>   });<BR>  }<BR>  return clearButton;<BR> }</P>
<P> /**<BR>  * This method initializes fullExtentButton <BR>  *  <BR>  * @return javax.swing.JButton <BR>  */<BR> private JButton getFullExtentButton() {<BR>  if (fullExtentButton == null) {<BR>   fullExtentButton = new JButton();<BR>   fullExtentButton.setText("Full Extent");<BR>   fullExtentButton.addActionListener(new java.awt.event.ActionListener() {<BR>    public void actionPerformed(java.awt.event.ActionEvent e) {<BR>     System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()<BR>      try {<BR>                //Assign map controls extent property to the full extent of all the layers<BR>                mapControl.getFullExtent();<BR>                mapControl.setExtent(mapControl.getFullExtent());<BR>             }<BR>             catch (Exception ex) {<BR>                System.out.println(<BR>                    "Exception in fullExtentButton#actionPerformed : " + ex);<BR>             }</P>
<P>    <BR>    }<BR>   });<BR>  }<BR>  return fullExtentButton;<BR> }</P>
<P> /**<BR>  * This method initializes textField <BR>  *  <BR>  * @return javax.swing.JTextField <BR>  */<BR> private JTextField getTextField() {<BR>  if (textField == null) {<BR>   textField = new JTextField();<BR>   textField.setText("Put a map in your app...");<BR>  }<BR>  return textField;<BR> }</P>
<P> /**<BR>  * @param args<BR>  */<BR> public static void main(String[] args) {<BR>  // TODO Auto-generated method stub<BR>  SwingUtilities.invokeLater(new Runnable() {<BR>   public void run() {<BR>    try{<BR>    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());<BR>          EngineInitializer.initializeVisualBeans();</P>
<P>          AoInitialize aoInit = new AoInitialize();<BR>          aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);</P>
<P>    }catch(Exception e){<BR>     System.out.println("出错");<BR>    }<BR>    DrawTextd thisClass = new DrawTextd();<BR>    thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<BR>    thisClass.setVisible(true);<BR>   }<BR>  });<BR> }</P>
<P> /**<BR>  * This is the default constructor<BR>  */<BR> public DrawTextd() {<BR>  super();<BR>  initialize();<BR> }</P>
<P> /**<BR>  * This method initializes this<BR>  * <BR>  * @return void<BR>  */<BR> private void initialize() {<BR>  mapControl = new MapControl();<BR>System.out.println(filePath);<BR>System.out.println(f1);<BR>System.out.println(ss);<BR>  this.setSize(696, 469);<BR>  this.setContentPane(getJContentPane());<BR>  this.setTitle("JFrame");<BR>  try {<BR>           FeatureLayer featureLayer = null;<BR>           SimpleRenderer simpleRenderer = null;<BR>           SimpleFillSymbol simpleFillSymbol = null;<BR>           SimpleLineSymbol simpleLineSymbol = null;</P>
<P>           //Add sample 'country' shapefile data、road_g、country\D:\\map<BR>           try{<BR>          <BR>           mapControl.addShapeFile(filePath,"airport.shp");<BR>       // mapControl.addLayerFromFile("D:\\map\\data\\country.shp",0);<BR>           }catch(Exception e){<BR>            <BR>            System.out.println("图层加载出错"+e.getMessage());<BR>           }<BR>           //Create a Featurelayer object on the layer<BR>           //in the map control in order to symbolize the data<BR>           featureLayer = new FeatureLayer(mapControl.getLayer(0));</P>
<P>           //Create a simple renderer object<BR>           simpleRenderer = new SimpleRenderer();<BR>           //Create a fill symbol<BR>           simpleFillSymbol = new SimpleFillSymbol();<BR>           //Create a line symbol<BR>           simpleLineSymbol = new SimpleLineSymbol();<BR>           //Assign line symbol and fill symbol properties<BR>           simpleLineSymbol.setWidth(0.1);<BR>           simpleLineSymbol.setColor(getRGBColor(255, 0, 0));<BR>           simpleFillSymbol.setOutline(simpleLineSymbol);<BR>           simpleFillSymbol.setColor(getRGBColor(0, 0, 255));</P>
<P>           //Set the symbol property of the renderer<BR>           simpleRenderer.setSymbolByRef(simpleFillSymbol);</P>
<P>           //Set the renderer property of the geo feature layer<BR>           featureLayer.setRendererByRef(simpleRenderer);<BR>           //Refresh map<BR>          // mapControl.refresh(esriViewDrawPhase.esriViewBackground, null, null);<BR>           //Add map control listener<BR>          // mapControl.addIMapControlEvents2Listener(new IMapControlEvents2());<BR>           mapControl.refresh(esriViewDrawPhase.esriViewBackground, null, null);<BR>           //Add map control listener<BR>           mapControl.addIMapControlEvents2Listener(new MapControlListener());</P>
<P>        }<BR>        catch (Exception ex) {<BR>           System.out.println("Exception in initMap : " + ex);<BR>           ex.printStackTrace();<BR>        }<BR>     }</P>
<P> //}</P>
<P> /**<BR>  * This method initializes jContentPane<BR>  * <BR>  * @return javax.swing.JPanel<BR>  */<BR> private JPanel getJContentPane() {<BR>  if (jContentPane == null) {<BR>   jContentPane = new JPanel();<BR>   jContentPane.setLayout(new BorderLayout());<BR>   jContentPane.add(getBottomPanel(), BorderLayout.SOUTH);<BR>   jContentPane.add(getMainPanel(), BorderLayout.CENTER);<BR>  }<BR>  return jContentPane;<BR> }<BR>   private IRgbColor getRGBColor(int red, int green, int blue) {<BR>       IRgbColor rgbColor = null;</P>
<P>       try {<BR>           //Create rgb color and grab hold of the IRGBColor interface<BR>          rgbColor = new RgbColor();<BR>          rgbColor.setRed(red);<BR>          rgbColor.setGreen(green);<BR>          rgbColor.setBlue(blue);<BR>          rgbColor.setUseWindowsDithering(true);<BR>       }<BR>       catch (Exception ex) {<BR>          System.out.println("Error in getRGBFunction :" + ex);<BR>          ex.printStackTrace();<BR>       }<BR>       return rgbColor;<BR>    }<BR>   private String getText() {<BR>         return textField.getText();<BR>    }<BR>   <BR>     class MapControlListener extends IMapControlEvents2Adapter {</P>
<P><BR>      public void onMouseDown(IMapControlEvents2OnMouseDownEvent theEvent) {<BR>          try {<BR>             //If left mouse button<BR>             if(theEvent.getButton() == 1) {<BR>                //Create a point and grab hold of the IPoint inteface<BR>                Point point = new Point();</P>
<P>                //Set point properties<BR>                point.setX( (double) (theEvent.getMapX()));<BR>                point.setY( (double) (theEvent.getMapY()));</P>
<P>                //If this is the first point of a new line<BR>                if(polyLine == null) { polyLine = new Polyline(); }</P>
<P>                //Add point to polyline<BR>                polyLine.addPoint(point, null, null);<BR>                //Refresh the foreground thereby removing any text annotation<BR>                mapControl.refresh(esriViewDrawPhase.esriViewForeground, null, null);</P>
<P>            }<BR>            else {<BR>                //If right or middle mouse button zoom to user defined rectangle<BR>                IEnvelope envelope = null;<BR>                //Create an envelope and grab hold of the IEnvelope interface<BR>                envelope = mapControl.trackRectangle();<BR>                //If user dragged a rectangle<BR>                if(envelope != null)<BR>                   mapControl.setExtent(envelope);</P>
<P>           }<BR>         }<BR>         catch (Exception ex) {<BR>             System.out.println("Exception in MapControlListener#onMouseDown : " + ex);<BR>             ex.printStackTrace();<BR>         }<BR>       }<BR>      public void onAfterDraw(IMapControlEvents2OnAfterDrawEvent theEvent) {<BR>          try {<BR>             //If foreground refreshed and if a line object for splining text exists<BR>             // and if there's at least two points in the line<BR>             if (theEvent.getViewDrawPhase() ==<BR>                 esriViewDrawPhase.esriViewForeground ;;<BR>                 polyLine != null ;;<BR>                 polyLine.getAsIPointCollection().getPointCount() > 1) {</P>
<P>                //Create a line symbol<BR>                SimpleLineSymbol lineSymbol = new SimpleLineSymbol();<BR>                //Set line symbol properties<BR>                lineSymbol.setColor(getRGBColor(0, 0, 0));<BR>                lineSymbol.setWidth(2.0);</P>
<P>                //Create a text symbol<BR>                TextSymbol textSymbol = new TextSymbol();<BR>                //Create a font symbol<BR>                StdFont font = new StdFont();<BR>                font.setName("Arial");<BR>                font.setBold(true);<BR>                textSymbol.setFont(font);<BR>                textSymbol.setSize(16);<BR>                textSymbol.setColor(getRGBColor(0, 0, 0));</P>
<P>                //Create a text path and grab hold of the ITextPath interface<BR>                ITextPath textPath = new BezierTextPath();<BR>                //Grab hold of the ISimpleTextSymbol interface through the ITextSymbol interface<BR>                ISimpleTextSymbol simpleTextSymbol = textSymbol.getAsISimpleTextSymbol();<BR>                //Set the text path of the simple text symbol<BR>                simpleTextSymbol.setTextPathByRef(textPath);<BR>                //Draw the line object and spline the user text around the line<BR>                mapControl.getAsIMapControl2().drawShape(polyLine, lineSymbol);<BR>                mapControl.getAsIMapControl3().drawText(polyLine, getText(), textSymbol);</P>
<P>             }<BR>          }<BR>          catch (Exception ex) {<BR>             System.out.println("Exception in MapControlListener#onAfterDraw :" +  ex);<BR>             ex.printStackTrace();<BR>          }</P>
<P>       }</P>
<P>     }<BR>}  //  @jve:decl-index=0:visual-constraint="10,10"<BR></P>

<P>这是整个程序,请大家帮忙调试一下,看看问题到底在哪里???</P>
<P>在我的调试中还是出错:</P>
<P>C:\arcgis\ArcTutor\LinearReferencing\<BR>..\..\..\..\..\data<BR>/E:/eclipse3.2work/testGis/bin/<BR>图层加载出错AutomationException: <BR>Exception in initMap : AutomationException: 0x80070057 - <BR>AutomationException: 0x80070057 - <BR> at com.esri.arcgis.beans.map.MapControl.getLayer(Unknown Source)</P>
<P>.......</P>
<P>谢谢,</P><img src="images/post/smile/dvbbs/em02.gif" /><img src="images/post/smile/dvbbs/em02.gif" />
举报 回复(0) 喜欢(0)     评分
上一页 下一页
游客

返回顶部