登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 ycjtj1dx202ly 于 2013-10-25 11:22 编辑
教程二主要实现Mapview和Maplayout的缩放、移动、图元信息查询的功能,以及在状态栏中添加一个用来显示当前状态的标签。
1.在工具栏中添加相应的按钮:jButton_Select、jButton_ZoomIn、jButton_ZoomOut、jButton_Pan、jButton_FullExtent和jButton_Identifer,并在各个按钮属性中的tooltiptext改为相应的名称。然后在状态栏中添加一个标签Status,并按教程一中方法更改各自相应的变量名。
2.构造一个变量,然后构造一个相应的函数
- private JButton _currentTool = null;
- private void setCurrentTool(JButton currentTool) {
- if (!(_currentTool == null)) {
- _currentTool.setSelected(false);
- }
- _currentTool = currentTool;
- _currentTool.setSelected(true);
- jLabel_Status.setText(_currentTool.getToolTipText());
- }
3.在各按钮的事件中添加相应的代码
- private void jButton_SelectActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- this.mapView1.setMouseTool(MouseTools.SelectElements);
- this.layersLegend1.getMapLayout().setMouseMode(MouseMode.Select);
- setCurrentTool((JButton) evt.getSource());
- }
- private void jButton_ZoomInActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- this.mapView1.setMouseTool(MouseTools.Zoom_In);
- this.layersLegend1.getMapLayout().setMouseMode(MouseMode.Map_ZoomIn);
- setCurrentTool((JButton) evt.getSource());
- }
- private void jButton_ZoomOutActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- this.mapView1.setMouseTool(MouseTools.Zoom_Out);
- this.layersLegend1.getMapLayout().setMouseMode(MouseMode.Map_ZoomOut);
- setCurrentTool((JButton) evt.getSource());
- }
- private void jButton_PanActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- this.mapView1.setMouseTool(MouseTools.Pan);
- this.layersLegend1.getMapLayout().setMouseMode(MouseMode.PanMap);
- setCurrentTool((JButton) evt.getSource());
- }
- private void jButton_FullExtentActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- this.mapView1.zoomToExtent(this.mapView1.getExtent());
- }
- private void jButton_IdentiferActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- this.mapView1.setMouseTool(MouseTools.Identifer);
- this.layersLegend1.getMapLayout().setMouseMode(MouseMode.Map_Identifer);
- setCurrentTool((JButton) evt.getSource());
- }
4.调试项目
图元信息
|