爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 5524|回复: 9

MeteoInfo Java版二次开发教程二

[复制链接]

新浪微博达人勋

发表于 2013-10-23 10:55:14 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本帖最后由 ycjtj1dx202ly 于 2013-10-25 11:22 编辑

      教程二主要实现Mapview和Maplayout的缩放、移动、图元信息查询的功能,以及在状态栏中添加一个用来显示当前状态的标签。
1.在工具栏中添加相应的按钮:jButton_Select、jButton_ZoomIn、jButton_ZoomOut、jButton_Pan、jButton_FullExtent和jButton_Identifer,并在各个按钮属性中的tooltiptext改为相应的名称。然后在状态栏中添加一个标签Status,并按教程一中方法更改各自相应的变量名。

Image00091.png

2.构造一个变量,然后构造一个相应的函数

  1. private JButton _currentTool = null;
  2. private void setCurrentTool(JButton currentTool) {
  3.         if (!(_currentTool == null)) {
  4.             _currentTool.setSelected(false);
  5.         }
  6.         _currentTool = currentTool;
  7.         _currentTool.setSelected(true);
  8.         jLabel_Status.setText(_currentTool.getToolTipText());
  9.     }


3.在各按钮的事件中添加相应的代码

  1.     private void jButton_SelectActionPerformed(java.awt.event.ActionEvent evt) {                                               
  2.         // TODO add your handling code here:
  3.         this.mapView1.setMouseTool(MouseTools.SelectElements);
  4.         this.layersLegend1.getMapLayout().setMouseMode(MouseMode.Select);
  5.         setCurrentTool((JButton) evt.getSource());
  6.     }                                             

  7.     private void jButton_ZoomInActionPerformed(java.awt.event.ActionEvent evt) {                                               
  8.         // TODO add your handling code here:
  9.         this.mapView1.setMouseTool(MouseTools.Zoom_In);
  10.         this.layersLegend1.getMapLayout().setMouseMode(MouseMode.Map_ZoomIn);
  11.         setCurrentTool((JButton) evt.getSource());
  12.     }                                             

  13.     private void jButton_ZoomOutActionPerformed(java.awt.event.ActionEvent evt) {                                                
  14.         // TODO add your handling code here:
  15.         this.mapView1.setMouseTool(MouseTools.Zoom_Out);
  16.         this.layersLegend1.getMapLayout().setMouseMode(MouseMode.Map_ZoomOut);
  17.         setCurrentTool((JButton) evt.getSource());
  18.     }                                               

  19.     private void jButton_PanActionPerformed(java.awt.event.ActionEvent evt) {                                            
  20.         // TODO add your handling code here:
  21.         this.mapView1.setMouseTool(MouseTools.Pan);
  22.         this.layersLegend1.getMapLayout().setMouseMode(MouseMode.PanMap);
  23.         setCurrentTool((JButton) evt.getSource());
  24.     }                                          

  25.     private void jButton_FullExtentActionPerformed(java.awt.event.ActionEvent evt) {                                                   
  26.         // TODO add your handling code here:
  27.         this.mapView1.zoomToExtent(this.mapView1.getExtent());
  28.     }                                                  

  29.     private void jButton_IdentiferActionPerformed(java.awt.event.ActionEvent evt) {                                                  
  30.         // TODO add your handling code here:
  31.         this.mapView1.setMouseTool(MouseTools.Identifer);
  32.         this.layersLegend1.getMapLayout().setMouseMode(MouseMode.Map_Identifer);
  33.         setCurrentTool((JButton) evt.getSource());
  34.     }                                       


4.调试项目

6.png

图元信息

7.png


密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2013-10-23 13:34:42 | 显示全部楼层
高清教程第二季..王老师有了得力助手
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-4-3 23:21:10 | 显示全部楼层
王老师厉害!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-5-21 08:42:59 | 显示全部楼层
学java的明显比c#少哈
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-6-20 16:47:36 | 显示全部楼层
学习中!真棒
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-10-4 18:49:59 | 显示全部楼层
本帖最后由 zhksoft 于 2014-10-4 18:51 编辑

虽然出图了,但效果不如意,王老师给看一下

  1. private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent evt) {                                          
  2.         // TODO add your handling code here:
  3.         int selIndex=this.jTabbedPane1.getSelectedIndex();
  4.         switch(selIndex){
  5.             case 0:
  6.                 //this.layersLegend1.setIsLayoutView(false);
  7.                 this.mapView1.setIsLayoutMap(true);
  8.                 this.mapView1.zoomToExtent(this.mapView1.getViewExtent());
  9.                 break;
  10.             case 1:
  11.                 //this.layersLegend1.setIsLayoutView(true);
  12.                
  13.                 this.layersLegend1.getMapLayout().paintGraphics();
  14.                 break;
  15.         }
  16.     }  


我的问题:1、我必须把this.layersLegend1.setIsLayoutView(false);注释掉才能编译运行,库版本的问题?
2、我的map里用Identifer没反应,在maplayout里能正常。
3、maplayout里图不自动FullExtent
20141004java-2.jpg
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-10-4 19:01:27 | 显示全部楼层
zhksoft 发表于 2014-10-4 18:49
虽然出图了,但效果不如意,王老师给看一下

应该是版本的问题,改为如下:
    private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent evt) {                                          
        // TODO add your handling code here:
        int selIndex = this.jTabbedPane1.getSelectedIndex();
        switch (selIndex) {
            case 0:    //MapView
                this.mapLayout1.setLockViewUpdate(true);
                this.mapView1.zoomToExtent(this.mapView1.getViewExtent());
                break;
            case 1:    //MapLayout
                this.mapLayout1.setLockViewUpdate(false);
                this.mapLayout1.paintGraphics();
                break;
        }
    }  
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-10-4 19:25:15 | 显示全部楼层
MeteoInfo 发表于 2014-10-4 19:01
应该是版本的问题,改为如下:
    private void jTabbedPane1StateChanged(javax.swing.event.ChangeEv ...

嗯,改了以后就好了,谢谢啦。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-6-13 20:46:44 | 显示全部楼层
厉害
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2017-9-13 14:52:59 | 显示全部楼层
谢谢分享
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表