爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 4525|回复: 5

MeteoInfo Java版二次开发教程五

[复制链接]

新浪微博达人勋

发表于 2013-10-29 21:26:51 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 ycjtj1dx202ly 于 2013-10-29 21:26 编辑

在LayerLegend中鼠标右击MapFrame名会出现一个Active菜单项,点击它可以用来设置ActiveMapFrame。此次教程用来实现使MapView随着切换ActiveMapFrame也随之切换,用一个SetMapView函数来完成。
首先在FrmMain构造函数中加入下列代码
  1. //setMapView
  2.         this.setMapView();        

  3.         this.layersLegend1.addActiveMapFrameChangedListener(new IActiveMapFrameChangedListener(){
  4.             @Override
  5.             public void activeMapFrameChangedEvent(ActiveMapFrameChangedEvent event) {
  6.             mapView1 = layersLegend1.getActiveMapFrame().getMapView();
  7.             setMapView();
  8.                 if (jTabbedPane1.getSelectedIndex() == 0) {
  9.                 mapView1.paintLayers();
  10.                 }
  11.             }
  12.         });


写一个SetMapView函数用来切换MapView,代码如下:
  1. private void setMapView(){
  2.         //Add map view
  3.         this.mapView1.setLockViewUpdate(true);
  4.         this.jPanel_Map.removeAll();
  5.         javax.swing.GroupLayout jPanel_MapLayout=new javax.swing.GroupLayout(jPanel_Map);
  6.         jPanel_Map.setLayout(jPanel_MapLayout);
  7.         jPanel_MapLayout.setHorizontalGroup(
  8.                 jPanel_MapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(mapView1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
  9.         jPanel_MapLayout.setVerticalGroup(
  10.                 jPanel_MapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(mapView1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
  11.         this.mapView1.setLockViewUpdate(false);
  12.         if (_currentTool != null) {
  13.         _currentTool.doClick();
  14.         }
  15.         this.mapView1.setFocusable(true);
  16.         this.mapView1.requestFocusInWindow();      
  17. }


气象数据中有一个重要的类MeteoDataInfo,用它创建一个对象,用相应Open语句可以打开不同格式的气象数据,以GrADS格式的经典示例数据model.ctl和model.dat为例,用openGrADSData函数打开GrADS格式数据,然后获取格点或者站点数据,用GridData和StationData类来表示,然后创建并添加图层。添加一个MeteoInfo菜单,为该菜单添加一个GrADS Data子菜单,为该子菜单再添加一个Contour菜单,打开model.ctl文件并绘制等值线图层,代码如下:
  1.     private void jMenuItem_ContourActionPerformed(java.awt.event.ActionEvent evt) {                                                  
  2.         // TODO add your handling code here:
  3.         //Create a MeteoDataInfo object
  4.         MeteoDataInfo aDataInfo = new MeteoDataInfo();

  5.         //Open GrADS data file
  6.         String dataDir = "E:\\MeteoInfo\\sample\\GrADS\\";
  7.         String fileName = dataDir + "model.ctl";
  8.         aDataInfo.openGrADSData(fileName);

  9.         //Get GridData
  10.         GridData press = aDataInfo.getGridData("PS");

  11.         //Create a legend scheme
  12.         LegendScheme aLS = LegendManage.createLegendSchemeFromGridData(press,LegendType.UniqueValue, ShapeTypes.Polyline);

  13.         //Create a contour layer
  14.         VectorLayer aLayer = DrawMeteoData.createContourLayer(press, aLS, "Contour_PS", "PS", true);

  15.         //Add layer
  16.         layersLegend1.getActiveMapFrame().addLayer(aLayer);
  17.         layersLegend1.getActiveMapFrame().moveLayer(aLayer.getHandle(), 2);
  18.         layersLegend1.repaint();

  19.         //Change title of the layout
  20.         LayoutGraphic aTitle = mapLayout1.getTexts().get(0);
  21.         aTitle.setLabelText("MeteoInfo Class Library Demo - Contour Layer");

  22.         //Add a legend in layout
  23.         LayoutLegend aLegend = mapLayout1.addLegend(650, 100);
  24.         aLegend.setLegendStyle(LegendStyles.Normal);
  25.         aLegend.setLegendLayer(aLayer);
  26.         mapLayout1.paintGraphics();
  27.     }


调试结果如下
3.png

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

新浪微博达人勋

发表于 2013-10-29 22:02:14 | 显示全部楼层
不错不错        谢谢分享  
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-4-3 23:23:51 | 显示全部楼层
很好,必须鼓励!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-6-20 16:48:53 | 显示全部楼层
本科生学习中
密码修改失败请联系微信:mofangbao

新浪微博达人勋

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

使用道具 举报

新浪微博达人勋

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

使用道具 举报

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

本版积分规则

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

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

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