登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 ycjtj1dx202ly 于 2013-10-29 21:26 编辑
在LayerLegend中鼠标右击MapFrame名会出现一个Active菜单项,点击它可以用来设置ActiveMapFrame。此次教程用来实现使MapView随着切换ActiveMapFrame也随之切换,用一个SetMapView函数来完成。
首先在FrmMain构造函数中加入下列代码
- //setMapView
- this.setMapView();
- this.layersLegend1.addActiveMapFrameChangedListener(new IActiveMapFrameChangedListener(){
- @Override
- public void activeMapFrameChangedEvent(ActiveMapFrameChangedEvent event) {
- mapView1 = layersLegend1.getActiveMapFrame().getMapView();
- setMapView();
- if (jTabbedPane1.getSelectedIndex() == 0) {
- mapView1.paintLayers();
- }
- }
- });
写一个SetMapView函数用来切换MapView,代码如下:
- private void setMapView(){
- //Add map view
- this.mapView1.setLockViewUpdate(true);
- this.jPanel_Map.removeAll();
- javax.swing.GroupLayout jPanel_MapLayout=new javax.swing.GroupLayout(jPanel_Map);
- jPanel_Map.setLayout(jPanel_MapLayout);
- jPanel_MapLayout.setHorizontalGroup(
- jPanel_MapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(mapView1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
- jPanel_MapLayout.setVerticalGroup(
- jPanel_MapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(mapView1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
- this.mapView1.setLockViewUpdate(false);
- if (_currentTool != null) {
- _currentTool.doClick();
- }
- this.mapView1.setFocusable(true);
- this.mapView1.requestFocusInWindow();
- }
气象数据中有一个重要的类MeteoDataInfo,用它创建一个对象,用相应Open语句可以打开不同格式的气象数据,以GrADS格式的经典示例数据model.ctl和model.dat为例,用openGrADSData函数打开GrADS格式数据,然后获取格点或者站点数据,用GridData和StationData类来表示,然后创建并添加图层。添加一个MeteoInfo菜单,为该菜单添加一个GrADS Data子菜单,为该子菜单再添加一个Contour菜单,打开model.ctl文件并绘制等值线图层,代码如下:
- private void jMenuItem_ContourActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- //Create a MeteoDataInfo object
- MeteoDataInfo aDataInfo = new MeteoDataInfo();
- //Open GrADS data file
- String dataDir = "E:\\MeteoInfo\\sample\\GrADS\\";
- String fileName = dataDir + "model.ctl";
- aDataInfo.openGrADSData(fileName);
- //Get GridData
- GridData press = aDataInfo.getGridData("PS");
- //Create a legend scheme
- LegendScheme aLS = LegendManage.createLegendSchemeFromGridData(press,LegendType.UniqueValue, ShapeTypes.Polyline);
- //Create a contour layer
- VectorLayer aLayer = DrawMeteoData.createContourLayer(press, aLS, "Contour_PS", "PS", true);
- //Add layer
- layersLegend1.getActiveMapFrame().addLayer(aLayer);
- layersLegend1.getActiveMapFrame().moveLayer(aLayer.getHandle(), 2);
- layersLegend1.repaint();
- //Change title of the layout
- LayoutGraphic aTitle = mapLayout1.getTexts().get(0);
- aTitle.setLabelText("MeteoInfo Class Library Demo - Contour Layer");
- //Add a legend in layout
- LayoutLegend aLegend = mapLayout1.addLegend(650, 100);
- aLegend.setLegendStyle(LegendStyles.Normal);
- aLegend.setLegendLayer(aLayer);
- mapLayout1.paintGraphics();
- }
调试结果如下
|