爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 4058|回复: 3

MeteoInfo Java版二次开发教程四

[复制链接]

新浪微博达人勋

发表于 2013-10-28 21:40:35 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 ycjtj1dx202ly 于 2013-10-28 22:07 编辑

此次教程是实现在MapLayout上添加中国南海脚图。首先要添加一个MapFrame,并且将它添加到LayersLegend中,接下来为MapFrame添加一个图层,MapLayout中会自动添加一个LayoutMap,最后设置相应的参数将MapView缩放到南海范围。我们先在public FrmMain下添加函数
  1. this.addMapFrame_ChinaSouthSea();

添加MapFrame及设置相应参数,代码如下:

  1. private void addMapFrame_ChinaSouthSea() {

  2.      //Add an empty map frame
  3.      MapFrame aMF = new MapFrame();
  4.      aMF.setText("China South Sea");
  5.      this.layersLegend1.addMapFrame(aMF);

  6.      //Add a layer to this map frame
  7.      try {
  8.          String mapDir = "E:\\MeteoInfo\\map\\";
  9.          String aFile = mapDir + "country1.shp";
  10.          MapLayer aLayer = MapDataManage.loadLayer(aFile);            aLayer.getLegendScheme().getLegendBreaks().get(0).setColor(new Color(232, 232, 232));
  11.          aMF.addLayer(aLayer);

  12.          //Set layout map property
  13.          LayoutMap aLM = this.mapLayout1.getLayoutMaps().get(1);
  14.          aMF.setDrawGridLabel(false);
  15.          aLM.setLeft(550);
  16.          aLM.setTop(330);
  17.          aLM.setWidth(80);
  18.          aLM.setHeight(100);
  19.          aMF.getMapView().zoomToExtent(105, 120, 0, 20);
  20.          this.layersLegend1.repaint();
  21.       } catch (IOException ex) {
  22.          Logger.getLogger(FrmMain.class.getName()).log(Level.SEVERE, null, ex);
  23.       } catch (Exception ex) {
  24.          Logger.getLogger(FrmMain.class.getName()).log(Level.SEVERE, null, ex);
  25.       }
  26. }


接下来给MapLayout添加一个文本

首先同样在public FrmMain中添加一个函数

  1. this.AddTitle();


addTitle函数代码如下:
  1. private void AddTitle() {this.mapLayo .addText("MeteoInfo Class Library Demo", mapLayout1.getWidth() / 2, 20, 16);   
  2. }


给菜单File添加一个子菜单ExportFigure,并在其Click事件中加入下列代码,实现图像保存为图形文件的功能。

  1.    private void jMenuItem_ExportFigureActionPerformed(java.awt.event.ActionEvent evt) {
  2.     // TODO add your handling code here:
  3.     JFileChooser aDlg = new JFileChooser();
  4.     String[] fileExts = new String[]{"png"};
  5.     GenericFileFilter mapFileFilter = new GenericFileFilter(fileExts, "Png Image (*.png)");  
  6.     aDlg.setFileFilter(mapFileFilter);        
  7.     fileExts = new String[]{"gif"};        
  8.     mapFileFilter = new GenericFileFilter(fileExts, "Gif Image (*.gif)");      
  9.     aDlg.addChoosableFileFilter(mapFileFilter);      
  10.     fileExts = new String[]{"jpg"};        
  11.     mapFileFilter = new GenericFileFilter(fileExts, "Jpeg Image (*.jpg)");   
  12.     aDlg.addChoosableFileFilter(mapFileFilter);      
  13.     aDlg.setAcceptAllFileFilterUsed(false);        
  14.     if (JFileChooser.APPROVE_OPTION == aDlg.showSaveDialog(this)) {           
  15.         File aFile = aDlg.getSelectedFile();            
  16.         System.setProperty("User.dir", aFile.getParent());           
  17.         String extent = ((GenericFileFilter) aDlg.getFileFilter()).getFileExtent();           
  18.         String fileName = aFile.getAbsolutePath();           
  19.         if (!fileName.substring(fileName.length() - extent.length()).equals(extent)) {               
  20.              fileName = fileName + "." + extent;           
  21.         }           
  22.         if (this.jTabbedPane1.getSelectedIndex() == 0) {               
  23.              try {                  
  24.              this.layersLegend1.getActiveMapFrame().getMapView().exportToPicture(fileName);              
  25.              } catch (FileNotFoundException ex) {                    
  26.                 Logger.getLogger(FrmMain.class.getName()).log(Level.SEVERE, null, ex);               
  27.              } catch (PrintException ex) {                  
  28.                 Logger.getLogger(FrmMain.class.getName()).log(Level.SEVERE, null, ex);               
  29.              } catch (IOException ex) {                  
  30.                 Logger.getLogger(FrmMain.class.getName()).log(Level.SEVERE, null, ex);               
  31.              }            
  32.         } else if (this.jTabbedPane1.getSelectedIndex() == 1) {              
  33.               try {                  
  34.                 this.layersLegend1.getMapLayout().exportToPicture(fileName);               
  35.             } catch (FileNotFoundException ex) {                  
  36.                 Logger.getLogger(FrmMain.class.getName()).log(Level.SEVERE, null, ex);               
  37.             } catch (PrintException ex) {                  
  38.                 Logger.getLogger(FrmMain.class.getName()).log(Level.SEVERE, null, ex);               
  39.             } catch (IOException ex) {                  
  40.                 Logger.getLogger(FrmMain.class.getName()).log(Level.SEVERE, null, ex);               
  41.             }            
  42.         }        
  43.     }   
  44. }


调试结果如下:

1.png





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

新浪微博达人勋

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

新浪微博达人勋

发表于 2017-6-13 20:55:52 | 显示全部楼层
{:eb502:}
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

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

使用道具 举报

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

本版积分规则

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

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

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